Skip to content

Commit

Permalink
remove deprecated jwks endpoint (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
GokceGK authored Aug 26, 2024
1 parent a10c4a5 commit 6281701
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 57 deletions.
1 change: 0 additions & 1 deletion docs/stackit_config_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ stackit config set [flags]
--iaas-custom-endpoint string IaaS API base URL, used in calls to this API
--identity-provider-custom-client-id string Identity Provider client ID, used for user authentication
--identity-provider-custom-endpoint string Identity Provider base URL, used for user authentication
--jwks-custom-endpoint string Custom endpoint for the jwks API, which is used to get the json web key sets (jwks) to validate tokens when the service-account authentication is activated
--load-balancer-custom-endpoint string Load Balancer API base URL, used in calls to this API
--logme-custom-endpoint string LogMe API base URL, used in calls to this API
--mariadb-custom-endpoint string MariaDB API base URL, used in calls to this API
Expand Down
1 change: 0 additions & 1 deletion docs/stackit_config_unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ stackit config unset [flags]
--iaas-custom-endpoint IaaS API base URL. If unset, uses the default base URL
--identity-provider-custom-client-id Identity Provider client ID, used for user authentication
--identity-provider-custom-endpoint Identity Provider base URL. If unset, uses the default base URL
--jwks-custom-endpoint Custom endpoint for the jwks API, which is used to get the json web key sets (jwks) to validate tokens when the service-account authentication is activated
--load-balancer-custom-endpoint Load Balancer API base URL. If unset, uses the default base URL
--logme-custom-endpoint LogMe API base URL. If unset, uses the default base URL
--mariadb-custom-endpoint MariaDB API base URL. If unset, uses the default base URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
model := parseInput(p, cmd)

tokenCustomEndpoint, jwksCustomEndpoint, err := storeFlags()
tokenCustomEndpoint, err := storeFlags()
if err != nil {
return err
}
Expand All @@ -64,7 +64,6 @@ func NewCmd(p *print.Printer) *cobra.Command {
ServiceAccountKeyPath: model.ServiceAccountKeyPath,
PrivateKeyPath: model.PrivateKeyPath,
TokenCustomUrl: tokenCustomEndpoint,
JWKSCustomUrl: jwksCustomEndpoint,
}

// Setup authentication based on the provided credentials and the environment
Expand Down Expand Up @@ -119,17 +118,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
return &model
}

