Skip to content

Commit

Permalink
check source header for apache 2.0 license (#4)
Browse files Browse the repository at this point in the history
* check source header for apache 2.0 license

* use script to check for invalid headers

* on pr and commit to master

* resolve shellcheck concerns

* fix name

* install go and install addlicense with go install

* fix syntax

* add Google license headers

* Fix linux config checksums, they are different because of the license addition
  • Loading branch information
Joseph Sirianni authored Jun 30, 2021
1 parent 4b13c0b commit e49bd71
Show file tree
Hide file tree
Showing 49 changed files with 736 additions and 5 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/check_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.
#
# This script returns a non 0 exit code when a source file is found
# without a license header.

set -e

if ! command -v addlicense &> /dev/null
then
echo "addlicense command could not be found: https://github.com/google/addlicense"
exit 1
fi

# Source types to check
ALL_EXT=("pp" "tf" "rb" "conf" "yaml" "ps1" "sh")

# Array will contain all source files to check
ALL_SRC=()

# Find source files and add them to ALL_SRC
for src_type in "${ALL_EXT[@]}"; do
src_files=$(find . -name "*.${src_type}" -type f | sort)
ALL_SRC+=("$src_files")
done

# Check licenses, will return 1 if a license is missing
echo "The following source files are missing a license header:"
# Quoting ALL_SRC does not play nice with addlicense cli, array expansion is not a concern here
# shellcheck disable=SC2068
addlicense \
-check \
-l apache \
-c "Google LLC" \
${ALL_SRC[@]}
14 changes: 14 additions & 0 deletions .github/scripts/inspec.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

if [ -z "$PLATFORM" ]; then
echo "PLATFORM not set"
exit 1
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/puppet.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

if [ -z "$PLATFORM" ]; then
echo "PLATFORM not set"
exit 1
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

set -e

export DEBIAN_FRONTEND=noninteractive
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/ssh.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

set -e

if [ -z "$1" ]; then
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/terraform-apply.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

set -e

if [ -z "$1" ]; then
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/terraform-destroy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Copyright 2021 Google 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
#
# https://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.

set -e

if [ -z "$1" ]; then
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: license
on:
pull_request:
push:
branches:
- master
jobs:
license:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Go
uses: actions/setup-go@v2
with:
go-version: '1.16'

- name: Install addlicense
run: go install github.com/google/addlicense@latest

- name: Check license headers
run: "./.github/scripts/check_license.sh"
14 changes: 14 additions & 0 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @summary Installs a Google Cloud agent
#
# Copyright 2021 Google 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
#
# https://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.
#
# Installs a Google Cloud agent
#
# @example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Master configuration file for google-fluentd

# Copyright 2021 Google 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
#
# https://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.

# Managed by Puppet

# Include any configuration files in the config.d directory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

module Fluent
module Plugin
class MyAwesomeInput < Input
Expand Down
14 changes: 14 additions & 0 deletions test/cases/linux/logging/latest/custom_config/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

cloud_ops::agent {'logging':
agent_type => 'logging',
main_config => '/tmp/cases/linux/logging/latest/custom_config/files/google-fluentd.conf',
Expand Down
18 changes: 16 additions & 2 deletions test/cases/linux/logging/latest/custom_config/spec/spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

describe service('google-fluentd') do
it { should be_installed }
it { should be_enabled }
Expand All @@ -9,14 +23,14 @@
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
its('sha256sum') { should eq '1bd5261e75092fb6e76feee034a3cf0cf8e3fa981cdc819c709be945f8ff4bb9' }
its('sha256sum') { should eq '9f83e16f70a9b014cb7631f68eab6bab9f05e992d4db7873ed26ff28b087a533' }
end

describe file('/etc/google-fluentd/plugin/plugin.rb') do
it { should exist }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
its('sha256sum') { should eq 'b74d2d88969a4664132555d5d030e08f72f2e135f6005edbfe4b3aec84a42412' }
its('sha256sum') { should eq '040c1d4c506c3d650e43ed268052d04c10e6267cfde3d7911f55ab0e43e2594b' }
end

14 changes: 14 additions & 0 deletions test/cases/linux/logging/latest/install/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

cloud_ops::agent {'logging':
agent_type => 'logging',
version => 'latest'
Expand Down
14 changes: 14 additions & 0 deletions test/cases/linux/logging/latest/install/spec/spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

describe service('google-fluentd') do
it { should be_installed }
it { should be_enabled }
Expand Down
14 changes: 14 additions & 0 deletions test/cases/linux/logging/latest/uninstall/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

cloud_ops::agent {'logging':
agent_type => 'logging',
installed => false
Expand Down
14 changes: 14 additions & 0 deletions test/cases/linux/logging/latest/uninstall/spec/spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

describe service('google-fluentd') do
it { should_not be_enabled }
it { should_not be_running }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google 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
#
# https://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.

# Managed by Puppet

Interval 60
Expand Down
Loading

0 comments on commit e49bd71

Please sign in to comment.