diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..dfe7475 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ + +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 + diff --git a/func_tests/test_client.py b/func_tests/test_client.py index 38ac26f..a450974 100644 --- a/func_tests/test_client.py +++ b/func_tests/test_client.py @@ -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 diff --git a/func_tests/utils.py b/func_tests/utils.py index 7a7f69e..393e7ec 100644 --- a/func_tests/utils.py +++ b/func_tests/utils.py @@ -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 diff --git a/func_tests/vinyldns_context.py b/func_tests/vinyldns_context.py index a7c8d37..261fef9 100644 --- a/func_tests/vinyldns_context.py +++ b/func_tests/vinyldns_context.py @@ -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('./') diff --git a/scripts/apache_header_check.py b/scripts/apache_header_check.py new file mode 100644 index 0000000..6cde381 --- /dev/null +++ b/scripts/apache_header_check.py @@ -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 + 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) \ No newline at end of file diff --git a/scripts/search_records_by_name.py b/scripts/search_records_by_name.py index 661f8c1..2b2dfba 100644 --- a/scripts/search_records_by_name.py +++ b/scripts/search_records_by_name.py @@ -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 diff --git a/scripts/search_records_by_owner_group.py b/scripts/search_records_by_owner_group.py index a93c905..9c8f5d6 100644 --- a/scripts/search_records_by_owner_group.py +++ b/scripts/search_records_by_owner_group.py @@ -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 diff --git a/scripts/update_record_owner.py b/scripts/update_record_owner.py index ae56ccf..2a7c4c1 100644 --- a/scripts/update_record_owner.py +++ b/scripts/update_record_owner.py @@ -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 diff --git a/scripts/zone_dump.py b/scripts/zone_dump.py index 9b1d8a1..3b84228 100644 --- a/scripts/zone_dump.py +++ b/scripts/zone_dump.py @@ -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