Skip to content

Commit

Permalink
DXE-2851 Merge pull request #448 from akamai/release/v5.0.1
Browse files Browse the repository at this point in the history
Release/v5.0.1
  • Loading branch information
wzagrajcz committed Jul 12, 2023
2 parents 3e79eb5 + a3bda57 commit 46f1026
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
version: v1.18.2
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,12 @@
# RELEASE NOTES

## 5.0.1 (Jul 12, 2023)

#### BUG FIXES:

* Reinstated support for configuring provider with environmental variables ([#407](https://github.com/akamai/terraform-provider-akamai/issues/407), [#444](https://github.com/akamai/terraform-provider-akamai/issues/444))
* Fixed `signature does not match` error when using `config` block for authentication ([#444](https://github.com/akamai/terraform-provider-akamai/issues/444), [#446](https://github.com/akamai/terraform-provider-akamai/issues/446))

## 5.0.0 (Jul 5, 2023)

#### BREAKING CHANGES:
Expand Down
2 changes: 1 addition & 1 deletion build/internal/releaser/Dockerfile
Expand Up @@ -22,6 +22,6 @@ RUN apt update && apt install -y curl git gcc ca-certificates openssh-client gnu
&& update-ca-certificates \
&& curl -o go1.18.linux-amd64.tar.gz https://dl.google.com/go/go1.18.linux-amd64.tar.gz \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz \
&& go install github.com/goreleaser/goreleaser@latest \
&& go install github.com/goreleaser/goreleaser@v1.18.2 \
&& mkdir -p /root/.terraform.d/plugins/registry.terraform.io/akamai/akamai/10.0.0/linux_amd64 /root/.ssh

2 changes: 1 addition & 1 deletion docs/guides/get-started.md
Expand Up @@ -21,7 +21,7 @@ Your Akamai Terraform configuration starts with listing us as a required provide
required_providers {
akamai = {
source = "akamai/akamai"
version = "5.0.0"
version = "5.0.1"
}
}
}
Expand Down
19 changes: 6 additions & 13 deletions pkg/akamai/configure_context.go
Expand Up @@ -14,26 +14,19 @@ import (
)

type contextConfig struct {
edgercPath string
edgercSection string
edgercConfig *edgegrid.Config
userAgent string
ctx context.Context
requestLimit int
enableCache bool
edgegridConfig *edgegrid.Config
userAgent string
ctx context.Context
requestLimit int
enableCache bool
}

func configureContext(cfg contextConfig) (*meta.OperationMeta, error) {
operationID := uuid.NewString()
log := logger.FromContext(cfg.ctx, "OperationID", operationID)

edgerc, err := newEdgegridConfig(cfg.edgercPath, cfg.edgercSection, cfg.edgercConfig)
if err != nil {
return nil, err
}

sess, err := session.New(
session.WithSigner(edgerc),
session.WithSigner(cfg.edgegridConfig),
session.WithUserAgent(cfg.userAgent),
session.WithLog(log),
session.WithHTTPTracing(cast.ToBool(os.Getenv("AKAMAI_HTTP_TRACE_ENABLED"))),
Expand Down
75 changes: 62 additions & 13 deletions pkg/akamai/edgegrid.go
Expand Up @@ -10,22 +10,71 @@ import (
// ErrWrongEdgeGridConfiguration is returned when the configuration could not be read
var ErrWrongEdgeGridConfiguration = errors.New("error reading Akamai EdgeGrid configuration")

func newEdgegridConfig(path, section string, config *edgegrid.Config) (*edgegrid.Config, error) {
if (path != "" || section != "") && config != nil {
return nil, fmt.Errorf("edgegrid cannot be simultaneously configured with file and config map") // should not happen as schema guarantees that
var defaultConfigFile = edgegrid.DefaultConfigFile

type configBearer struct {
accessToken string
accountKey string
clientSecret string
clientToken string
host string
maxBody int
}

func (c configBearer) toEdgegridConfig() (*edgegrid.Config, error) {
if !c.valid() {
return nil, ErrWrongEdgeGridConfiguration
}

edgerc := &edgegrid.Config{
AccessToken: c.accessToken,
AccountKey: c.accountKey,
ClientSecret: c.clientSecret,
ClientToken: c.clientToken,
Host: c.host,
MaxBody: c.maxBody,
}

var edgerc *edgegrid.Config
if config != nil {
edgerc = config
} else {
edgerc = &edgegrid.Config{}
err := edgerc.FromFile(edgercPathOrDefault(path), edgercSectionOrDefault(section))
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrWrongEdgeGridConfiguration, err)
}
if edgerc.MaxBody == 0 {
edgerc.MaxBody = edgegrid.MaxBodySize
}

return edgerc, nil
}

func (c configBearer) valid() bool {
return c.host != "" && c.accessToken != "" && c.clientSecret != "" && c.clientToken != ""
}

// newEdgegridConfig creates a new edgegrid.Config based on provided arguments.
//
// It evaluates possibility of creating the config in the following order:
// 1. Environmental variables
// 2. Config block
// 3. Edgerc file
//
// If edgerc path or section are not provided, it uses the edgegrid defaults.
func newEdgegridConfig(path, section string, config configBearer) (*edgegrid.Config, error) {
envEdgerc := &edgegrid.Config{}
err := envEdgerc.FromEnv(edgercSectionOrDefault(section))
if err == nil {
return validateEdgerc(envEdgerc)
}

configEdgerc, err := config.toEdgegridConfig()
if err == nil {
return validateEdgerc(configEdgerc)
}

fileEdgerc := &edgegrid.Config{}
err = fileEdgerc.FromFile(edgercPathOrDefault(path), edgercSectionOrDefault(section))
if err == nil {
return validateEdgerc(fileEdgerc)
}
return nil, fmt.Errorf("%w: %s", ErrWrongEdgeGridConfiguration, err)
}

func validateEdgerc(edgerc *edgegrid.Config) (*edgegrid.Config, error) {
if err := edgerc.Validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrWrongEdgeGridConfiguration, err)
}
Expand All @@ -35,7 +84,7 @@ func newEdgegridConfig(path, section string, config *edgegrid.Config) (*edgegrid

func edgercPathOrDefault(path string) string {
if path == "" {
return edgegrid.DefaultConfigFile
return defaultConfigFile
}
return path
}
Expand Down

0 comments on commit 46f1026

Please sign in to comment.