Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stepanselyuk/a9df52f3e865c57862ee05556e920f90 to your computer and use it in GitHub Desktop.
Save stepanselyuk/a9df52f3e865c57862ee05556e920f90 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# CF API KEY
# API key != TOKEN (Certbot 1.11 which installed by Jenkins X expects API key)
API_KEY="KEY_HERE"
cat <<EOF | kubectl -n jx apply -f -
---
apiVersion: v1
kind: Secret
metadata:
name: cloudflare-api-key-secret
type: Opaque
stringData:
api-key: ${API_KEY}
EOF
echo "===== Secret (CF api key) added."
import inotify.adapters
import yaml
import os.path
import time
def _main():
i = inotify.adapters.InotifyTree('/tmp')
for event in i.event_gen(yield_nones=False):
(_, type_names, path, filename) = event
if 'IN_ISDIR' not in type_names:
continue
if 'IN_CREATE' not in type_names:
continue
fpath = '/'.join([path, filename])
if 'helm-template-workdir' not in fpath:
continue
print("MATCH / PATH=[{}] EVENT_TYPES={}".format(fpath, type_names))
# /tmp/helm-template-workdir-152206431/acme/output/namespaces/jx/acme/templates/part0-cert-manager-prod-issuer.yaml
files = [
'acme/output/namespaces/jx/acme/templates/part0-cert-manager-prod-issuer.yaml',
'acme/output/namespaces/jx/acme/templates/part0-cert-manager-staging-issuer.yaml',
]
for f in files:
filepath = '/'.join([fpath, f])
slept = 0
while not os.path.exists(filepath):
time.sleep(0.005)
slept += 0.005
if slept > 1:
print("Cannot find file %s after 1 sec of waiting" % filepath)
break
if os.path.isfile(filepath):
fix_file(filepath)
print("FIXED FILE: PATH=[{}] EVENT_TYPES={}".format(fpath, type_names))
def fix_file(fpath):
print(fpath)
with open(fpath, 'r') as file:
doc = yaml.load(file, Loader=yaml.FullLoader)
doc['spec']['acme']['solvers'][0]['dns01'] = {
'cloudflare': {
'email': "your-account@at-cloudflare.com",
'apiKeySecretRef': {
'name': 'cloudflare-api-key-secret',
'key': 'api-key'
}
}
}
with open(fpath, 'w') as file:
yaml.dump(doc, file)
if __name__ == '__main__':
_main()
@stepanselyuk
Copy link
Author

inotify and pyyaml pip modules required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment