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

Deprecating Tokens as it is no longer supported. #374

Merged
merged 2 commits into from
Feb 3, 2025
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
2 changes: 1 addition & 1 deletion cli/tools/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func newAuthCmd() simplecobra.Commander {
NameP: "auth",
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{newTokensCmd(), newServiceAccountCmd()},
CommandsList: []simplecobra.Commander{newServiceAccountCmd()},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
return cd.CobraCommand.Help()
},
Expand Down
88 changes: 16 additions & 72 deletions cli/tools/auth_service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{
newServiceAccountTokensCmd(),
newListServiceAccountCmd(),
newDeleteServiceAccountCmd(),
newDeleteServiceAccountTokensCmd(),
newClearServiceAccountsCmd(),
newDeleteServiceAccountsCmd(),
newServiceAccount(),
newServiceAccountTokenCmd(),
},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
return cd.CobraCommand.Help()
Expand Down Expand Up @@ -81,10 +81,10 @@
}
}

func newDeleteServiceAccountTokensCmd() simplecobra.Commander {
description := "delete all tokens for Service Account from grafana"
func newDeleteServiceAccountsCmd() simplecobra.Commander {
description := "delete the given service account from grafana"
return &support.SimpleCommand{
NameP: "clearTokens",
NameP: "delete",
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{},
Expand All @@ -98,25 +98,21 @@
log.Fatalf("unable to parse %s as a valid numeric value", idStr)
}

slog.Info("Deleting Service Accounts Tokens for context",
"serviceAccountId", id,
"context", config.Config().GetGDGConfig().GetContext())
savedFiles := rootCmd.GrafanaSvc().DeleteServiceAccountTokens(id)
rootCmd.TableObj.AppendHeader(table.Row{"serviceID", "type", "token_name"})
if len(savedFiles) == 0 {
slog.Info("No Service Accounts tokens found")
slog.Info("Deleting Service Accounts for context", "context", config.Config().GetGDGConfig().GetContext(),
"serviceAccountId", id)
err = rootCmd.GrafanaSvc().DeleteServiceAccount(id)
rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"})
if err != nil {
slog.Info("Unable to delete service account", "err", err.Error())

Check warning on line 106 in cli/tools/auth_service_accounts.go

View check run for this annotation

Codecov / codecov/patch

cli/tools/auth_service_accounts.go#L101-L106

Added lines #L101 - L106 were not covered by tests
} else {
for _, token := range savedFiles {
rootCmd.TableObj.AppendRow(table.Row{id, "service token", token})
}
rootCmd.Render(cd.CobraCommand, savedFiles)
slog.Info("Service account has been removed", "serviceAccountId", id)

Check warning on line 108 in cli/tools/auth_service_accounts.go

View check run for this annotation

Codecov / codecov/patch

cli/tools/auth_service_accounts.go#L108

Added line #L108 was not covered by tests
}
return nil
},
}
}

func newDeleteServiceAccountCmd() simplecobra.Commander {
func newClearServiceAccountsCmd() simplecobra.Commander {
description := "delete all Service Accounts from grafana"
return &support.SimpleCommand{
NameP: "clear",
Expand All @@ -141,9 +137,9 @@
}

func newServiceAccount() simplecobra.Commander {
description := "newService <serviceName> <role> [ttl in seconds]"
description := "new <serviceName> <role> [ttl in seconds]"
return &support.SimpleCommand{
NameP: "newService",
NameP: "new",
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{},
Expand Down Expand Up @@ -184,55 +180,3 @@
},
}
}

func newServiceAccountTokenCmd() simplecobra.Commander {
description := "newToken <serviceAccountID> <name> [ttl in seconds]"
return &support.SimpleCommand{
NameP: "newToken",
Short: description,
Long: description,
CommandsList: []simplecobra.Commander{newTokensCmd()},
RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error {
if len(args) < 2 {
return errors.New("requires a service-account ID and token name [ttl optional] ")
}
serviceIDRaw := args[0]
name := args[1]
ttl := "0"
if len(args) > 2 {
ttl = args[2]
}
var (
expiration int64
err error
)

serviceID, err := strconv.ParseInt(serviceIDRaw, 10, 64)
if err != nil {
log.Fatal("unable to parse serviceID, make sure it's a numeric value")
}
expiration, err = strconv.ParseInt(ttl, 10, 64)
if err != nil {
expiration = 0
}

key, err := rootCmd.GrafanaSvc().CreateServiceAccountToken(serviceID, name, expiration)
if err != nil {
log.Fatal("unable to create api key", "err", err)
} else {

rootCmd.TableObj.AppendHeader(table.Row{"serviceID", "token_id", "name", "token"})
rootCmd.TableObj.AppendRow(table.Row{serviceID, key.ID, key.Name, key.Key})
rootCmd.Render(cd.CobraCommand,
map[string]interface{}{
"serviceID": serviceID,
"token_id": key.ID,
"name": key.Name,
"token": key.Key,
})
}

return nil
},
}
}
138 changes: 0 additions & 138 deletions cli/tools/auth_tokens.go

This file was deleted.

Loading
Loading