Skip to content

Commit

Permalink
Enable service account keys to be provided in base64 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
soeirosantos authored Apr 5, 2021
1 parent 5831a7e commit ccfd513
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Refer to GAE [Access Control](https://cloud.google.com/appengine/docs/flexible/p
Use least permissible role for the tasks required.
Typically for `action: deploy` this is `App Engine Admin` and `Cloud Build Service Account`.

If the service account JSON key is provided in base64 format, the plugin will decode it internally.

For example:

```yml
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -244,6 +245,13 @@ func configFromEnv(vargs *GAE, workspace *string) error {
vargs.Token = os.Getenv("GAE_CREDENTIALS")
}

if decodedToken, err := base64.StdEncoding.DecodeString(vargs.Token); err == nil {
// if no error then the token is base64 encoded (or empty)
vargs.Token = string(decodedToken)
} else {
fmt.Println("gae_credentials is not base64 encoded: skipping decode")
}

// Maps
dummyVargs := dummyGAE{}
addlArgs := os.Getenv("PLUGIN_ADDL_ARGS")
Expand Down
19 changes: 19 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,22 @@ func TestSetupFile(t *testing.T) {
}

}

func TestEncodedToken(t *testing.T) {

os.Setenv("PLUGIN_GAE_CREDENTIALS", "ZW5jb2RlZCBzZXJ2aWNlIGFjY291bnQga2V5")

vargs := GAE{}

workspace := ""
configFromEnv(&vargs, &workspace)

expectedDecodedToken := "encoded service account key"
assert.Equal(t, expectedDecodedToken, vargs.Token)

nonEncodedToken := "non-encoded service account key"
os.Setenv("PLUGIN_GAE_CREDENTIALS", nonEncodedToken)

configFromEnv(&vargs, &workspace)
assert.Equal(t, nonEncodedToken, vargs.Token)
}

0 comments on commit ccfd513

Please sign in to comment.