Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: oauth integration #1315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/oauth_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ resource "snowflake_oauth_integration" "tableau_desktop" {
- `blocked_roles_list` (Set of String) List of roles that a user cannot explicitly consent to using after authenticating. Do not include ACCOUNTADMIN, ORGADMIN or SECURITYADMIN as they are already implicitly enforced and will cause in-place updates.
- `comment` (String) Specifies a comment for the OAuth integration.
- `enabled` (Boolean) Specifies whether this OAuth integration is enabled or disabled.
- `oauth_client_type` (String) Specifies the type of client being registered. Snowflake supports both confidential and public clients.
- `oauth_issue_refresh_tokens` (Boolean) Specifies whether to allow the client to exchange a refresh token for an access token when the current access token has expired.
- `oauth_redirect_uri` (String) Specifies the client URI. After a user is authenticated, the web browser is redirected to this URI.
- `oauth_refresh_token_validity` (Number) Specifies how long refresh tokens should be valid (in seconds). OAUTH_ISSUE_REFRESH_TOKENS must be set to TRUE.
Expand Down
21 changes: 19 additions & 2 deletions pkg/resources/oauth_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ var oauthIntegrationSchema = map[string]*schema.Schema{
Optional: true,
Description: "Specifies the client URI. After a user is authenticated, the web browser is redirected to this URI.",
},
"oauth_client_type": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the type of client being registered. Snowflake supports both confidential and public clients.",
ValidateFunc: validation.StringInSlice([]string{
"CONFIDENTIAL", "PUBLIC",
}, false),
},
"oauth_issue_refresh_tokens": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -104,7 +112,9 @@ func CreateOAuthIntegration(d *schema.ResourceData, meta interface{}) error {
if _, ok := d.GetOk("oauth_redirect_uri"); ok {
stmt.SetString(`OAUTH_REDIRECT_URI`, d.Get("oauth_redirect_uri").(string))
}

if _, ok := d.GetOk("oauth_client_type"); ok {
stmt.SetString(`OAUTH_CLIENT_TYPE`, d.Get("oauth_client_type").(string))
}
if _, ok := d.GetOk("oauth_issue_refresh_tokens"); ok {
stmt.SetBool(`OAUTH_ISSUE_REFRESH_TOKENS`, d.Get("oauth_issue_refresh_tokens").(bool))
}
Expand Down Expand Up @@ -233,7 +243,9 @@ func ReadOAuthIntegration(d *schema.ResourceData, meta interface{}) error {
return errors.Wrap(err, "unable to set OAuth redirect URI for security integration")
}
case "OAUTH_CLIENT_TYPE":
// Only used for custom OAuth clients (not supported yet)
if err = d.Set("oauth_client_type", v.(string)); err != nil {
return errors.Wrap(err, "unable to set OAuth client type for security integration")
}
case "OAUTH_ENFORCE_PKCE":
// Only used for custom OAuth clients (not supported yet)
case "OAUTH_AUTHORIZATION_ENDPOINT":
Expand Down Expand Up @@ -274,6 +286,11 @@ func UpdateOAuthIntegration(d *schema.ResourceData, meta interface{}) error {
stmt.SetString(`OAUTH_REDIRECT_URI`, d.Get("oauth_redirect_uri").(string))
}

if d.HasChange("oauth_client_type") {
runSetStatement = true
stmt.SetString(`OAUTH_CLIENT_TYPE`, d.Get("oauth_client_type").(string))
}

if d.HasChange("oauth_issue_refresh_tokens") {
runSetStatement = true
stmt.SetBool(`OAUTH_ISSUE_REFRESH_TOKENS`, d.Get("oauth_issue_refresh_tokens").(bool))
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/oauth_integration_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func oauthIntegrationConfig(name string, integrationType string) string {
resource "snowflake_oauth_integration" "test" {
name = "%s"
oauth_client = "%s"
oauth_client_type = "PUBLIC"
enabled = true
oauth_issue_refresh_tokens = true
oauth_refresh_token_validity = 3600
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
taskIDDelimiter = '|'
taskIDDelimiter = '|'
)

var taskSchema = map[string]*schema.Schema{
Expand Down