From 4301cefbb78f5abdb9ee7a8b93b266747c94f284 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 17:00:25 +0200 Subject: [PATCH 1/6] Add actions.yml --- action.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..02564ff --- /dev/null +++ b/action.yml @@ -0,0 +1,23 @@ +--- +name: DNSControl Action +description: Deploy your DNS configuration to multiple providers +author: Koen Rouwhorst +branding: + icon: cloud + color: yellow +inputs: + cloudflareApiUser: + description: Cloudflare API user + required: false + cloudflareApiKey: + description: Cloudflare API key + required: false + cloudflareAccountId: + description: Cloudflare account identifier + required: false + cloudflareAccountName: + description: Cloudflare account name + required: false +runs: + using: docker + image: 'Dockerfile' From f4987d1c4c3e06d75a8fa8c829853a1aeed45ffa Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 17:28:08 +0200 Subject: [PATCH 2/6] Fix bats and shellcheck steps --- .github/workflows/build.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 099214d..58dba43 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,11 +14,9 @@ jobs: args: Dockerfile - name: Bats - uses: actions/bin/bats@master + uses: koenrh/actions/bats@master with: args: test/*.bats - name: ShellCheck - uses: actions/bin/shellcheck@master - with: - args: entrypoint.sh + run: shellcheck entrypoint.sh From 0f640fa71b7d3bf1d2df275abd31b579eb5e90d5 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 17:45:06 +0200 Subject: [PATCH 3/6] Update input environment variable names --- entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6ad7eda..3c7b150 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,16 +10,16 @@ add_key () { cat <<< "$(jq "$1 = \"$2\"" < creds.json)" > creds.json } -if [[ -n "$CLOUDFLARE_API_USER" && -n "$CLOUDFLARE_API_KEY" ]] +if [[ -n "$INPUT_CLOUDFLAREAPIUSER" && -n "$INPUT_CLOUDFLAREAPIKEY" ]] then # NOTE: https://stackexchange.github.io/dnscontrol/providers/cloudflare - add_key ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" - add_key ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" + add_key ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" + add_key ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" - if [[ -n "$CLOUDFLARE_ACCOUNT_ID" && -n "$CLOUDFLARE_ACCOUNT_NAME" ]] + if [[ -n "$INPUT_CLOUDFLAREACCOUNTID" && -n "$INPUT_CLOUDFLAREACCOUNTNAME" ]] then - add_key ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID" - add_key ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME" + add_key ".cloudflare.accountid" "\$INPUT_CLOUDFLAREACCOUNTID" + add_key ".cloudflare.accountname" "\$INPUT_CLOUDFLAREACCOUNTNAME" fi fi From 38a9f0dfdc5b7970d73f81551f3223a7c5718b5d Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 17:53:57 +0200 Subject: [PATCH 4/6] Update tests --- test/entrypoint.bats | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/entrypoint.bats b/test/entrypoint.bats index b2c4ced..3f2b315 100644 --- a/test/entrypoint.bats +++ b/test/entrypoint.bats @@ -43,30 +43,30 @@ function assert_key_not_exists { # Cloudflare @test "Cloudflare API user and key are set in credentials file" { - export CLOUDFLARE_API_USER="info@example.com" - export CLOUDFLARE_API_KEY="foo" + export INPUT_CLOUDFLAREAPIUSER="info@example.com" + export INPUT_CLOUDFLAREAPIKEY="foo" run "$WORKSPACE/entrypoint.sh" - assert_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" - assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" + assert_key_equals ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" + assert_key_equals ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" assert_key_not_exists ".cloudflare.accountid" assert_key_not_exists ".cloudflare.accountname" } @test "Cloudflare API user and key, and optional account ID and name are set" { - export CLOUDFLARE_API_USER="info@example.com" - export CLOUDFLARE_API_KEY="foo" - export CLOUDFLARE_ACCOUNT_ID="1" - export CLOUDFLARE_ACCOUNT_NAME="Contoso" + export INPUT_CLOUDFLAREAPIUSER="info@example.com" + export INPUT_CLOUDFLAREAPIKEY="foo" + export INPUT_CLOUDFLAREACCOUNTID="1" + export INPUT_CLOUDFLAREACCOUNTNAME="Contoso" run "$WORKSPACE/entrypoint.sh" - assert_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" - assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" - assert_key_equals ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID" - assert_key_equals ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME" + assert_key_equals ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" + assert_key_equals ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" + assert_key_equals ".cloudflare.accountid" "\$INPUT_CLOUDFLAREACCOUNTID" + assert_key_equals ".cloudflare.accountname" "\$INPUT_CLOUDFLAREACCOUNTNAME" } # DigitalOcean From 2c36d4b48f0896e43d14e5e353bbaf63e8a0fac8 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 17:58:24 +0200 Subject: [PATCH 5/6] Fix Google Cloud integration --- entrypoint.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3c7b150..fc4dea7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,15 +47,15 @@ if [[ -n "$GOOGLE_CLOUD_PROJECT_ID" && -n "$GOOGLE_CLOUD_PRIVATE_KEY_ID" then # NOTE: https://stackexchange.github.io/dnscontrol/providers/gcloud add_key ".gcloud.type" "service_account" - add_key "gcloud.project_id": "\$GOOGLE_CLOUD_PROJECT_ID", - add_key "gcloud.private_key_id": "\$GOOGLE_CLOUD_PRIVATE_KEY_ID", - add_key "gcloud.private_key": "\$GOOGLE_CLOUD_PRIVATE_KEY", - add_key "gcloud.client_email": "\$GOOGLE_CLOUD_CLIENT_EMAIL", - add_key "gcloud.client_id": "\$GOOGLE_CLOUD_CLIENT_ID", - add_key "gcloud.auth_uri": "https://accounts.google.com/o/oauth2/auth", - add_key "gcloud.token_uri": "https://accounts.google.com/o/oauth2/token", - add_key "gcloud.auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - add_key "gcloud.client_x509_cert_url": "\$GOOGLE_CLOUD_CLIENT_X509_CERT_URL" + add_key ".gcloud.project_id": "\$GOOGLE_CLOUD_PROJECT_ID", + add_key ".gcloud.private_key_id": "\$GOOGLE_CLOUD_PRIVATE_KEY_ID", + add_key ".gcloud.private_key": "\$GOOGLE_CLOUD_PRIVATE_KEY", + add_key ".gcloud.client_email": "\$GOOGLE_CLOUD_CLIENT_EMAIL", + add_key ".gcloud.client_id": "\$GOOGLE_CLOUD_CLIENT_ID", + add_key ".gcloud.auth_uri": "https://accounts.google.com/o/oauth2/auth", + add_key ".gcloud.token_uri": "https://accounts.google.com/o/oauth2/token", + add_key ".gcloud.auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + add_key ".gcloud.client_x509_cert_url": "\$GOOGLE_CLOUD_CLIENT_X509_CERT_URL" fi if [[ -n "$LINODE_ACCESS_TOKEN" ]] From 7cb2f08c46d17bc16b9ab07c1c9ee13c6c986db5 Mon Sep 17 00:00:00 2001 From: Koen Rouwhorst Date: Sat, 12 Oct 2019 18:38:57 +0200 Subject: [PATCH 6/6] Add input variable names for other providers --- action.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 55 +++++++++++++++++++++++++++---- test/entrypoint.bats | 24 +++++++------- 3 files changed, 139 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 02564ff..f36854d 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,84 @@ inputs: cloudflareAccountName: description: Cloudflare account name required: false + digitalOceanOAuthToken: + description: Digital Ocean OAuth token + required: false + dnsimpleAccountAccessToken: + description: DNSimple account access token + required: false + gandiApiKey: + description: Gandi API key + required: false + googleCloudDNSProjectId: + description: Google Cloud DNS project identifier + required: false + googleCloudDNSPrivateKeyId: + description: Google Cloud DNS private key identifier + required: false + googleCloudDNSPrivateKey: + description: Google Cloud DNS private key + required: false + googleCloudDNSClientEmail: + description: Google Cloud DNS client email + required: false + googleCloudDNSClientID: + description: Google Cloud DNS client identifier + required: false + googleCloudDNSClientX509CertUrl: + description: Google Cloud DNS client X.509 certificate URL + required: false + linodeAccessToken: + description: Linode access token + required: false + nameComApiUser: + description: Name.com API user + required: false + nameComApiKey: + required: false + description: Name.com API key + nameComApiUrl: + required: false + description: Name.com API URL + namecheapApiUser: + description: Namecheap API user + required: false + namecheapApiKey: + description: Namecheap API key + required: false + namecheapBaseUrl: + description: Namecheap base URL + required: false + nsOneApiKey: + description: NS1 API key + required: false + ovhAppKey: + description: OVH app key + required: false + ovhAppSecretKey: + description: OVH app secret key + required: false + ovhConsumerKey: + description: OVH consumer key + required: false + awsAccessKeyId: + description: AWS access key identifier + required: false + awsSecretAccessKey: + description: AWS secret access key + required: false + awsSessionToken: + description: AWS session token + required: false + softLayerUsername: + description: SoftLayer username + required: false + softLayerApiKey: + description: SoftLayer API key + required: false + vultrToken: + description: Vultr token + required: false runs: using: docker image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index fc4dea7..bacaebb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,16 +10,59 @@ add_key () { cat <<< "$(jq "$1 = \"$2\"" < creds.json)" > creds.json } -if [[ -n "$INPUT_CLOUDFLAREAPIUSER" && -n "$INPUT_CLOUDFLAREAPIKEY" ]] +CLOUDFLARE_API_USER="${INPUT_CLOUDFLAREAPIUSER:-$CLOUDFLARE_API_USER}" +CLOUDFLARE_API_KEY="${INPUT_CLOUDFLAREAPIKEY:-$CLOUDFLARE_API_KEY}" +CLOUDFLARE_ACCOUNT_ID="${INPUT_CLOUDFLAREACCOUNTID:-$CLOUDFLARE_ACCOUNT_ID}" +CLOUDFLARE_ACCOUNT_NAME="${INPUT_CLOUDFLAREACCOUNTNAME:-$CLOUDFLARE_ACCOUNT_NAME}" + +DIGITALOCEAN_OAUTH_TOKEN="${INPUT_DIGITALOCEANOAUTHTOKEN:-$DIGITALOCEAN_OAUTH_TOKEN}" + +DNSIMPLE_ACCOUNT_ACCESS_TOKEN="${INPUT_DNSIMPLEACCOUNTACCESSTOKEN:-$DNSIMPLE_ACCOUNT_ACCESS_TOKEN}" + +GANDI_API_KEY="${INPUT_GANDIAPIKEY:-$GANDI_API_KEY}" + +GOOGLE_CLOUD_PROJECT_ID="${INPUT_GOOGLECLOUDPROJECTID:-$GOOGLE_CLOUD_PROJECT_ID}" +GOOGLE_CLOUD_PRIVATE_KEY_ID="${INPUT_GOOGLECLOUDPRIVATEKEYID:-$GOOGLE_CLOUD_PRIVATE_KEY_ID}" +GOOGLE_CLOUD_PRIVATE_KEY="${INPUT_GOOGLECLOUDPRIVATEKEY:-$GOOGLE_CLOUD_PRIVATE_KEY}" +GOOGLE_CLOUD_CLIENT_EMAIL="${INPUT_GOOGLECLOUDCLIENTEMAIL:-$GOOGLE_CLOUD_CLIENT_EMAIL}" +GOOGLE_CLOUD_CLIENT_ID="${INPUT_GOOGLECLOUDCLIENTID:-$GOOGLE_CLOUD_CLIENT_ID}" +GOOGLE_CLOUD_CLIENT_X509_CERT_URL="${INPUT_GOOGLECLOUDCLIENTX509CERTURL:-$GOOGLE_CLOUD_CLIENT_X509_CERT_URL}" + +LINODE_ACCESS_TOKEN="${INPUT_LINODEACCESSTOKEN:-$LINODE_ACCESS_TOKEN}" + +NAME_COM_API_USER="${INPUT_NAMECOMAPIUSER:-$NAME_COM_API_USER}" +NAME_COM_API_KEY="${INPUT_NAMECOMAPIKEY:-$NAME_COM_API_KEY}" +NAME_COM_API_URL="${INPUT_NAMECOMAPIURL:-$NAME_COM_API_URL}" + +NAMECHEAP_API_USER="${INPUT_NAMECOMAPIUSER:-$NAME_COM_API_USER}" +NAMECHEAP_API_KEY="${INPUT_NAMECOMAPIKEY:-$NAME_COM_API_KEY}" +NAMECHEAP_BASE_URL="${INPUT_NAMECOMBASEURL:-$NAME_COM_BASE_URL}" + +NSONE_API_KEY="${INPUT_NSONEAPIKEY:-$NSONE_API_KEY}" + +OVH_APP_KEY="${INPUT_OVHAPPKEY:-$OVH_APP_KEY}" +OVH_APP_SECRET_KEY="${INPUT_OVHAPPSECRETKEY:-$OVH_APP_SECRET_KEY}" +OVH_CONSUMER_KEY="${INPUT_OVHCONSUMERKEY:-$OVH_CONSUMER_KEY}" + +AWS_ACCESS_KEY_ID="${INPUT_AWSACCESSKEYID:-$AWS_ACCESS_KEY_ID}" +AWS_SECRET_ACCESS_KEY="${INPUT_AWSSECRETACCESSKEYID:-$AWS_SECRET_ACCESS_KEY}" +AWS_SESSION_TOKEN="${INPUT_AWSSESSIONTOKEN:-$AWS_SESSION_TOKEN}" + +SOFTLAYER_USERNAME="${INPUT_SOFTLAYERUSERNAME:-$SOFTLAYER_USERNAME}" +SOFTLAYER_API_KEY="${INPUT_SOFTLAYERAPIKEY:-$SOFTLAYER_API_KEY}" + +VULTR_TOKEN="${INPUT_VULTRTOKEN:-$VULTR_TOKEN}" + +if [[ -n "$CLOUDFLARE_API_USER" && -n "$CLOUDFLARE_API_KEY" ]] then # NOTE: https://stackexchange.github.io/dnscontrol/providers/cloudflare - add_key ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" - add_key ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" + add_key ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" + add_key ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" - if [[ -n "$INPUT_CLOUDFLAREACCOUNTID" && -n "$INPUT_CLOUDFLAREACCOUNTNAME" ]] + if [[ -n "$CLOUDFLARE_ACCOUNT_ID" && -n "$CLOUDFLARE_ACCOUNT_NAME" ]] then - add_key ".cloudflare.accountid" "\$INPUT_CLOUDFLAREACCOUNTID" - add_key ".cloudflare.accountname" "\$INPUT_CLOUDFLAREACCOUNTNAME" + add_key ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID" + add_key ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME" fi fi diff --git a/test/entrypoint.bats b/test/entrypoint.bats index 3f2b315..b2c4ced 100644 --- a/test/entrypoint.bats +++ b/test/entrypoint.bats @@ -43,30 +43,30 @@ function assert_key_not_exists { # Cloudflare @test "Cloudflare API user and key are set in credentials file" { - export INPUT_CLOUDFLAREAPIUSER="info@example.com" - export INPUT_CLOUDFLAREAPIKEY="foo" + export CLOUDFLARE_API_USER="info@example.com" + export CLOUDFLARE_API_KEY="foo" run "$WORKSPACE/entrypoint.sh" - assert_key_equals ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" - assert_key_equals ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" + assert_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" + assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" assert_key_not_exists ".cloudflare.accountid" assert_key_not_exists ".cloudflare.accountname" } @test "Cloudflare API user and key, and optional account ID and name are set" { - export INPUT_CLOUDFLAREAPIUSER="info@example.com" - export INPUT_CLOUDFLAREAPIKEY="foo" - export INPUT_CLOUDFLAREACCOUNTID="1" - export INPUT_CLOUDFLAREACCOUNTNAME="Contoso" + export CLOUDFLARE_API_USER="info@example.com" + export CLOUDFLARE_API_KEY="foo" + export CLOUDFLARE_ACCOUNT_ID="1" + export CLOUDFLARE_ACCOUNT_NAME="Contoso" run "$WORKSPACE/entrypoint.sh" - assert_key_equals ".cloudflare.apiuser" "\$INPUT_CLOUDFLAREAPIUSER" - assert_key_equals ".cloudflare.apikey" "\$INPUT_CLOUDFLAREAPIKEY" - assert_key_equals ".cloudflare.accountid" "\$INPUT_CLOUDFLAREACCOUNTID" - assert_key_equals ".cloudflare.accountname" "\$INPUT_CLOUDFLAREACCOUNTNAME" + assert_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" + assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" + assert_key_equals ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID" + assert_key_equals ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME" } # DigitalOcean