Skip to content

Commit

Permalink
add auth method support
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Oct 10, 2024
1 parent 72ebd1b commit 7c648d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/model/oidc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
gqlclient "github.com/pluralsh/console/go/client"
"github.com/pluralsh/polly/algorithms"
"github.com/samber/lo"
)

type OIDCProvider struct {
Expand All @@ -18,17 +19,27 @@ type OIDCProvider struct {
Description types.String `tfsdk:"description"`
ClientID types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
AuthMethod types.String `tfsdk:"auth_method"`
RedirectURIs types.Set `tfsdk:"redirect_uris"`
}

func (p *OIDCProvider) Attributes(ctx context.Context, d diag.Diagnostics) gqlclient.OidcProviderAttributes {
return gqlclient.OidcProviderAttributes{
Name: p.Name.ValueString(),
Description: p.Description.ValueStringPointer(),
AuthMethod: p.authMethodAttribute(),
RedirectUris: p.redirectURIsAttribute(ctx, d),
}
}

func (p *OIDCProvider) authMethodAttribute() *gqlclient.OidcAuthMethod {
if p.AuthMethod.IsNull() {
return nil
}

return lo.ToPtr(gqlclient.OidcAuthMethod(p.AuthMethod.ValueString()))
}

func (p *OIDCProvider) redirectURIsAttribute(ctx context.Context, d diag.Diagnostics) []*string {
redirectURIs := make([]types.String, len(p.RedirectURIs.Elements()))
d.Append(p.RedirectURIs.ElementsAs(ctx, &redirectURIs, false)...)
Expand All @@ -45,5 +56,15 @@ func (p *OIDCProvider) From(response *gqlclient.OIDCProviderFragment, ctx contex
p.Description = types.StringPointerValue(response.Description)
p.ClientID = types.StringValue(response.ClientID)
p.ClientSecret = types.StringValue(response.ClientSecret)
p.AuthMethod = p.authMethodFrom(response.AuthMethod)
p.RedirectURIs = common.SetFrom(response.RedirectUris, ctx, d)

}

func (p *OIDCProvider) authMethodFrom(authMethod *gqlclient.OidcAuthMethod) types.String {
if authMethod == nil {
return types.StringNull()
}

return types.StringValue(string(*authMethod))
}
9 changes: 9 additions & 0 deletions internal/resource/oidc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (r *OIDCProviderResource) Schema(_ context.Context, _ resource.SchemaReques
Sensitive: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"auth_method": schema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive(
algorithms.Map(gqlclient.AllOidcAuthMethod,
func(t gqlclient.OidcAuthMethod) string { return string(t) })...),
},
},
"redirect_uris": schema.SetAttribute{
Optional: true,
ElementType: types.StringType,
Expand Down

0 comments on commit 7c648d9

Please sign in to comment.