Skip to content

Commit

Permalink
Merge pull request #29 from axiomhq/advanced-api-token-support
Browse files Browse the repository at this point in the history
  • Loading branch information
toppercodes authored Apr 25, 2024
2 parents 4ff3f8a + 208b08f commit b43a014
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 88 deletions.
1 change: 0 additions & 1 deletion .github/workflows/acc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- name: Acceptance Tests
env:
AXIOM_TOKEN: ${{ secrets.TF_PROVIDER_API_TOKEN }}
AXIOM_ORG_ID: ${{ vars.AXIOM_ORG_ID }}
AXIOM_URL: ${{ vars.AXIOM_URL }}
run: |
make testacc
35 changes: 16 additions & 19 deletions axiom/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package axiom
import (
"context"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/path"
Expand All @@ -26,7 +27,6 @@ var (
// AxiomProviderModel describes the provider data model.
type AxiomProviderModel struct {
ApiToken types.String `tfsdk:"api_token"`
OrgID types.String `tfsdk:"org_id"`
BaseUrl types.String `tfsdk:"base_url"`
}

Expand All @@ -51,11 +51,6 @@ func (p *axiomProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp
Required: true,
MarkdownDescription: "The Axiom API token.",
},
"org_id": schema.StringAttribute{
Required: false,
MarkdownDescription: "The Axiom organization ID.",
Optional: true,
},
"base_url": schema.StringAttribute{
Optional: true,
MarkdownDescription: "The base url of the axiom api.",
Expand All @@ -71,31 +66,33 @@ func (p *axiomProvider) Configure(ctx context.Context, req provider.ConfigureReq
if resp.Diagnostics.HasError() {
return
}
if config.ApiToken.IsNull() {
resp.Diagnostics.AddAttributeError(
path.Root("token"),
"ApiToken is required",
"Please set the token in the provider configuration block.",
)
return
}

apiToken := os.Getenv("AXIOM_API_TOKEN")
orgID := os.Getenv("AXIOM_ORG_ID")
baseUrl := os.Getenv("AXIOM_BASE_URL")

if !config.ApiToken.IsNull() {
apiToken = config.ApiToken.ValueString()
}
if !config.OrgID.IsNull() {
orgID = config.OrgID.ValueString()
}
if !config.BaseUrl.IsNull() {
baseUrl = config.BaseUrl.ValueString()
}

if apiToken == "" {
resp.Diagnostics.AddAttributeError(
path.Root("token"),
"ApiToken is required",
"Please set the token in the provider configuration block.",
)
return
}

if !strings.HasPrefix(apiToken, "xaat-") {
resp.Diagnostics.AddError("invalid api token", "Please set a valid advanced api token in the provider configuration block.")
return
}

ops := []ax.Option{
ax.SetPersonalTokenConfig(apiToken, orgID),
ax.SetAPITokenConfig(apiToken),
ax.SetUserAgent(providerUserAgent),
}

Expand Down
5 changes: 2 additions & 3 deletions axiom/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"strings"
"testing"

ax "github.com/axiomhq/axiom-go/axiom"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"

ax "github.com/axiomhq/axiom-go/axiom"
)

func TestAccAxiomResources_basic(t *testing.T) {
Expand Down Expand Up @@ -165,7 +166,6 @@ func testAccAxiomDatasetConfig_basic(orgID string) string {
return `
provider "axiom" {
api_token = "` + os.Getenv("AXIOM_TOKEN") + `"
org_id = "` + orgID + `"
base_url = "` + os.Getenv("AXIOM_URL") + `"
}
Expand Down Expand Up @@ -229,7 +229,6 @@ func TestAccAxiomResources_data(t *testing.T) {
Config: `
provider "axiom" {
api_token = "` + os.Getenv("AXIOM_TOKEN") + `"
org_id = "` + os.Getenv("AXIOM_ORG_ID") + `"
base_url = "` + os.Getenv("AXIOM_URL") + `"
}
Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ data "axiom_dataset" "test_dataset" {
### Required

- `api_token` (String) The Axiom API token.
- `org_id` (String) The Axiom organization ID.

### Optional

Expand All @@ -90,7 +89,6 @@ terraform {
provider "axiom" {
api_token = ""
org_id = ""
base_url = "https://api.axiom.co"
}
Expand Down
33 changes: 17 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module terraform-provider-axiom-provider
go 1.21

require (
github.com/axiomhq/axiom-go v0.17.5
github.com/axiomhq/axiom-go v0.17.6
github.com/hashicorp/terraform-plugin-docs v0.18.0
github.com/hashicorp/terraform-plugin-framework v1.7.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
Expand All @@ -23,7 +23,7 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.16.0 // indirect
Expand Down Expand Up @@ -55,7 +55,7 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand All @@ -77,21 +77,22 @@ require (
github.com/yuin/goldmark v1.6.0 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.51.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit b43a014

Please sign in to comment.