Skip to content

Commit a80a0fd

Browse files
committed
ref: validate config keys
1 parent f05b890 commit a80a0fd

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
- env:
8383
TF_ACC: "1"
8484
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
85+
OPENAI_SESSION_KEY: ${{ secrets.OPENAI_SESSION_KEY }}
8586
OPENAI_TEST_ORGANIZATION_ID: ${{ secrets.OPENAI_TEST_ORGANIZATION_ID }}
8687
run: go test -v -cover ./internal/provider/
8788
timeout-minutes: 10

internal/provider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func (p *OpenAIProvider) Configure(ctx context.Context, req provider.ConfigureRe
8686
if apiKey == "" {
8787
resp.Diagnostics.AddError("api_key is required", "api_key is required")
8888
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
8992
}
9093

9194
var sessionKey string
@@ -98,6 +101,9 @@ func (p *OpenAIProvider) Configure(ctx context.Context, req provider.ConfigureRe
98101
if sessionKey == "" {
99102
resp.Diagnostics.AddError("session_key is required", "session_key is required")
100103
return
104+
} else if !strings.HasPrefix(sessionKey, "sess-") {
105+
resp.Diagnostics.AddError("session_key must start with 'sess-'", "session_key must start with 'sess-'")
106+
return
101107
}
102108

103109
client, err := apiclient.NewClientWithResponses(

0 commit comments

Comments
 (0)