Skip to content

Commit f0e75c6

Browse files
auth-templating
Summary: - Support for `account_id` `auth` DTO attribute. - Naive, structure-internal `golang` templating supported for `token_url` field **only** in `auth` DTO. - Amended test materials for robot test `Oauth2 CLient Credentials Auth Should Succeed with Valid Config`, in order to cover off new functionality.
1 parent 0d4c37c commit f0e75c6

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/spf13/cobra v1.4.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/spf13/viper v1.10.1
24-
github.com/stackql/any-sdk v0.0.3-beta21
24+
github.com/stackql/any-sdk v0.0.3-beta26
2525
github.com/stackql/go-suffix-map v0.0.1-alpha01
2626
github.com/stackql/psql-wire v0.1.1-alpha07
2727
github.com/stackql/stackql-parser v0.0.14-alpha04

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
471471
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
472472
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
473473
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
474-
github.com/stackql/any-sdk v0.0.3-beta21 h1:1x76S9scXukHKcBUmzSVYpwWG8TnZXMhlgU0HHcTO2g=
475-
github.com/stackql/any-sdk v0.0.3-beta21/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
474+
github.com/stackql/any-sdk v0.0.3-beta26 h1:pl8UwijDcg/87QsGZP+Odc/zCSBt4WCaEN/EiCrzarc=
475+
github.com/stackql/any-sdk v0.0.3-beta26/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
476476
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
477477
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
478478
github.com/stackql/psql-wire v0.1.1-alpha07 h1:LQWVUlx4Bougk6dztDNG5tmXxpIVeeTSsInTj801xCs=

internal/stackql/dto/auth_ctx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type AuthCtx struct {
5151
ClientSecretEnvVar string `json:"client_secret_env_var" yaml:"client_secret_env_var"`
5252
Values url.Values `json:"values" yaml:"values"`
5353
AuthStyle int `json:"auth_style" yaml:"auth_style"`
54+
AccountID string `json:"account_id" yaml:"account_id"`
55+
AccoountIDEnvVar string `json:"account_id_env_var" yaml:"account_id_var"`
5456
}
5557

5658
func (ac *AuthCtx) GetSQLCfg() (SQLBackendCfg, bool) {
@@ -96,6 +98,8 @@ func (ac *AuthCtx) Clone() *AuthCtx {
9698
ClientSecretEnvVar: ac.ClientSecretEnvVar,
9799
Values: ac.Values,
98100
AuthStyle: ac.AuthStyle,
101+
AccountID: ac.AccountID,
102+
AccoountIDEnvVar: ac.AccoountIDEnvVar,
99103
}
100104
return rv
101105
}

internal/stackql/handler/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ func transformOpenapiStackqlAuthToLocal(authDTO anysdk.AuthDTO) *dto.AuthCtx {
583583
ClientSecretEnvVar: authDTO.GetClientSecretEnvVar(),
584584
Values: authDTO.GetValues(),
585585
AuthStyle: authDTO.GetAuthStyle(),
586+
AccountID: authDTO.GetAccountID(),
587+
AccoountIDEnvVar: authDTO.GetAccountIDEnvVar(),
586588
}
587589
successor, successorExists := authDTO.GetSuccessor()
588590
currentParent := rv

internal/stackql/provider/auth_util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77

8+
"github.com/stackql/any-sdk/pkg/litetemplate"
89
"github.com/stackql/stackql/internal/stackql/constants"
910
"github.com/stackql/stackql/internal/stackql/dto"
1011
"github.com/stackql/stackql/internal/stackql/netutils"
@@ -199,11 +200,15 @@ func getGenericClientCredentialsConfig(authCtx *dto.AuthCtx, scopes []string) (*
199200
if secretErr != nil {
200201
return nil, secretErr
201202
}
203+
templatedTokenURL, templateErr := litetemplate.RenderTemplateFromSerializable(authCtx.GetTokenURL(), authCtx)
204+
if templateErr != nil {
205+
return nil, fmt.Errorf("incorrect token url templating %w", templateErr)
206+
}
202207
rv := &clientcredentials.Config{
203208
ClientID: clientID,
204209
ClientSecret: clientSecret,
205210
Scopes: scopes,
206-
TokenURL: authCtx.GetTokenURL(),
211+
TokenURL: templatedTokenURL,
207212
}
208213
if len(authCtx.GetValues()) > 0 {
209214
rv.EndpointParams = authCtx.GetValues()

test/registry/src/stackql_oauth2_testing/v0.1.0/provider.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ config:
2525
auth:
2626
client_id_env_var: 'YOUR_OAUTH2_CLIENT_ID_ENV_VAR'
2727
client_secret_env_var: 'YOUR_OAUTH2_CLIENT_SECRET_ENV_VAR'
28+
account_id: 'contrived'
2829
type: "oauth2"
2930
grant_type: "client_credentials"
30-
token_url: 'http://localhost:2091/contrived/simple/token'
31+
token_url: 'http://localhost:2091/{{ .account_id }}/simple/token'
3132
scopes:
3233
- 'scope-01'
3334
- 'scope-02'

0 commit comments

Comments
 (0)