-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from uselagoon/debug-keycloak-groups
Add command to help debug Keycloak group permissions
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/uselagoon/ssh-portal/internal/keycloak" | ||
) | ||
|
||
// DumpGroupsCmd represents the dump-groups command. | ||
type DumpGroupsCmd struct { | ||
KeycloakBaseURL string `kong:"required,env='KEYCLOAK_BASE_URL',help='Keycloak Base URL'"` | ||
KeycloakClientID string `kong:"default='service-api',env='KEYCLOAK_SERVICE_API_CLIENT_ID',help='Keycloak OAuth2 Client ID'"` | ||
KeycloakClientSecret string `kong:"required,env='KEYCLOAK_SERVICE_API_CLIENT_SECRET',help='Keycloak OAuth2 Client Secret'"` | ||
KeycloakRateLimit int `kong:"default=10,env='KEYCLOAK_RATE_LIMIT',help='Keycloak API Rate Limit (requests/second)'"` | ||
} | ||
|
||
// Run the serve command to ssh-portal API requests. | ||
func (cmd *DumpGroupsCmd) Run(log *slog.Logger) error { | ||
// get main process context, which cancels on SIGTERM | ||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM) | ||
defer stop() | ||
// init keycloak client | ||
k, err := keycloak.NewClient(ctx, log, | ||
cmd.KeycloakBaseURL, | ||
cmd.KeycloakClientID, | ||
cmd.KeycloakClientSecret, | ||
cmd.KeycloakRateLimit) | ||
if err != nil { | ||
return fmt.Errorf("couldn't init keycloak client: %v", err) | ||
} | ||
groupMap, err := k.GroupNameGroupIDMap(ctx) | ||
if err != nil { | ||
return fmt.Errorf("couldn't get keycloak group map: %v", err) | ||
} | ||
spew.Dump(groupMap) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Package main implements the ssh-portal-api service. | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/alecthomas/kong" | ||
) | ||
|
||
// CLI represents the command-line interface. | ||
type CLI struct { | ||
Debug bool `kong:"env='DEBUG',help='Enable debug logging'"` | ||
DumpGroups DumpGroupsCmd `kong:"cmd,default=1,help='(default) Serve ssh-portal-api requests'"` | ||
} | ||
|
||
func main() { | ||
// parse CLI config | ||
cli := CLI{} | ||
kctx := kong.Parse(&cli, | ||
kong.UsageOnError(), | ||
) | ||
// init logger | ||
var log *slog.Logger | ||
if cli.Debug { | ||
log = slog.New(slog.NewJSONHandler(os.Stderr, | ||
&slog.HandlerOptions{Level: slog.LevelDebug})) | ||
} else { | ||
log = slog.New(slog.NewJSONHandler(os.Stderr, nil)) | ||
} | ||
// execute CLI | ||
kctx.FatalIfErrorf(kctx.Run(log)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters