Skip to content

Commit

Permalink
Set terraform provider to use OPAL_AUTH_TOKEN envar to base as bearer…
Browse files Browse the repository at this point in the history
…_auth to provider. (#76)
  • Loading branch information
amruth-opal authored Jul 23, 2024
1 parent cd26672 commit 1c49746
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 17 deletions.
10 changes: 5 additions & 5 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ id: b5c8bf75-06e1-47c8-b9ae-ce49ba56069d
management:
docChecksum: a107ffd47833df714c17fbb8f44eb9c0
docVersion: "1.0"
speakeasyVersion: 1.344.2
generationVersion: 2.377.1
releaseVersion: 0.23.0
configChecksum: 04608bbdbcc98f993d4309aa058b6484
speakeasyVersion: 1.345.3
generationVersion: 2.378.3
releaseVersion: 0.23.1
configChecksum: b6a0270266465815fae95e0a1038eca3
repoURL: https://github.com/opalsecurity/terraform-provider-opal.git
repoSubDirectory: .
published: true
Expand All @@ -15,7 +15,7 @@ features:
additionalDependencies: 0.1.0
additionalProperties: 0.1.2
constsAndDefaults: 0.1.4
core: 3.24.1
core: 3.24.2
deprecations: 2.81.1
globalSecurity: 2.81.6
globalServerURLs: 2.82.1
Expand Down
6 changes: 3 additions & 3 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
speakeasyVersion: 1.344.2
speakeasyVersion: 1.345.3
sources:
opal-terraform-provider:
sourceNamespace: opal-terraform-provider
sourceRevisionDigest: sha256:faa79cb2eee4d0657309701ae709eb26913a83bf9b7af7df4e6fb1a1bfc4cde4
sourceRevisionDigest: sha256:fe19f5356675f1f897227b4f8ab1411ecc32b41f2d4d0e676d9c79a4afd87812
sourceBlobDigest: sha256:66b70d74e51f3898206042823c9b7a5feb55bd42f22f6a9d94c7856d6f8c8f55
tags:
- latest
targets:
terraform:
source: opal-terraform-provider
sourceNamespace: opal-terraform-provider
sourceRevisionDigest: sha256:faa79cb2eee4d0657309701ae709eb26913a83bf9b7af7df4e6fb1a1bfc4cde4
sourceRevisionDigest: sha256:fe19f5356675f1f897227b4f8ab1411ecc32b41f2d4d0e676d9c79a4afd87812
sourceBlobDigest: sha256:66b70d74e51f3898206042823c9b7a5feb55bd42f22f6a9d94c7856d6f8c8f55
outLocation: .
workflow:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
required_providers {
opal = {
source = "opalsecurity/opal"
version = "0.23.0"
version = "0.23.1"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
opal = {
source = "opalsecurity/opal"
version = "0.23.0"
version = "0.23.1"
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ generation:
requestResponseComponentNamesFeb2024: false
auth:
oAuth2ClientCredentialsEnabled: false
baseServerURL: ""
flattenGlobalSecurity: true
terraform:
version: 0.23.0
version: 0.23.1
additionalDataSources: []
additionalDependencies: {}
additionalResources: []
allowUnknownFieldsInWeakUnions: false
author: opalsecurity
environmentVariables: []
environmentVariables:
- env: OPAL_AUTH_TOKEN
providerAttribute: bearer_auth
imports:
option: openapi
paths:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.10.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-testing v1.9.0
github.com/pkg/errors v0.9.1
)

require (
Expand Down Expand Up @@ -58,7 +59,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/russross/blackfriday v1.6.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
Expand Down
7 changes: 6 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/opalsecurity/terraform-provider-opal/internal/sdk"
"github.com/opalsecurity/terraform-provider-opal/internal/sdk/models/shared"
"net/http"
"os"
)

var _ provider.Provider = &OpalProvider{}
Expand Down Expand Up @@ -70,7 +71,11 @@ func (p *OpalProvider) Configure(ctx context.Context, req provider.ConfigureRequ
if !data.BearerAuth.IsUnknown() && !data.BearerAuth.IsNull() {
*bearerAuth = data.BearerAuth.ValueString()
} else {
bearerAuth = nil
if len(os.Getenv("OPAL_AUTH_TOKEN")) > 0 {
*bearerAuth = os.Getenv("OPAL_AUTH_TOKEN")
} else {
bearerAuth = nil
}
}
security := shared.Security{
BearerAuth: bearerAuth,
Expand Down
5 changes: 5 additions & 0 deletions internal/sdk/internal/utils/queryparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
)

func PopulateQueryParams(_ context.Context, req *http.Request, queryParams interface{}, globals interface{}) error {
// Query parameters may already be present from overriding URL
if req.URL.RawQuery != "" {
return nil
}

values := url.Values{}

globalsAlreadyPopulated, err := populateQueryParams(queryParams, globals, values, []string{})
Expand Down
14 changes: 14 additions & 0 deletions internal/sdk/models/operations/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
SupportedOptionRetries = "retries"
SupportedOptionTimeout = "timeout"
SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride"
SupportedOptionURLOverride = "urlOverride"
)

type AcceptHeaderEnum string
Expand All @@ -34,6 +35,7 @@ type Options struct {
Retries *retry.Config
Timeout *time.Duration
AcceptHeaderOverride *AcceptHeaderEnum
URLOverride *string
}

type Option func(*Options, ...string) error
Expand Down Expand Up @@ -100,3 +102,15 @@ func WithAcceptHeaderOverride(acceptHeaderOverride AcceptHeaderEnum) Option {
return nil
}
}

// WithURLOverride allows overriding the URL.
func WithURLOverride(urlOverride string) Option {
return func(opts *Options, supportedOptions ...string) error {
if !utils.Contains(supportedOptions, SupportedOptionURLOverride) {
return ErrUnsupportedOption
}

opts.URLOverride = &urlOverride
return nil
}
}
4 changes: 2 additions & 2 deletions internal/sdk/opalapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func New(opts ...SDKOption) *OpalAPI {
Language: "go",
OpenAPIDocVersion: "1.0",
SDKVersion: "0.0.1",
GenVersion: "2.377.1",
UserAgent: "speakeasy-sdk/go 0.0.1 2.377.1 1.0 github.com/opalsecurity/terraform-provider-opal/internal/sdk",
GenVersion: "2.378.3",
UserAgent: "speakeasy-sdk/go 0.0.1 2.378.3 1.0 github.com/opalsecurity/terraform-provider-opal/internal/sdk",
Hooks: hooks.New(),
},
}
Expand Down

0 comments on commit 1c49746

Please sign in to comment.