Skip to content

Commit 43b3f1b

Browse files
committed
ref: remove api_key from provider config
1 parent a80a0fd commit 43b3f1b

File tree

4 files changed

+4
-32
lines changed

4 files changed

+4
-32
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
- run: go mod download
8282
- env:
8383
TF_ACC: "1"
84-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
8584
OPENAI_SESSION_KEY: ${{ secrets.OPENAI_SESSION_KEY }}
8685
OPENAI_TEST_ORGANIZATION_ID: ${{ secrets.OPENAI_TEST_ORGANIZATION_ID }}
8786
run: go test -v -cover ./internal/provider/

docs/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ provider "openai" {
2323

2424
### Optional
2525

26-
- `api_key` (String, Sensitive) API key for the OpenAI API.
2726
- `base_url` (String) Base URL for the OpenAI API. Defaults to `https://api.openai.com`.
2827
- `session_key` (String, Sensitive) Session key for the OpenAI API.

internal/acctest/acctest.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
)
77

88
var (
9+
TestSessionKey = os.Getenv("OPENAI_SESSION_KEY")
910
TestOrganizationId = os.Getenv("OPENAI_TEST_ORGANIZATION_ID")
10-
TestApiKey = os.Getenv("OPENAI_API_KEY")
1111
)
1212

1313
func PreCheck(t *testing.T) {
14-
if TestApiKey == "" {
15-
t.Fatal("OPENAI_API_KEY must be set for acceptance tests")
14+
if TestSessionKey == "" {
15+
t.Fatal("OPENAI_SESSION_KEY must be set for acceptance tests")
1616
}
1717

1818
if TestOrganizationId == "" {

internal/provider/provider.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type OpenAIProvider struct {
3030
// OpenAIProviderModel describes the provider data model.
3131
type OpenAIProviderModel struct {
3232
BaseUrl types.String `tfsdk:"base_url"`
33-
ApiKey types.String `tfsdk:"api_key"`
3433
SessionKey types.String `tfsdk:"session_key"`
3534
}
3635

@@ -46,11 +45,6 @@ func (p *OpenAIProvider) Schema(ctx context.Context, req provider.SchemaRequest,
4645
MarkdownDescription: "Base URL for the OpenAI API. Defaults to `https://api.openai.com`.",
4746
Optional: true,
4847
},
49-
"api_key": schema.StringAttribute{
50-
MarkdownDescription: "API key for the OpenAI API.",
51-
Optional: true,
52-
Sensitive: true,
53-
},
5448
"session_key": schema.StringAttribute{
5549
MarkdownDescription: "Session key for the OpenAI API.",
5650
Optional: true,
@@ -76,21 +70,6 @@ func (p *OpenAIProvider) Configure(ctx context.Context, req provider.ConfigureRe
7670
baseUrl = "https://api.openai.com"
7771
}
7872

79-
var apiKey string
80-
if !data.ApiKey.IsNull() {
81-
apiKey = data.ApiKey.ValueString()
82-
} else if v := os.Getenv("OPENAI_API_KEY"); v != "" {
83-
apiKey = v
84-
}
85-
86-
if apiKey == "" {
87-
resp.Diagnostics.AddError("api_key is required", "api_key is required")
88-
return
89-
} else if !strings.HasPrefix(apiKey, "sk-") {
90-
resp.Diagnostics.AddError("api_key must start with 'sk-'", "api_key must start with 'sk-'")
91-
return
92-
}
93-
9473
var sessionKey string
9574
if !data.SessionKey.IsNull() {
9675
sessionKey = data.SessionKey.ValueString()
@@ -109,12 +88,7 @@ func (p *OpenAIProvider) Configure(ctx context.Context, req provider.ConfigureRe
10988
client, err := apiclient.NewClientWithResponses(
11089
baseUrl,
11190
apiclient.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
112-
if strings.HasPrefix(req.URL.Path, "/v1") {
113-
req.Header.Set("Authorization", "Bearer "+apiKey)
114-
} else if strings.HasPrefix(req.URL.Path, "/dashboard") {
115-
req.Header.Set("Authorization", "Bearer "+sessionKey)
116-
}
117-
91+
req.Header.Set("Authorization", "Bearer "+sessionKey)
11892
return nil
11993
}),
12094
)

0 commit comments

Comments
 (0)