Skip to content

Commit

Permalink
Merge pull request #1183 from stacklok/keycloak-default
Browse files Browse the repository at this point in the history
feat: Default to staging keycloak for identity configuration
  • Loading branch information
JAORMX authored Oct 12, 2023
2 parents 0ea1c2b + c7e834d commit 4e2141b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions cmd/cli/app/auth/auth_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/stacklok/mediator/internal/config"
mcrypto "github.com/stacklok/mediator/internal/crypto"
"github.com/stacklok/mediator/internal/util"
"github.com/stacklok/mediator/internal/util/cli"
Expand Down Expand Up @@ -74,14 +73,14 @@ will be saved to $XDG_CONFIG_HOME/mediator/credentials.json`,
},
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
cfg, err := config.ReadConfigFromViper(viper.GetViper())
util.ExitNicelyOnError(err, "unable to read config")

clientID := cfg.Identity.ClientId
issuerUrlStr := util.GetConfigValue("identity.issuer_url", "identity-url", cmd, "https://auth.staging.stacklok.dev").(string)
realm := util.GetConfigValue("identity.realm", "identity-realm", cmd, "stacklok").(string)
clientID := util.GetConfigValue("identity.client_id", "identity-client", cmd, "mediator-cli").(string)

parsedURL, err := url.Parse(cfg.Identity.IssuerUrl)
parsedURL, err := url.Parse(issuerUrlStr)
util.ExitNicelyOnError(err, "Error parsing issuer URL")
issuerUrl := parsedURL.JoinPath("realms", cfg.Identity.Realm)
issuerUrl := parsedURL.JoinPath("realms", realm)
scopes := []string{"openid"}
callbackPath := "/auth/callback"

Expand Down
9 changes: 4 additions & 5 deletions cmd/cli/app/auth/auth_logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/stacklok/mediator/internal/config"
"github.com/stacklok/mediator/internal/util"
"github.com/stacklok/mediator/internal/util/cli"
)
Expand Down Expand Up @@ -60,13 +59,13 @@ var auth_logoutCmd = &cobra.Command{
err := os.Remove(filePath)
util.ExitNicelyOnError(err, "Error removing credentials file")

cfg, err := config.ReadConfigFromViper(viper.GetViper())
util.ExitNicelyOnError(err, "Error reading config")
issuerUrlStr := util.GetConfigValue("identity.issuer_url", "identity-url", cmd, "https://auth.staging.stacklok.dev").(string)
realm := util.GetConfigValue("identity.realm", "identity-realm", cmd, "stacklok").(string)

parsedURL, err := url.Parse(cfg.Identity.IssuerUrl)
parsedURL, err := url.Parse(issuerUrlStr)
util.ExitNicelyOnError(err, "Error parsing issuer URL")

logoutUrl := parsedURL.JoinPath("realms", cfg.Identity.Realm, "protocol/openid-connect/logout")
logoutUrl := parsedURL.JoinPath("realms", realm, "protocol/openid-connect/logout")
cli.PrintCmd(cmd, cli.SuccessBanner.Render("You have successfully logged out of the CLI."))
cli.PrintCmd(cmd, "If you would like to log out of the browser, you can visit %s", logoutUrl.String())
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
RootCmd.PersistentFlags().String("grpc-host", "staging.stacklok.dev", "Server host")
RootCmd.PersistentFlags().Int("grpc-port", 443, "Server port")
RootCmd.PersistentFlags().Bool("grpc-insecure", false, "Allow establishing insecure connections")
RootCmd.PersistentFlags().String("identity-url", "http://localhost:8081", "Identity server issuer URL")
RootCmd.PersistentFlags().String("identity-url", "https://auth.staging.stacklok.dev", "Identity server issuer URL")
RootCmd.PersistentFlags().String("identity-realm", "stacklok", "Identity server realm")
RootCmd.PersistentFlags().String("identity-client", "mediator-cli", "Identity server client ID")
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is $PWD/config.yaml)")
Expand Down
2 changes: 1 addition & 1 deletion internal/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func GrpcForCommand(cmd *cobra.Command) (*grpc.ClientConn, error) {
insecureDefault := grpc_host == "localhost" || grpc_host == "127.0.0.1" || grpc_host == "::1"
allowInsecure := GetConfigValue("grpc_server.insecure", "grpc-insecure", cmd, insecureDefault).(bool)

issuerUrl := GetConfigValue("identity.issuer_url", "identity-url", cmd, "http://localhost:8081").(string)
issuerUrl := GetConfigValue("identity.issuer_url", "identity-url", cmd, "https://auth.staging.stacklok.dev").(string)
realm := GetConfigValue("identity.realm", "identity-realm", cmd, "stacklok").(string)
clientId := GetConfigValue("identity.client_id", "identity-client", cmd, "mediator-cli").(string)

Expand Down

0 comments on commit 4e2141b

Please sign in to comment.