Skip to content

Commit

Permalink
CICD: json files should be strictly formatted (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli authored Jan 1, 2025
1 parent 2c2d7a1 commit 513b8be
Show file tree
Hide file tree
Showing 53 changed files with 1,308 additions and 981 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr_check_git_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
go-version: stable
- run: go install golang.org/x/tools/cmd/stringer@latest
- run: go fmt ./...
- run: bin/fmtjson $(find . -type f -name \*.json -print)
- run: go mod tidy
- run: go generate ./...
- uses: CatChen/check-git-status-action@v1
Expand Down
63 changes: 63 additions & 0 deletions bin/fmtjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python3

"""
Convert JSON data to human-readable form.
Usage:
fmtjson.py inputFile [inputFile2...]
or
fmtjson.py <input >output
-n Dry run mode.
"""

import sys
import json

def main(args):
problem = False
if len(args) and args[0] == '-n':
files = args[1:]
readonly = True
else:
files = args
readonly = False

if not files:
if readonly:
json.loads(sys.stdin.read())
else:
print(
json.dumps(
json.loads(sys.stdin.read()),
sort_keys=True,
indent=2,
separators=(',', ': ')
)
)
else:
for filename in files:
orig = {}
with open(filename, 'r') as f:
try:
orig_data = f.read()
orig = json.loads(orig_data)
except ValueError as e:
print('Reformatting: %s' % filename)
print('ERROR:', str(e))
problem = True
if (not problem) and (not readonly):
fixed_data = json.dumps(orig,
sort_keys=True, indent=2, separators=(',', ': ')) + '\n'
if orig_data != fixed_data:
print('Reformatting: %s' % filename)
with open(filename, 'w') as f:
f.write(fixed_data)
return problem

def usage():
print(__doc__)


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
6 changes: 3 additions & 3 deletions commands/test_data/bind-creds.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"bind": {
"directory": "test_data"
}
"bind": {
"directory": "test_data"
}
}
4 changes: 2 additions & 2 deletions documentation/assets/1password/creds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
},
"cloudflare": {
"TYPE": "CLOUDFLAREAPI",
"apitoken": "op://Secrets/Cloudflare DNSControl/credential",
"accountid": "op://Secrets/Cloudflare DNSControl/username"
"accountid": "op://Secrets/Cloudflare DNSControl/username",
"apitoken": "op://Secrets/Cloudflare DNSControl/credential"
},
"linode": {
"TYPE": "LINODE",
Expand Down
2 changes: 1 addition & 1 deletion documentation/assets/getting-started/creds.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"TYPE": "BIND"
},
"r53_ACCOUNTNAME": {
"TYPE": "ROUTE53",
"KeyId": "change_to_your_keyid",
"SecretKey": "change_to_your_secretkey",
"TYPE": "ROUTE53",
"Token": "optional_sts_token"
}
}
38 changes: 19 additions & 19 deletions integrationTest/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
},
"AXFRDDNS": {
"TYPE": "AXFRDDNS",
"buggy-cname": "$AXFRDDNS_BUGGY_CNAME",
"domain": "$AXFRDDNS_DOMAIN",
"master": "$AXFRDDNS_MASTER",
"nameservers": "ns.example.com",
"transfer-key": "$AXFRDDNS_TRANSFER_KEY",
"update-key": "$AXFRDDNS_UPDATE_KEY",
"buggy-cname": "$AXFRDDNS_BUGGY_CNAME"
"update-key": "$AXFRDDNS_UPDATE_KEY"
},
"AZURE_DNS": {
"ClientID": "$AZURE_DNS_CLIENT_ID",
Expand All @@ -40,8 +40,8 @@
},
"BUNNY_DNS": {
"TYPE": "BUNNY_DNS",
"domain": "$BUNNY_DNS_DOMAIN",
"api_key": "$BUNNY_DNS_API_KEY"
"api_key": "$BUNNY_DNS_API_KEY",
"domain": "$BUNNY_DNS_DOMAIN"
},
"CLOUDFLAREAPI": {
"TYPE": "CLOUDFLAREAPI",
Expand All @@ -65,13 +65,6 @@
"domain": "$CLOUDNS_DOMAIN",
"sub-auth-id": "$CLOUDNS_SUB_AUTH_ID"
},
"CSCGLOBAL": {
"TYPE": "CSCGLOBAL",
"api-key": "$CSCGLOBAL_APIKEY",
"domain": "$CSCGLOBAL_DOMAIN",
"notification_emails": "$CSCGLOBAL_NOTIFICATION",
"user-token": "$CSCGLOBAL_USERTOKEN"
},
"CNR": {
"TYPE": "CNR",
"apientity": "$CNR_ENTITY",
Expand All @@ -80,6 +73,13 @@
"debugmode": "$CNR_DEBUGMODE",
"domain": "$CNR_DOMAIN"
},
"CSCGLOBAL": {
"TYPE": "CSCGLOBAL",
"api-key": "$CSCGLOBAL_APIKEY",
"domain": "$CSCGLOBAL_DOMAIN",
"notification_emails": "$CSCGLOBAL_NOTIFICATION",
"user-token": "$CSCGLOBAL_USERTOKEN"
},
"DESEC": {
"TYPE": "DESEC",
"auth-token": "$DESEC_TOKEN",
Expand Down Expand Up @@ -164,11 +164,11 @@
"domain": "$HOSTINGDE_DOMAIN"
},
"HUAWEICLOUD": {
"TYPE": "HUAWEICLOUD",
"domain": "$HUAWEICLOUD_DOMAIN",
"Region": "$HUAWEICLOUD_REGION",
"KeyId": "$HUAWEICLOUD_KEY_ID",
"SecretKey": "$HUAWEICLOUD_KEY"
"Region": "$HUAWEICLOUD_REGION",
"SecretKey": "$HUAWEICLOUD_KEY",
"TYPE": "HUAWEICLOUD",
"domain": "$HUAWEICLOUD_DOMAIN"
},
"INWX": {
"TYPE": "INWX",
Expand Down Expand Up @@ -202,9 +202,9 @@
},
"MYTHICBEASTS": {
"TYPE": "MYTHICBEASTS",
"domain": "$MYTHICBEASTS_DOMAIN",
"keyID": "$MYTHICBEASTS_KEYID",
"secret": "$MYTHICBEASTS_SECRET",
"domain": "$MYTHICBEASTS_DOMAIN"
"secret": "$MYTHICBEASTS_SECRET"
},
"NAMECHEAP": {
"BaseURL": "$NAMECHEAP_BASEURL",
Expand Down Expand Up @@ -277,9 +277,9 @@
"REALTIMEREGISTER": {
"TYPE": "REALTIMEREGISTER",
"apikey": "$REALTIMEREGISTER_APIKEY",
"sandbox" : "$REALTIMEREGISTER_SANDBOX",
"domain": "$REALTIMEREGISTER_DOMAIN",
"premium": "$REALTIMEREGISTER_PREMIUM"
"premium": "$REALTIMEREGISTER_PREMIUM",
"sandbox": "$REALTIMEREGISTER_SANDBOX"
},
"ROUTE53": {
"KeyId": "$ROUTE53_KEY_ID",
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions pkg/js/parse_tests/001-basic.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"registrars": [
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"dnsProviders": {
"Cloudflare": -1
},
"name": "foo.com",
"records": [
{
"name": "Third-Party",
"type": "NONE"
"name": "@",
"target": "1.2.3.4",
"type": "A"
}
],
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
}
]
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
22 changes: 11 additions & 11 deletions pkg/js/parse_tests/002-ttl.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,19 +7,25 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"ttl": 42
"ttl": 42,
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
26 changes: 13 additions & 13 deletions pkg/js/parse_tests/003-meta.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"dns_providers": [],
"domains": [
{
"name": "foo.com",
"registrar": "Cloudflare",
"dnsProviders": {},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"meta": {
"cloudflare_proxy": "ON"
}
},
"name": "@",
"target": "1.2.3.4",
"type": "A"
}
]
],
"registrar": "Cloudflare"
}
],
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
]
}
Loading

0 comments on commit 513b8be

Please sign in to comment.