Skip to content

Commit ef29c9b

Browse files
committed
Refactor
1 parent 6b52a00 commit ef29c9b

File tree

8 files changed

+111
-31
lines changed

8 files changed

+111
-31
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11+
[*.md]
12+
indent_size = unset
13+
1114
[*.py]
1215
indent_size = 4
1316

.github/workflows/cicd-pipeline.yaml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches:
6-
- main
75
pull_request:
86
branches:
97
- main
8+
types: [opened, synchronize, reopened]
109

1110
jobs:
12-
get-datetime:
11+
get-metadata:
1312
runs-on: ubuntu-latest
1413
outputs:
15-
datetime: ${{ steps.datetime.outputs.datetime }}
16-
timestamp: ${{ steps.datetime.outputs.timestamp }}
17-
epoch: ${{ steps.datetime.outputs.epoch }}
14+
build_datetime: ${{ steps.metadata.outputs.build_datetime }}
15+
build_timestamp: ${{ steps.metadata.outputs.build_timestamp }}
16+
build_epoch: ${{ steps.metadata.outputs.build_epoch }}
1817
steps:
19-
- id: datetime
18+
- id: metadata
2019
run: |
2120
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
22-
echo "datetime=$datetime" >> $GITHUB_OUTPUT
23-
echo "timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
24-
echo "epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
21+
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
22+
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
23+
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
24+
scan-secrets:
25+
uses: ./.github/workflows/scan-secrets.yaml
2526
check-file-format:
2627
uses: ./.github/workflows/check-file-format.yaml
2728
check-markdown-format:
@@ -31,15 +32,21 @@ jobs:
3132
cicd-pipeline-test:
3233
runs-on: ubuntu-latest
3334
needs:
34-
[get-datetime, check-file-format, check-markdown-format, cloc-repository]
35+
[
36+
get-metadata,
37+
scan-secrets,
38+
check-file-format,
39+
check-markdown-format,
40+
cloc-repository,
41+
]
3542
timeout-minutes: 10
3643
steps:
3744
- uses: actions/checkout@v3
3845
- name: List Variables
3946
run: |
40-
export BUILD_DATETIME="${{ needs.get-datetime.outputs.datetime }}"
41-
export BUILD_TIMESTAMP="${{ needs.get-datetime.outputs.timestamp }}"
42-
export BUILD_EPOCH="${{ needs.get-datetime.outputs.epoch }}"
47+
export BUILD_DATETIME="${{ needs.get-metadata.outputs.build_datetime }}"
48+
export BUILD_TIMESTAMP="${{ needs.get-metadata.outputs.build_timestamp }}"
49+
export BUILD_EPOCH="${{ needs.get-metadata.outputs.build_epoch }}"
4350
make list-variables
4451
- name: Run Functional Test Suite
4552
run: |

.github/workflows/scan-secrets.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Scan Secrets
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
secret-scan:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
fetch-depth: 0
13+
- run: |
14+
export ALL_FILES=true
15+
./scripts/githooks/secret-scan-pre-commit.sh

.gitleaks.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SEE: https://github.com/gitleaks/gitleaks/#configuration
2+
3+
[extend]
4+
useDefault = true # SEE: https://github.com/gitleaks/gitleaks/blob/master/config/gitleaks.toml
5+
6+
[[rules]]
7+
description = "IPv4"
8+
id = "ipv4"
9+
regex = '''[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'''

.gitleaksignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SEE: https://github.com/gitleaks/gitleaks/blob/master/README.md#gitleaksignore

.vscode/extensions.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
{
22
"recommendations": [
33
"alefragnani.bookmarks",
4-
"amazonwebservices.aws-toolkit-vscode",
54
"davidanson.vscode-markdownlint",
65
"dbaeumer.vscode-eslint",
76
"donjayamanne.githistory",
87
"eamodio.gitlens",
98
"editorconfig.editorconfig",
109
"esbenp.prettier-vscode",
1110
"github.codespaces",
12-
"github.copilot",
1311
"github.github-vscode-theme",
1412
"github.remotehub",
1513
"github.vscode-github-actions",
1614
"github.vscode-pull-request-github",
17-
"golang.go",
18-
"hashicorp.terraform",
1915
"hediet.vscode-drawio",
2016
"johnpapa.vscode-peacock",
2117
"mhutchie.git-graph",
2218
"ms-azuretools.vscode-docker",
23-
"ms-kubernetes-tools.vscode-kubernetes-tools",
24-
"ms-python.python",
2519
"ms-vscode-remote.remote-containers",
2620
"ms-vscode-remote.remote-wsl",
2721
"ms-vscode.hexeditor",
22+
"ms-vscode.live-server",
2823
"ms-vsliveshare.vsliveshare",
2924
"redhat.vscode-xml",
3025
"streetsidesoftware.code-spell-checker-british-english",
@@ -37,5 +32,5 @@
3732
"yzhang.dictionary-completion",
3833
"yzhang.markdown-all-in-one"
3934
],
40-
"unwantedRecommendations": ["ms-vscode.makefile-tools"]
35+
"unwantedRecommendations": []
4136
}

.vscode/settings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Pre-commit git hook to scan for secrets hardcoded in the codebase.
6+
#
7+
# Usage:
8+
# $ ./secret-scan-pre-commit.sh
9+
#
10+
# Options:
11+
# ALL_FILES=true # Scan whole git history or 'last-commit', default is `false`
12+
# VERBOSE=true # Show all the executed commands, default is `false`
13+
#
14+
# Exit codes:
15+
# 0 - No leaks present
16+
# 1 - Leaks or error encountered
17+
# 126 - Unknown flag
18+
19+
# ==============================================================================
20+
21+
image_version=v8.16.3@sha256:05b48ff3f4fd7daa9487b42cbf9d576f2dc0dbe2551e3d0a8738e18ba2278091
22+
23+
# ==============================================================================
24+
25+
function main() {
26+
27+
if is_arg_true "$ALL_FILES"; then
28+
# Scan whole git history
29+
cmd="detect --source=/scan --verbose --redact"
30+
elif [ "$ALL_FILES" == "last-commit" ]; then
31+
# Scan the last commit
32+
cmd="detect --source=/scan --verbose --redact --log-opts=-1"
33+
else
34+
# Scan staged files only
35+
cmd="protect --source=/scan --verbose --staged"
36+
fi
37+
38+
docker run --rm --platform linux/amd64 \
39+
--volume=$PWD:/scan \
40+
--workdir=/scan \
41+
ghcr.io/gitleaks/gitleaks:$image_version \
42+
$cmd
43+
}
44+
45+
function is_arg_true() {
46+
47+
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
48+
return 0
49+
else
50+
return 1
51+
fi
52+
}
53+
54+
# ==============================================================================
55+
56+
is_arg_true "$VERBOSE" && set -x
57+
58+
main $*
59+
60+
exit 0

0 commit comments

Comments
 (0)