func storeFlags() (tokenCustomEndpoint, jwksCustomEndpoint string, err error) {
func storeFlags() (tokenCustomEndpoint string, err error) {
tokenCustomEndpoint = viper.GetString(config.TokenCustomEndpointKey)
jwksCustomEndpoint = viper.GetString(config.JwksCustomEndpointKey)

err = auth.SetAuthField(auth.TOKEN_CUSTOM_ENDPOINT, tokenCustomEndpoint)
if err != nil {
return "", "", fmt.Errorf("set %s: %w", auth.TOKEN_CUSTOM_ENDPOINT, err)
return "", fmt.Errorf("set %s: %w", auth.TOKEN_CUSTOM_ENDPOINT, err)
}
err = auth.SetAuthField(auth.JWKS_CUSTOM_ENDPOINT, jwksCustomEndpoint)
if err != nil {
return "", "", fmt.Errorf("set %s: %w", auth.JWKS_CUSTOM_ENDPOINT, err)
}
return tokenCustomEndpoint, jwksCustomEndpoint, nil
return tokenCustomEndpoint, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

var testTokenCustomEndpoint = "token_url"
var testJwksCustomEndpoint = "jwks_url"

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
Expand Down Expand Up @@ -45,23 +44,20 @@ func TestParseInput(t *testing.T) {
description string
flagValues map[string]string
tokenCustomEndpoint string
jwksCustomEndpoint string
isValid bool
expectedModel *inputModel
}{
{
description: "base",
flagValues: fixtureFlagValues(),
tokenCustomEndpoint: testTokenCustomEndpoint,
jwksCustomEndpoint: testJwksCustomEndpoint,
isValid: true,
expectedModel: fixtureInputModel(),
},
{
description: "no values",
flagValues: map[string]string{},
tokenCustomEndpoint: "",
jwksCustomEndpoint: "",
isValid: true,
expectedModel: &inputModel{
ServiceAccountToken: "",
Expand All @@ -77,7 +73,6 @@ func TestParseInput(t *testing.T) {
privateKeyPathFlag: "",
},
tokenCustomEndpoint: "",
jwksCustomEndpoint: "",
isValid: true,
expectedModel: &inputModel{
ServiceAccountToken: "",
Expand Down Expand Up @@ -131,14 +126,12 @@ func TestStoreFlags(t *testing.T) {
description string
model *inputModel
tokenCustomEndpoint string
jwksCustomEndpoint string
isValid bool
}{
{
description: "base",
model: fixtureInputModel(),
tokenCustomEndpoint: testTokenCustomEndpoint,
jwksCustomEndpoint: testJwksCustomEndpoint,
isValid: true,
},
{
Expand All @@ -149,7 +142,6 @@ func TestStoreFlags(t *testing.T) {
PrivateKeyPath: "",
},
tokenCustomEndpoint: "",
jwksCustomEndpoint: "",
isValid: true,
},
}
Expand All @@ -161,9 +153,8 @@ func TestStoreFlags(t *testing.T) {

viper.Reset()
viper.Set(config.TokenCustomEndpointKey, tt.tokenCustomEndpoint)
viper.Set(config.JwksCustomEndpointKey, tt.jwksCustomEndpoint)

tokenCustomEndpoint, jwksCustomEndpoint, err := storeFlags()
tokenCustomEndpoint, err := storeFlags()
if !tt.isValid {
if err == nil {
t.Fatalf("did not fail on invalid input")
Expand All @@ -181,14 +172,6 @@ func TestStoreFlags(t *testing.T) {
if value != tokenCustomEndpoint {
t.Errorf("Value of \"%s\" does not match: expected \"%s\", got \"%s\"", auth.TOKEN_CUSTOM_ENDPOINT, tokenCustomEndpoint, value)
}

value, err = auth.GetAuthField(auth.JWKS_CUSTOM_ENDPOINT)
if err != nil {
t.Errorf("Failed to get value of auth field: %v", err)
}
if value != jwksCustomEndpoint {
t.Errorf("Value of \"%s\" does not match: expected \"%s\", got \"%s\"", auth.JWKS_CUSTOM_ENDPOINT, jwksCustomEndpoint, value)
}
})
}
}
4 changes: 0 additions & 4 deletions internal/cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
sqlServerFlexCustomEndpointFlag = "sqlserverflex-custom-endpoint"
iaasCustomEndpointFlag = "iaas-custom-endpoint"
tokenCustomEndpointFlag = "token-custom-endpoint"
jwksCustomEndpointFlag = "jwks-custom-endpoint"
)

type inputModel struct {
Expand Down Expand Up @@ -157,7 +156,6 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(sqlServerFlexCustomEndpointFlag, "", "SQLServer Flex API base URL, used in calls to this API")
cmd.Flags().String(iaasCustomEndpointFlag, "", "IaaS API base URL, used in calls to this API")
cmd.Flags().String(tokenCustomEndpointFlag, "", "Custom endpoint for the token API, which is used to request access tokens when the service-account authentication is activated")
cmd.Flags().String(jwksCustomEndpointFlag, "", "Custom endpoint for the jwks API, which is used to get the json web key sets (jwks) to validate tokens when the service-account authentication is activated")

err := viper.BindPFlag(config.SessionTimeLimitKey, cmd.Flags().Lookup(sessionTimeLimitFlag))
cobra.CheckErr(err)
Expand Down Expand Up @@ -212,8 +210,6 @@ func configureFlags(cmd *cobra.Command) {
cobra.CheckErr(err)
err = viper.BindPFlag(config.TokenCustomEndpointKey, cmd.Flags().Lookup(tokenCustomEndpointFlag))
cobra.CheckErr(err)
err = viper.BindPFlag(config.JwksCustomEndpointKey, cmd.Flags().Lookup(jwksCustomEndpointFlag))
cobra.CheckErr(err)
}

func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
Expand Down
7 changes: 0 additions & 7 deletions internal/cmd/config/unset/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const (
sqlServerFlexCustomEndpointFlag = "sqlserverflex-custom-endpoint"
iaasCustomEndpointFlag = "iaas-custom-endpoint"
tokenCustomEndpointFlag = "token-custom-endpoint"
jwksCustomEndpointFlag = "jwks-custom-endpoint"
)

type inputModel struct {
Expand Down Expand Up @@ -83,7 +82,6 @@ type inputModel struct {
SQLServerFlexCustomEndpoint bool
IaaSCustomEndpoint bool
TokenCustomEndpoint bool
JwksCustomEndpoint bool
}

func NewCmd(p *print.Printer) *cobra.Command {
Expand Down Expand Up @@ -198,9 +196,6 @@ func NewCmd(p *print.Printer) *cobra.Command {
if model.TokenCustomEndpoint {
viper.Set(config.TokenCustomEndpointKey, "")
}
if model.JwksCustomEndpoint {
viper.Set(config.JwksCustomEndpointKey, "")
}

err := config.Write()
if err != nil {
Expand Down Expand Up @@ -246,7 +241,6 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(sqlServerFlexCustomEndpointFlag, false, "SQLServer Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(iaasCustomEndpointFlag, false, "IaaS API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(tokenCustomEndpointFlag, false, "Custom endpoint for the token API, which is used to request access tokens when the service-account authentication is activated")
cmd.Flags().Bool(jwksCustomEndpointFlag, false, "Custom endpoint for the jwks API, which is used to get the json web key sets (jwks) to validate tokens when the service-account authentication is activated")
}

func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
Expand Down Expand Up @@ -283,7 +277,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
SQLServerFlexCustomEndpoint: flags.FlagToBoolValue(p, cmd, sqlServerFlexCustomEndpointFlag),
IaaSCustomEndpoint: flags.FlagToBoolValue(p, cmd, iaasCustomEndpointFlag),
TokenCustomEndpoint: flags.FlagToBoolValue(p, cmd, tokenCustomEndpointFlag),
JwksCustomEndpoint: flags.FlagToBoolValue(p, cmd, jwksCustomEndpointFlag),
}

if p.IsVerbosityDebug() {
Expand Down
13 changes: 0 additions & 13 deletions internal/cmd/config/unset/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool
sqlServerFlexCustomEndpointFlag: true,
iaasCustomEndpointFlag: true,
tokenCustomEndpointFlag: true,
jwksCustomEndpointFlag: true,
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -79,7 +78,6 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
SQLServerFlexCustomEndpoint: true,
IaaSCustomEndpoint: true,
TokenCustomEndpoint: true,
JwksCustomEndpoint: true,
}
for _, mod := range mods {
mod(model)
Expand Down Expand Up @@ -134,7 +132,6 @@ func TestParseInput(t *testing.T) {
model.SQLServerFlexCustomEndpoint = false
model.IaaSCustomEndpoint = false
model.TokenCustomEndpoint = false
model.JwksCustomEndpoint = false
}),
},
{
Expand Down Expand Up @@ -277,16 +274,6 @@ func TestParseInput(t *testing.T) {
model.TokenCustomEndpoint = false
}),
},
{
description: "jwks custom endpoint empty",
flagValues: fixtureFlagValues(func(flagValues map[string]bool) {
flagValues[jwksCustomEndpointFlag] = false
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
model.JwksCustomEndpoint = false
}),
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
SQLServerFlexCustomEndpointKey = "sqlserverflex_custom_endpoint"
IaaSCustomEndpointKey = "iaas_custom_endpoint"
TokenCustomEndpointKey = "token_custom_endpoint"
JwksCustomEndpointKey = "jwks_custom_endpoint"

ProjectNameKey = "project_name"
DefaultProfileName = "default"
Expand Down Expand Up @@ -99,7 +98,6 @@ var ConfigKeys = []string{
SQLServerFlexCustomEndpointKey,
IaaSCustomEndpointKey,
TokenCustomEndpointKey,
JwksCustomEndpointKey,
}

var defaultConfigFolderPath string
Expand Down Expand Up @@ -177,7 +175,6 @@ func setConfigDefaults() {
viper.SetDefault(SQLServerFlexCustomEndpointKey, "")
viper.SetDefault(IaaSCustomEndpointKey, "")
viper.SetDefault(TokenCustomEndpointKey, "")
viper.SetDefault(JwksCustomEndpointKey, "")
}

func getConfigFilePath(configFolder string) string {
Expand Down

0 comments on commit 6281701

Please sign in to comment.