Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions plugins/akamai/api_client_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,22 @@ func APIClientCredentials() schema.CredentialType {
},
},
},
DefaultProvisioner: provision.TempFile(configFile,
provision.Filename(".edgerc"),
provision.AddArgs(
"--edgerc", "{{ .Path }}",
"--section", "default",
),
provision.SetPathAsEnvVar("EDGERC"), // for Akamai Terraform provider
),
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
TryAkamaiConfigFile(),
)}
}

func configFile(in sdk.ProvisionInput) ([]byte, error) {
contents := "[default]\n"

if clientsecret, ok := in.ItemFields[fieldname.ClientSecret]; ok {
contents += "client_secret = " + clientsecret + "\n"
}

if host, ok := in.ItemFields[fieldname.Host]; ok {
contents += "host = " + host + "\n"
}

if accesstoken, ok := in.ItemFields[fieldname.AccessToken]; ok {
contents += "access_token = " + accesstoken + "\n"
}

if clienttoken, ok := in.ItemFields[fieldname.ClientToken]; ok {
contents += "client_token = " + clienttoken + "\n"
}

return []byte(contents), nil
// Akamai's edgegrid library (used by the Akamai CLI and its sub-packages) checks these
// environment variables before falling back to the ~/.edgerc file. Using them avoids
// relying on command-line flag injection, which several Akamai CLI packages (e.g. cli-gtm)
// don't parse correctly when the flags are appended after the subcommand.
// See: https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/master/pkg/edgegrid/config.go
var defaultEnvVarMapping = map[string]sdk.FieldName{
"AKAMAI_HOST": fieldname.Host,
"AKAMAI_CLIENT_TOKEN": fieldname.ClientToken,
"AKAMAI_CLIENT_SECRET": fieldname.ClientSecret,
"AKAMAI_ACCESS_TOKEN": fieldname.AccessToken,
}

// Load credentials from the ~/.edgerc file.
Expand Down
9 changes: 4 additions & 5 deletions plugins/akamai/api_client_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ func TestAPIClientCredentialsProvisioner(t *testing.T) {
fieldname.ClientToken: "akab-nomoflavjuc4422e-fa2xznerxrm3teg7",
},
ExpectedOutput: sdk.ProvisionOutput{
CommandLine: []string{"--edgerc", "/tmp/.edgerc", "--section", "default"},
Files: map[string]sdk.OutputFile{
"/tmp/.edgerc": {Contents: []byte(plugintest.LoadFixture(t, ".edgerc-single"))},
},
Environment: map[string]string{
"EDGERC": "/tmp/.edgerc",
"AKAMAI_HOST": "akab-lmn789n2k53w7qrs-nfkxaa4lfk3kd6ym.luna.akamaiapis.net",
"AKAMAI_CLIENT_TOKEN": "akab-nomoflavjuc4422e-fa2xznerxrm3teg7",
"AKAMAI_CLIENT_SECRET": "abcdE23FNkBxy456z25qx9Yp5CPUxlEfQeTDkfh4QA=I",
"AKAMAI_ACCESS_TOKEN": "akab-zyx987xa6osbli4k-e7jf5ikib5jknes3",
},
},
},
Expand Down