Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nitpicky, but can we remove the blank lines at the beginning and end of this file?

repos:
- repo: local
hooks:
- id: apache-license-header-check
name: apache license header check
entry: python3 scripts/apache_header_check.py
language: system
types: [python]
pass_filenames: true

13 changes: 13 additions & 0 deletions func_tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from func_tests.vinyldns_context import vinyldns_test_context
from vinyldns.batch_change import AddRecordChange, DeleteRecordSetChange, BatchChange, BatchChangeRequest, \
DeleteRecordSet, AddRecord, BatchChangeSummary, ListBatchChangeSummaries
Expand Down
13 changes: 13 additions & 0 deletions func_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import time
import logging
Expand Down
13 changes: 13 additions & 0 deletions func_tests/vinyldns_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append('../')
sys.path.append('./')
Expand Down
43 changes: 43 additions & 0 deletions scripts/apache_header_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import tokenize

license_to_check = "http://www.apache.org/licenses/LICENSE-2.0"

missing_license = False

#checks if the license_to_check is in a comment in the files
def is_string_in_comment(file_path, target_string):
with tokenize.open(file_path) as file:
# Loop through every token in the Python file
for token in tokenize.generate_tokens(file.readline):
# Check if the current token is a comment
if token.type == tokenize.COMMENT:
# Check if apache link string is inside that comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, but it currently allows for the Apache link string to be in a comment anywhere in the file. For example, a Python file with no header but a trailing comment such as # http://www.apache.org/licenses/LICENSE-2.0 passes. I think we should restrict the check to the initial header region, allowing only a shebang/encoding declaration before it, or if it's easier we can just validate the full expected header.

if target_string in token.string:
return True
return False

#Iterate through the .py files passed by the .pre-commit-config.yaml file
for filepath in sys.argv[1:]:
with open(filepath, "r", encoding="utf-8") as f:

#if license is not in header print it out in the pre commit error
if not is_string_in_comment(filepath, license_to_check):
print(f"Error: Missing Apache License header in {filepath}")
missing_license = True

if missing_license:
sys.exit(1)
13 changes: 13 additions & 0 deletions scripts/search_records_by_name.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import csv
import logging
Expand Down
13 changes: 13 additions & 0 deletions scripts/search_records_by_owner_group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import csv
import logging
Expand Down
13 changes: 13 additions & 0 deletions scripts/update_record_owner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import csv
import logging
Expand Down
13 changes: 13 additions & 0 deletions scripts/zone_dump.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2018 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import csv
import logging
Expand Down
Loading