From 71ab48fc157c44041a8d02ab12ba62c7d6034b7a Mon Sep 17 00:00:00 2001 From: Samir F Date: Mon, 3 Feb 2025 10:24:37 -0500 Subject: [PATCH] Deprecating Tokens as it is no longer supported. (#374) * Deprecating Tokens as it is no longer supported in favor of service account tokens ChangeLog: - Updating grafana-openapi-client-go to latest from master. * Adding a Service Account Explicit test --- cli/tools/auth.go | 2 +- cli/tools/auth_service_accounts.go | 88 ++------ cli/tools/auth_tokens.go | 138 ------------ cli/tools/service_account_tokens.go | 121 +++++++++++ go.mod | 3 +- go.sum | 97 +-------- internal/service/contracts.go | 11 +- internal/service/mocks/AuthenticationApi.go | 164 +++------------ internal/service/mocks/GrafanaService.go | 196 ++++-------------- internal/service/mocks/ServiceAccountApi.go | 66 +++++- internal/service/mocks/TokenApi.go | 189 ----------------- internal/service/serviceaccounts.go | 8 +- internal/service/tokens.go | 60 ------ pkg/test_tooling/common.go | 19 +- test/common_test.go | 4 + test/service_account_test.go | 53 +++++ .../content/docs/usage_guide/tools_guide.md | 65 +++--- 17 files changed, 378 insertions(+), 906 deletions(-) delete mode 100644 cli/tools/auth_tokens.go create mode 100644 cli/tools/service_account_tokens.go delete mode 100644 internal/service/mocks/TokenApi.go delete mode 100644 internal/service/tokens.go create mode 100644 test/service_account_test.go diff --git a/cli/tools/auth.go b/cli/tools/auth.go index 2756bca6..1c77e532 100644 --- a/cli/tools/auth.go +++ b/cli/tools/auth.go @@ -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() }, diff --git a/cli/tools/auth_service_accounts.go b/cli/tools/auth_service_accounts.go index 99f48a60..f6d39fe5 100644 --- a/cli/tools/auth_service_accounts.go +++ b/cli/tools/auth_service_accounts.go @@ -25,11 +25,11 @@ func newServiceAccountCmd() simplecobra.Commander { 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() @@ -81,10 +81,10 @@ func newListServiceAccountCmd() simplecobra.Commander { } } -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{}, @@ -98,25 +98,21 @@ func newDeleteServiceAccountTokensCmd() simplecobra.Commander { 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()) } 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) } return nil }, } } -func newDeleteServiceAccountCmd() simplecobra.Commander { +func newClearServiceAccountsCmd() simplecobra.Commander { description := "delete all Service Accounts from grafana" return &support.SimpleCommand{ NameP: "clear", @@ -141,9 +137,9 @@ func newDeleteServiceAccountCmd() simplecobra.Commander { } func newServiceAccount() simplecobra.Commander { - description := "newService [ttl in seconds]" + description := "new [ttl in seconds]" return &support.SimpleCommand{ - NameP: "newService", + NameP: "new", Short: description, Long: description, CommandsList: []simplecobra.Commander{}, @@ -184,55 +180,3 @@ func newServiceAccount() simplecobra.Commander { }, } } - -func newServiceAccountTokenCmd() simplecobra.Commander { - description := "newToken [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 - }, - } -} diff --git a/cli/tools/auth_tokens.go b/cli/tools/auth_tokens.go deleted file mode 100644 index 0da13710..00000000 --- a/cli/tools/auth_tokens.go +++ /dev/null @@ -1,138 +0,0 @@ -package tools - -import ( - "context" - "fmt" - "log" - "log/slog" - "sort" - "strconv" - "strings" - - "github.com/bep/simplecobra" - "github.com/esnet/gdg/cli/support" - "github.com/esnet/gdg/internal/config" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" -) - -func newTokensCmd() simplecobra.Commander { - description := "Provides some utility to help the user manage their API token keys" - return &support.SimpleCommand{ - NameP: "tokens", - Short: description, - Long: description, - RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { - return cd.CobraCommand.Help() - }, - WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) { - cmd.Aliases = []string{"token", "apikeys"} - }, - CommandsList: []simplecobra.Commander{ - newListTokensCmd(), - newDeleteTokenCmd(), - newNewTokenCmd(), - }, - } -} - -func newListTokensCmd() simplecobra.Commander { - description := "List API Keys" - return &support.SimpleCommand{ - NameP: "list", - Short: description, - Long: description, - CommandsList: []simplecobra.Commander{}, - RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { - rootCmd.TableObj.AppendHeader(table.Row{"id", "name", "role", "expiration"}) - apiKeys := rootCmd.GrafanaSvc().ListAPIKeys() - sort.SliceStable(apiKeys, func(i, j int) bool { - return apiKeys[i].ID < apiKeys[j].ID - }) - if len(apiKeys) == 0 { - slog.Info("No apiKeys found") - } else { - for _, apiKey := range apiKeys { - var formattedDate string = apiKey.Expiration.String() - date, _ := apiKey.Expiration.Value() - if date.(string) == "0001-01-01T00:00:00.000Z" { - formattedDate = "No Expiration" - } - - rootCmd.TableObj.AppendRow(table.Row{apiKey.ID, apiKey.Name, apiKey.Role, formattedDate}) - } - rootCmd.Render(cd.CobraCommand, apiKeys) - } - return nil - }, - } -} - -func newDeleteTokenCmd() simplecobra.Commander { - description := "delete all Tokens from grafana" - return &support.SimpleCommand{ - NameP: "clear", - Short: description, - Long: description, - CommandsList: []simplecobra.Commander{}, - RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { - savedFiles := rootCmd.GrafanaSvc().DeleteAllTokens() - slog.Info("Delete Tokens for context: ", "context", config.Config().GetGDGConfig().GetContext()) - rootCmd.TableObj.AppendHeader(table.Row{"type", "filename"}) - if len(savedFiles) == 0 { - slog.Info("No Tokens found") - } else { - for _, file := range savedFiles { - rootCmd.TableObj.AppendRow(table.Row{"user", file}) - } - rootCmd.Render(cd.CobraCommand, savedFiles) - } - return nil - }, - } -} - -func newNewTokenCmd() simplecobra.Commander { - description := "new [ttl in seconds]" - return &support.SimpleCommand{ - NameP: "new", - Short: description, - Long: description, - CommandsList: []simplecobra.Commander{}, - RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { - if len(args) < 2 { - return fmt.Errorf("requires a key name and a role(%s) [ttl optional] ", strings.Join(getBasicRoles(), ", ")) - } - name := args[0] - role := args[1] - ttl := "0" - if len(args) > 2 { - ttl = args[2] - } - var ( - expiration int64 - err error - ) - - expiration, err = strconv.ParseInt(ttl, 10, 64) - if err != nil { - expiration = 0 - } - - if !validBasicRole(role) { - log.Fatalf("Invalid role specified, '%s'. Valid roles are:[%s]", role, strings.Join(getBasicRoles(), ", ")) - } - key, err := rootCmd.GrafanaSvc().CreateAPIKey(name, role, expiration) - if err != nil { - log.Fatal("unable to create api key", "err", err) - } else { - - rootCmd.TableObj.AppendHeader(table.Row{"id", "name", "token"}) - rootCmd.TableObj.AppendRow(table.Row{key.ID, key.Name, key.Key}) - rootCmd.Render(cd.CobraCommand, map[string]interface{}{"id": key.ID, "name": key.Name, "token": key.Key}) - } - - return nil - }, - } -} diff --git a/cli/tools/service_account_tokens.go b/cli/tools/service_account_tokens.go new file mode 100644 index 00000000..a477b240 --- /dev/null +++ b/cli/tools/service_account_tokens.go @@ -0,0 +1,121 @@ +package tools + +import ( + "context" + "errors" + "log" + "log/slog" + "strconv" + + "github.com/bep/simplecobra" + "github.com/esnet/gdg/cli/support" + "github.com/esnet/gdg/internal/config" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" +) + +func newServiceAccountTokensCmd() simplecobra.Commander { + description := "Manage api service-account tokens" + return &support.SimpleCommand{ + NameP: "tokens", + Short: description, + Long: description, + CommandsList: []simplecobra.Commander{ + newDeleteServiceAccountTokensCmd(), + newServiceAccountTokenCmd(), + }, + RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { + return cd.CobraCommand.Help() + }, + WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) { + cmd.Aliases = []string{"token"} + }, + } +} + +func newDeleteServiceAccountTokensCmd() simplecobra.Commander { + description := "clear , removes all tokens from service account" + return &support.SimpleCommand{ + NameP: "clear", + Short: description, + Long: description, + CommandsList: []simplecobra.Commander{}, + RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *support.RootCommand, args []string) error { + if len(args) < 1 { + return errors.New("requires a service account ID to be specified") + } + idStr := args[0] + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + 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") + } else { + for _, token := range savedFiles { + rootCmd.TableObj.AppendRow(table.Row{id, "service token", token}) + } + rootCmd.Render(cd.CobraCommand, savedFiles) + } + return nil + }, + } +} + +func newServiceAccountTokenCmd() simplecobra.Commander { + description := "new [ttl in seconds]" + return &support.SimpleCommand{ + NameP: "new", + Short: description, + Long: description, + CommandsList: []simplecobra.Commander{}, + 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 + }, + } +} diff --git a/go.mod b/go.mod index 03ca663c..5ea49ecf 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,13 @@ require ( github.com/aws/aws-sdk-go-v2/service/s3 v1.74.1 github.com/aws/smithy-go v1.22.2 github.com/bep/simplecobra v0.4.0 + github.com/brianvoe/gofakeit/v6 v6.28.0 github.com/carlmjohnson/requests v0.24.3 github.com/go-openapi/strfmt v0.23.0 github.com/google/uuid v1.6.0 github.com/gosimple/slug v1.15.0 github.com/grafana/dashboard-linter v0.0.0-20241017155901-a9d6c25b7bd3 - github.com/grafana/grafana-openapi-client-go v0.0.0-20240826142251-d1c93bae4198 + github.com/grafana/grafana-openapi-client-go v0.0.0-20250108132429-8d7e1f158f65 github.com/jedib0t/go-pretty/v6 v6.6.5 github.com/joho/godotenv v1.5.1 github.com/lmittmann/tint v1.0.6 diff --git a/go.sum b/go.sum index f1c76096..64400d04 100644 --- a/go.sum +++ b/go.sum @@ -100,106 +100,42 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= -github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= -github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= -github.com/aws/aws-sdk-go-v2 v1.33.0 h1:Evgm4DI9imD81V0WwD+TN4DCwjUMdc94TrduMLbgZJs= -github.com/aws/aws-sdk-go-v2 v1.33.0/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U= github.com/aws/aws-sdk-go-v2 v1.34.0 h1:9iyL+cjifckRGEVpRKZP3eIxVlL06Qk1Tk13vreaVQU= github.com/aws/aws-sdk-go-v2 v1.34.0/go.mod h1:JgstGg0JjWU1KpVJjD5H0y0yyAIpSdKEq556EI6yOOM= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7/go.mod h1:QraP0UcVlQJsmHfioCrveWOC1nbiWUl3ej08h4mXWoc= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.8 h1:zAxi9p3wsZMIaVCdoiQp2uZ9k1LsZvmAnoTBeZPXom0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.8/go.mod h1:3XkePX5dSaxveLAYY7nsbsZZrKxCyEuE5pM4ziFxyGg= github.com/aws/aws-sdk-go-v2/config v1.28.0 h1:FosVYWcqEtWNxHn8gB/Vs6jOlNwSoyOCA/g/sxyySOQ= github.com/aws/aws-sdk-go-v2/config v1.28.0/go.mod h1:pYhbtvg1siOOg8h5an77rXle9tVG8T+BWLWAo7cOukc= -github.com/aws/aws-sdk-go-v2/credentials v1.17.41 h1:7gXo+Axmp+R4Z+AK8YFQO0ZV3L0gizGINCOWxSLY9W8= -github.com/aws/aws-sdk-go-v2/credentials v1.17.41/go.mod h1:u4Eb8d3394YLubphT4jLEwN1rLNq2wFOlT6OuxFwPzU= -github.com/aws/aws-sdk-go-v2/credentials v1.17.54 h1:4UmqeOqJPvdvASZWrKlhzpRahAulBfyTJQUaYy4+hEI= -github.com/aws/aws-sdk-go-v2/credentials v1.17.54/go.mod h1:RTdfo0P0hbbTxIhmQrOsC/PquBZGabEPnCaxxKRPSnI= github.com/aws/aws-sdk-go-v2/credentials v1.17.55 h1:CDhKnDEaGkLA5ZszV/qw5uwN5M8rbv9Cl0JRN+PRsaM= github.com/aws/aws-sdk-go-v2/credentials v1.17.55/go.mod h1:kPD/vj+RB5MREDUky376+zdnjZpR+WgdBBvwrmnlmKE= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 h1:TMH3f/SCAWdNtXXVPPu5D6wrr4G5hI1rAxbcocKfC7Q= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17/go.mod h1:1ZRXLdTpzdJb9fwTMXiLipENRxkGMTn1sfKexGllQCw= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24 h1:5grmdTdMsovn9kPZPI23Hhvp0ZyNm5cRO+IZFIYiAfw= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24/go.mod h1:zqi7TVKTswH3Ozq28PkmBmgzG1tona7mo9G2IJg4Cis= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.25 h1:kU7tmXNaJ07LsyN3BUgGqAmVmQtq0w6duVIHAKfp0/w= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.25/go.mod h1:OiC8+OiqrURb1wrwmr/UbOVLFSWEGxjinj5C299VQdo= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.33 h1:X+4YY5kZRI/cOoSMVMGTqFXHAMg1bvvay7IBcqHpybQ= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.33/go.mod h1:DPynzu+cn92k5UQ6tZhX+wfTB4ah6QDU/NgdHqatmvk= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 h1:igORFSiH3bfq4lxKFkTSYDhJEUCYo6C8VKiWJjYwQuQ= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28/go.mod h1:3So8EA/aAYm36L7XIvCVwLa0s5N0P7o2b1oqnx/2R4g= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.29 h1:Ej0Rf3GMv50Qh4G4852j2djtoDb7AzQ7MuQeFHa3D70= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.29/go.mod h1:oeNTC7PwJNoM5AznVr23wxhLnuJv0ZDe5v7w0wqIs9M= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 h1:1mOW9zAUMhTSrMDssEHS/ajx8JcAj/IcftzcmNlmVLI= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28/go.mod h1:kGlXVIWDfvt2Ox5zEaNglmq0hXPHgQFNMix33Tw22jA= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.29 h1:6e8a71X+9GfghragVevC5bZqvATtc3mAMgxpSNbgzF0= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.29/go.mod h1:c4jkZiQ+BWpNqq7VtrxjwISrLrt/VvPq3XiopkUIolI= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 h1:7edmS3VOBDhK00b/MwGtGglCm7hhwNYnjJs/PgFdMQE= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21/go.mod h1:Q9o5h4HoIWG8XfzxqiuK/CGUbepCJ8uTlaE3bAbxytQ= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28 h1:7kpeALOUeThs2kEjlAxlADAVfxKmkYAedlpZ3kdoSJ4= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28/go.mod h1:pyaOYEdp1MJWgtXLy6q80r3DhsVdOIOZNB9hdTcJIvI= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.29 h1:g9OUETuxA8i/Www5Cby0R3WSTe7ppFTZXHVLNskNS4w= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.29/go.mod h1:CQk+koLR1QeY1+vm7lqNfFii07DEderKq6T3F1L2pyc= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.2 h1:D4oz8/CzT9bAEYtVhSBmFj2dNOtaHOtMKc2vHBwYizA= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.2/go.mod h1:Za3IHqTQ+yNcRHxu1OFucBh0ACZT4j4VQFF0BqpZcLY= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 h1:4FMHqLfk0efmTqhXVRL5xYRqlEBNBiRI7N6w4jsEdd4= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2/go.mod h1:LWoqeWlK9OZeJxsROW2RqrSPvQHKTpp69r/iDjwsSaw= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.2 h1:e6um6+DWYQP1XCa+E9YVtG/9v1qk5lyAOelMOVwSyO8= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.2/go.mod h1:dIW8puxSbYLSPv/ju0d9A3CpwXdtqvJtYKDMVmPLOWE= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.3 h1:EP1ITDgYVPM2dL1bBBntJ7AW5yTjuWGz9XO+CZwpALU= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.3/go.mod h1:5lWNWeAgWenJ/BZ/CP9k9DjLbC0pjnM045WjXRPPi14= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 h1:s7NA1SOw8q/5c0wr8477yOPp0z+uBaXBnLE0XYb0POA= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2/go.mod h1:fnjjWyAW/Pj5HYOxl9LJqWtEwS7W2qgcRLWP+uWbss0= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9 h1:TQmKDyETFGiXVhZfQ/I0cCFziqqX58pi4tKJGYGFSz0= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9/go.mod h1:HVLPK2iHQBUx7HfZeOQSEu3v2ubZaAY2YPbAm5/WUyY= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.10 h1:hN4yJBGswmFTOVYqmbz1GBs9ZMtQe8SrYxPwrkrlRv8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.10/go.mod h1:TsxON4fEZXyrKY+D+3d2gSTyJkGORexIYab9PTf56DA= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 h1:t7iUP9+4wdc5lt3E41huP+GvQZJD38WLsgVp4iOtAjg= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2/go.mod h1:/niFCtmuQNxqx9v8WAPq5qh7EH25U4BF6tjoyq9bObM= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9 h1:2aInXbh02XsbO0KobPGMNXyv2QP73VDKsWPNJARj/+4= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9/go.mod h1:dgXS1i+HgWnYkPXqNoPIPKeUsUUYHaUbThC90aDnNiE= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.10 h1:fXoWC2gi7tdJYNTPnnlSGzEVwewUchOi8xVq/dkg8Qs= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.10/go.mod h1:cvzBApD5dVazHU8C2rbBQzzzsKc8m5+wNJ9mCRZLKPc= -github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 h1:xA6XhTF7PE89BCNHJbQi8VvPzcgMtmGC5dr8S8N7lHk= -github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0/go.mod h1:cB6oAuus7YXRZhWCc1wIwPywwZ1XwweNp2TVAEGYeB8= -github.com/aws/aws-sdk-go-v2/service/s3 v1.74.0 h1:ncCHiFU9Eq4qnKCNlzMZXfFmvb9R8OVNfU8SFOskxdI= -github.com/aws/aws-sdk-go-v2/service/s3 v1.74.0/go.mod h1:jGJ/v7FIi7Ys9t54tmEFnrxuaWeJLpwNgKp2DXAVhOU= github.com/aws/aws-sdk-go-v2/service/s3 v1.74.1 h1:9LawY3cDJ3HE+v2GMd5SOkNLDwgN4K7TsCjyVBYu/L4= github.com/aws/aws-sdk-go-v2/service/s3 v1.74.1/go.mod h1:hHnELVnIHltd8EOF3YzahVX6F6y2C6dNqpRj1IMkS5I= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 h1:bSYXVyUzoTHoKalBmwaZxs97HU9DWWI3ehHSAMa7xOk= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.2/go.mod h1:skMqY7JElusiOUjMJMOv1jJsP7YUg7DrhgqZZWuzu1U= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.11 h1:kuIyu4fTT38Kj7YCC7ouNbVZSSpqkZ+LzIfhCr6Dg+I= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.11/go.mod h1:Ro744S4fKiCCuZECXgOi760TiYylUM8ZBf6OGiZzJtY= github.com/aws/aws-sdk-go-v2/service/sso v1.24.12 h1:kznaW4f81mNMlREkU9w3jUuJvU5g/KsqDV43ab7Rp6s= github.com/aws/aws-sdk-go-v2/service/sso v1.24.12/go.mod h1:bZy9r8e0/s0P7BSDHgMLXK2KvdyRRBIQ2blKlvLt0IU= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 h1:AhmO1fHINP9vFYUE0LHzCWg/LfUWUF+zFPEcY9QXb7o= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2/go.mod h1:o8aQygT2+MVP0NaV6kbdE1YnnIM8RRVQzoeUH45GOdI= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.10 h1:l+dgv/64iVlQ3WsBbnn+JSbkj01jIi+SM0wYsj3y/hY= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.10/go.mod h1:Fzsj6lZEb8AkTE5S68OhcbBqeWPsR8RnGuKPr8Todl8= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.11 h1:mUwIpAvILeKFnRx4h1dEgGEFGuV8KJ3pEScZWVFYuZA= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.11/go.mod h1:JDJtD+b8HNVv71axz8+S5492KM8wTzHRFpMKQbPlYxw= -github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 h1:CiS7i0+FUe+/YY1GvIBLLrR/XNGZ4CtM1Ll0XavNuVo= -github.com/aws/aws-sdk-go-v2/service/sts v1.32.2/go.mod h1:HtaiBI8CjYoNVde8arShXb94UbQQi9L4EMr6D+xGBwo= -github.com/aws/aws-sdk-go-v2/service/sts v1.33.9 h1:BRVDbewN6VZcwr+FBOszDKvYeXY1kJ+GGMCcpghlw0U= -github.com/aws/aws-sdk-go-v2/service/sts v1.33.9/go.mod h1:f6vjfZER1M17Fokn0IzssOTMT2N8ZSq+7jnNF0tArvw= github.com/aws/aws-sdk-go-v2/service/sts v1.33.10 h1:g9d+TOsu3ac7SgmY2dUf1qMgu/uJVTlQ4VCbH6hRxSw= github.com/aws/aws-sdk-go-v2/service/sts v1.33.10/go.mod h1:WZfNmntu92HO44MVZAubQaz3qCuIdeOdog2sADfU6hU= -github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= -github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= -github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro= -github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ= github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 h1:6df1vn4bBlDDo4tARvBm7l6KA9iVMnE3NWizDeWSrps= @@ -211,10 +147,10 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bep/simplecobra v0.4.0 h1:ufX/6WcOtEVJdCd7hsztTWURlZkOaWYOD+zCqrM8qUE= github.com/bep/simplecobra v0.4.0/go.mod h1:evSM6iQqRwqpV7W4H4DlYFfe9mZ0x6Hj5GEOnIV7dI4= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4= +github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 h1:6lhrsTEnloDPXyeZBvSYvQf8u86jbKehZPVDDlkgDl4= github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= -github.com/carlmjohnson/requests v0.24.2 h1:JDakhAmTIKL/qL/1P7Kkc2INGBJIkIFP6xUeUmPzLso= -github.com/carlmjohnson/requests v0.24.2/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU= github.com/carlmjohnson/requests v0.24.3 h1:LYcM/jVIVPkioigMjEAnBACXl2vb42TVqiC8EYNoaXQ= github.com/carlmjohnson/requests v0.24.3/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= @@ -391,8 +327,6 @@ github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDP github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es= -github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ= github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo= github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ= github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o= @@ -403,8 +337,8 @@ github.com/grafana/dskit v0.0.0-20241015200741-21f60cf427aa h1:qn6vlh4ZPBgyMTGUo github.com/grafana/dskit v0.0.0-20241015200741-21f60cf427aa/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ= github.com/grafana/gomemcache v0.0.0-20241016125027-0a5bcc5aef40 h1:1TeKhyS+pvzOeyLV1XPZsiqebnKky/AKS3pJNNbHVPo= github.com/grafana/gomemcache v0.0.0-20241016125027-0a5bcc5aef40/go.mod h1:IGRj8oOoxwJbHBYl1+OhS9UjQR0dv6SQOep7HqmtyFU= -github.com/grafana/grafana-openapi-client-go v0.0.0-20240826142251-d1c93bae4198 h1:JEoUdaKnBdZ57YsWiDeAERYu52W4c7g7eAAxY2PpWl8= -github.com/grafana/grafana-openapi-client-go v0.0.0-20240826142251-d1c93bae4198/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI= +github.com/grafana/grafana-openapi-client-go v0.0.0-20250108132429-8d7e1f158f65 h1:AnfwjPE8TXJO8CX0Q5PvtzGta9Ls3iRASWVV4jHl4KA= +github.com/grafana/grafana-openapi-client-go v0.0.0-20250108132429-8d7e1f158f65/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI= github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675 h1:U94jQ2TQr1m3HNyE8efSdyaBbDrdPaWImXyenuKZ/nw= github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675/go.mod h1:796sq+UcONnSlzA3RtlBZ+b/hrerkZXiEmO8oMjyRwY= github.com/grafana/loki/pkg/push v0.0.0-20241017144940-311797442f0a h1:FqMzx/Gw5jTFhdAmuXfsiJg4Th8AWgm9AxLA153+2OQ= @@ -475,8 +409,6 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw= -github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/jedib0t/go-pretty/v6 v6.6.5 h1:9PgMJOVBedpgYLI56jQRJYqngxYAAzfEUua+3NgSqAo= github.com/jedib0t/go-pretty/v6 v6.6.5/go.mod h1:Uq/HrbhuFty5WSVNfjpQQe47x16RwVGXIveNGEyGtHs= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -513,8 +445,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw= -github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/lmittmann/tint v1.0.6 h1:vkkuDAZXc0EFGNzYjWcV0h7eEX+uujH48f/ifSkJWgc= github.com/lmittmann/tint v1.0.6/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= @@ -673,8 +603,6 @@ github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3 github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= -github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/samber/lo v1.48.0 h1:ELOfcaM7vdYPe0egBS2Nxa8LxkY4lR+9LBzj0l6cHJ0= github.com/samber/lo v1.48.0/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= @@ -728,7 +656,6 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -822,13 +749,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= -golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA= golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -840,8 +763,6 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= -golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -863,10 +784,6 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -921,8 +838,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -931,8 +846,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= -golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= -golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -962,8 +875,6 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= -golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= -golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/service/contracts.go b/internal/service/contracts.go index 1b0a9601..cdb1a8b0 100644 --- a/internal/service/contracts.go +++ b/internal/service/contracts.go @@ -95,7 +95,7 @@ type LibraryElementsApi interface { // AuthenticationApi Contract definition type AuthenticationApi interface { - TokenApi + // TokenApi ServiceAccountApi Login() } @@ -141,9 +141,10 @@ type OrganizationsApi interface { type ServiceAccountApi interface { ListServiceAccounts() []*gdgType.ServiceAccountDTOWithTokens ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, error) + DeleteServiceAccount(accountId int64) error DeleteAllServiceAccounts() []string DeleteServiceAccountTokens(serviceId int64) []string - CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) + CreateServiceAccountToken(serviceAccountId int64, name string, expiration int64) (*models.NewAPIKeyResult, error) CreateServiceAccount(name, role string, expiration int64) (*models.ServiceAccountDTO, error) } @@ -155,12 +156,6 @@ type TeamsApi interface { DeleteTeam(filter filters.Filter) ([]*models.TeamDTO, error) } -type TokenApi interface { - ListAPIKeys() []*models.APIKeyDTO - DeleteAllTokens() []string - CreateAPIKey(name, role string, expiration int64) (*models.NewAPIKeyResult, error) -} - // UsersApi Contract definition type UsersApi interface { // UserApi diff --git a/internal/service/mocks/AuthenticationApi.go b/internal/service/mocks/AuthenticationApi.go index 8f44c16c..9aadf439 100644 --- a/internal/service/mocks/AuthenticationApi.go +++ b/internal/service/mocks/AuthenticationApi.go @@ -22,66 +22,6 @@ func (_m *AuthenticationApi) EXPECT() *AuthenticationApi_Expecter { return &AuthenticationApi_Expecter{mock: &_m.Mock} } -// CreateAPIKey provides a mock function with given fields: name, role, expiration -func (_m *AuthenticationApi) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) - - if len(ret) == 0 { - panic("no return value specified for CreateAPIKey") - } - - var r0 *models.NewAPIKeyResult - var r1 error - if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) - } - if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*models.NewAPIKeyResult) - } - } - - if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { - r1 = rf(name, role, expiration) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// AuthenticationApi_CreateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAPIKey' -type AuthenticationApi_CreateAPIKey_Call struct { - *mock.Call -} - -// CreateAPIKey is a helper method to define mock.On call -// - name string -// - role string -// - expiration int64 -func (_e *AuthenticationApi_Expecter) CreateAPIKey(name interface{}, role interface{}, expiration interface{}) *AuthenticationApi_CreateAPIKey_Call { - return &AuthenticationApi_CreateAPIKey_Call{Call: _e.mock.On("CreateAPIKey", name, role, expiration)} -} - -func (_c *AuthenticationApi_CreateAPIKey_Call) Run(run func(name string, role string, expiration int64)) *AuthenticationApi_CreateAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(string), args[2].(int64)) - }) - return _c -} - -func (_c *AuthenticationApi_CreateAPIKey_Call) Return(_a0 *models.NewAPIKeyResult, _a1 error) *AuthenticationApi_CreateAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *AuthenticationApi_CreateAPIKey_Call) RunAndReturn(run func(string, string, int64) (*models.NewAPIKeyResult, error)) *AuthenticationApi_CreateAPIKey_Call { - _c.Call.Return(run) - return _c -} - // CreateServiceAccount provides a mock function with given fields: name, role, expiration func (_m *AuthenticationApi) CreateServiceAccount(name string, role string, expiration int64) (*models.ServiceAccountDTO, error) { ret := _m.Called(name, role, expiration) @@ -142,9 +82,9 @@ func (_c *AuthenticationApi_CreateServiceAccount_Call) RunAndReturn(run func(str return _c } -// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration -func (_m *AuthenticationApi) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) +// CreateServiceAccountToken provides a mock function with given fields: serviceAccountId, role, expiration +func (_m *AuthenticationApi) CreateServiceAccountToken(serviceAccountId int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(serviceAccountId, role, expiration) if len(ret) == 0 { panic("no return value specified for CreateServiceAccountToken") @@ -153,10 +93,10 @@ func (_m *AuthenticationApi) CreateServiceAccountToken(name int64, role string, var r0 *models.NewAPIKeyResult var r1 error if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) + return rf(serviceAccountId, role, expiration) } if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) + r0 = rf(serviceAccountId, role, expiration) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.NewAPIKeyResult) @@ -164,7 +104,7 @@ func (_m *AuthenticationApi) CreateServiceAccountToken(name int64, role string, } if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { - r1 = rf(name, role, expiration) + r1 = rf(serviceAccountId, role, expiration) } else { r1 = ret.Error(1) } @@ -178,14 +118,14 @@ type AuthenticationApi_CreateServiceAccountToken_Call struct { } // CreateServiceAccountToken is a helper method to define mock.On call -// - name int64 +// - serviceAccountId int64 // - role string // - expiration int64 -func (_e *AuthenticationApi_Expecter) CreateServiceAccountToken(name interface{}, role interface{}, expiration interface{}) *AuthenticationApi_CreateServiceAccountToken_Call { - return &AuthenticationApi_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", name, role, expiration)} +func (_e *AuthenticationApi_Expecter) CreateServiceAccountToken(serviceAccountId interface{}, role interface{}, expiration interface{}) *AuthenticationApi_CreateServiceAccountToken_Call { + return &AuthenticationApi_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", serviceAccountId, role, expiration)} } -func (_c *AuthenticationApi_CreateServiceAccountToken_Call) Run(run func(name int64, role string, expiration int64)) *AuthenticationApi_CreateServiceAccountToken_Call { +func (_c *AuthenticationApi_CreateServiceAccountToken_Call) Run(run func(serviceAccountId int64, role string, expiration int64)) *AuthenticationApi_CreateServiceAccountToken_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(int64), args[1].(string), args[2].(int64)) }) @@ -249,49 +189,48 @@ func (_c *AuthenticationApi_DeleteAllServiceAccounts_Call) RunAndReturn(run func return _c } -// DeleteAllTokens provides a mock function with given fields: -func (_m *AuthenticationApi) DeleteAllTokens() []string { - ret := _m.Called() +// DeleteServiceAccount provides a mock function with given fields: accountId +func (_m *AuthenticationApi) DeleteServiceAccount(accountId int64) error { + ret := _m.Called(accountId) if len(ret) == 0 { - panic("no return value specified for DeleteAllTokens") + panic("no return value specified for DeleteServiceAccount") } - var r0 []string - if rf, ok := ret.Get(0).(func() []string); ok { - r0 = rf() + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(accountId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + r0 = ret.Error(0) } return r0 } -// AuthenticationApi_DeleteAllTokens_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllTokens' -type AuthenticationApi_DeleteAllTokens_Call struct { +// AuthenticationApi_DeleteServiceAccount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteServiceAccount' +type AuthenticationApi_DeleteServiceAccount_Call struct { *mock.Call } -// DeleteAllTokens is a helper method to define mock.On call -func (_e *AuthenticationApi_Expecter) DeleteAllTokens() *AuthenticationApi_DeleteAllTokens_Call { - return &AuthenticationApi_DeleteAllTokens_Call{Call: _e.mock.On("DeleteAllTokens")} +// DeleteServiceAccount is a helper method to define mock.On call +// - accountId int64 +func (_e *AuthenticationApi_Expecter) DeleteServiceAccount(accountId interface{}) *AuthenticationApi_DeleteServiceAccount_Call { + return &AuthenticationApi_DeleteServiceAccount_Call{Call: _e.mock.On("DeleteServiceAccount", accountId)} } -func (_c *AuthenticationApi_DeleteAllTokens_Call) Run(run func()) *AuthenticationApi_DeleteAllTokens_Call { +func (_c *AuthenticationApi_DeleteServiceAccount_Call) Run(run func(accountId int64)) *AuthenticationApi_DeleteServiceAccount_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(int64)) }) return _c } -func (_c *AuthenticationApi_DeleteAllTokens_Call) Return(_a0 []string) *AuthenticationApi_DeleteAllTokens_Call { +func (_c *AuthenticationApi_DeleteServiceAccount_Call) Return(_a0 error) *AuthenticationApi_DeleteServiceAccount_Call { _c.Call.Return(_a0) return _c } -func (_c *AuthenticationApi_DeleteAllTokens_Call) RunAndReturn(run func() []string) *AuthenticationApi_DeleteAllTokens_Call { +func (_c *AuthenticationApi_DeleteServiceAccount_Call) RunAndReturn(run func(int64) error) *AuthenticationApi_DeleteServiceAccount_Call { _c.Call.Return(run) return _c } @@ -344,53 +283,6 @@ func (_c *AuthenticationApi_DeleteServiceAccountTokens_Call) RunAndReturn(run fu return _c } -// ListAPIKeys provides a mock function with given fields: -func (_m *AuthenticationApi) ListAPIKeys() []*models.APIKeyDTO { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for ListAPIKeys") - } - - var r0 []*models.APIKeyDTO - if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*models.APIKeyDTO) - } - } - - return r0 -} - -// AuthenticationApi_ListAPIKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAPIKeys' -type AuthenticationApi_ListAPIKeys_Call struct { - *mock.Call -} - -// ListAPIKeys is a helper method to define mock.On call -func (_e *AuthenticationApi_Expecter) ListAPIKeys() *AuthenticationApi_ListAPIKeys_Call { - return &AuthenticationApi_ListAPIKeys_Call{Call: _e.mock.On("ListAPIKeys")} -} - -func (_c *AuthenticationApi_ListAPIKeys_Call) Run(run func()) *AuthenticationApi_ListAPIKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *AuthenticationApi_ListAPIKeys_Call) Return(_a0 []*models.APIKeyDTO) *AuthenticationApi_ListAPIKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *AuthenticationApi_ListAPIKeys_Call) RunAndReturn(run func() []*models.APIKeyDTO) *AuthenticationApi_ListAPIKeys_Call { - _c.Call.Return(run) - return _c -} - // ListServiceAccounts provides a mock function with given fields: func (_m *AuthenticationApi) ListServiceAccounts() []*types.ServiceAccountDTOWithTokens { ret := _m.Called() diff --git a/internal/service/mocks/GrafanaService.go b/internal/service/mocks/GrafanaService.go index 281a0ab4..38d56a22 100644 --- a/internal/service/mocks/GrafanaService.go +++ b/internal/service/mocks/GrafanaService.go @@ -177,66 +177,6 @@ func (_c *GrafanaService_ClearDashboardPermissions_Call) RunAndReturn(run func(f return _c } -// CreateAPIKey provides a mock function with given fields: name, role, expiration -func (_m *GrafanaService) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) - - if len(ret) == 0 { - panic("no return value specified for CreateAPIKey") - } - - var r0 *models.NewAPIKeyResult - var r1 error - if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) - } - if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*models.NewAPIKeyResult) - } - } - - if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { - r1 = rf(name, role, expiration) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GrafanaService_CreateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAPIKey' -type GrafanaService_CreateAPIKey_Call struct { - *mock.Call -} - -// CreateAPIKey is a helper method to define mock.On call -// - name string -// - role string -// - expiration int64 -func (_e *GrafanaService_Expecter) CreateAPIKey(name interface{}, role interface{}, expiration interface{}) *GrafanaService_CreateAPIKey_Call { - return &GrafanaService_CreateAPIKey_Call{Call: _e.mock.On("CreateAPIKey", name, role, expiration)} -} - -func (_c *GrafanaService_CreateAPIKey_Call) Run(run func(name string, role string, expiration int64)) *GrafanaService_CreateAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(string), args[2].(int64)) - }) - return _c -} - -func (_c *GrafanaService_CreateAPIKey_Call) Return(_a0 *models.NewAPIKeyResult, _a1 error) *GrafanaService_CreateAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *GrafanaService_CreateAPIKey_Call) RunAndReturn(run func(string, string, int64) (*models.NewAPIKeyResult, error)) *GrafanaService_CreateAPIKey_Call { - _c.Call.Return(run) - return _c -} - // CreateServiceAccount provides a mock function with given fields: name, role, expiration func (_m *GrafanaService) CreateServiceAccount(name string, role string, expiration int64) (*models.ServiceAccountDTO, error) { ret := _m.Called(name, role, expiration) @@ -297,9 +237,9 @@ func (_c *GrafanaService_CreateServiceAccount_Call) RunAndReturn(run func(string return _c } -// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration -func (_m *GrafanaService) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) +// CreateServiceAccountToken provides a mock function with given fields: serviceAccountId, role, expiration +func (_m *GrafanaService) CreateServiceAccountToken(serviceAccountId int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(serviceAccountId, role, expiration) if len(ret) == 0 { panic("no return value specified for CreateServiceAccountToken") @@ -308,10 +248,10 @@ func (_m *GrafanaService) CreateServiceAccountToken(name int64, role string, exp var r0 *models.NewAPIKeyResult var r1 error if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) + return rf(serviceAccountId, role, expiration) } if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) + r0 = rf(serviceAccountId, role, expiration) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.NewAPIKeyResult) @@ -319,7 +259,7 @@ func (_m *GrafanaService) CreateServiceAccountToken(name int64, role string, exp } if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { - r1 = rf(name, role, expiration) + r1 = rf(serviceAccountId, role, expiration) } else { r1 = ret.Error(1) } @@ -333,14 +273,14 @@ type GrafanaService_CreateServiceAccountToken_Call struct { } // CreateServiceAccountToken is a helper method to define mock.On call -// - name int64 +// - serviceAccountId int64 // - role string // - expiration int64 -func (_e *GrafanaService_Expecter) CreateServiceAccountToken(name interface{}, role interface{}, expiration interface{}) *GrafanaService_CreateServiceAccountToken_Call { - return &GrafanaService_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", name, role, expiration)} +func (_e *GrafanaService_Expecter) CreateServiceAccountToken(serviceAccountId interface{}, role interface{}, expiration interface{}) *GrafanaService_CreateServiceAccountToken_Call { + return &GrafanaService_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", serviceAccountId, role, expiration)} } -func (_c *GrafanaService_CreateServiceAccountToken_Call) Run(run func(name int64, role string, expiration int64)) *GrafanaService_CreateServiceAccountToken_Call { +func (_c *GrafanaService_CreateServiceAccountToken_Call) Run(run func(serviceAccountId int64, role string, expiration int64)) *GrafanaService_CreateServiceAccountToken_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(int64), args[1].(string), args[2].(int64)) }) @@ -644,17 +584,17 @@ func (_c *GrafanaService_DeleteAllServiceAccounts_Call) RunAndReturn(run func() return _c } -// DeleteAllTokens provides a mock function with given fields: -func (_m *GrafanaService) DeleteAllTokens() []string { - ret := _m.Called() +// DeleteAllUsers provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllUsers(filter filters.Filter) []string { + ret := _m.Called(filter) if len(ret) == 0 { - panic("no return value specified for DeleteAllTokens") + panic("no return value specified for DeleteAllUsers") } var r0 []string - if rf, ok := ret.Get(0).(func() []string); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]string) @@ -664,77 +604,76 @@ func (_m *GrafanaService) DeleteAllTokens() []string { return r0 } -// GrafanaService_DeleteAllTokens_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllTokens' -type GrafanaService_DeleteAllTokens_Call struct { +// GrafanaService_DeleteAllUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllUsers' +type GrafanaService_DeleteAllUsers_Call struct { *mock.Call } -// DeleteAllTokens is a helper method to define mock.On call -func (_e *GrafanaService_Expecter) DeleteAllTokens() *GrafanaService_DeleteAllTokens_Call { - return &GrafanaService_DeleteAllTokens_Call{Call: _e.mock.On("DeleteAllTokens")} +// DeleteAllUsers is a helper method to define mock.On call +// - filter filters.Filter +func (_e *GrafanaService_Expecter) DeleteAllUsers(filter interface{}) *GrafanaService_DeleteAllUsers_Call { + return &GrafanaService_DeleteAllUsers_Call{Call: _e.mock.On("DeleteAllUsers", filter)} } -func (_c *GrafanaService_DeleteAllTokens_Call) Run(run func()) *GrafanaService_DeleteAllTokens_Call { +func (_c *GrafanaService_DeleteAllUsers_Call) Run(run func(filter filters.Filter)) *GrafanaService_DeleteAllUsers_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(filters.Filter)) }) return _c } -func (_c *GrafanaService_DeleteAllTokens_Call) Return(_a0 []string) *GrafanaService_DeleteAllTokens_Call { +func (_c *GrafanaService_DeleteAllUsers_Call) Return(_a0 []string) *GrafanaService_DeleteAllUsers_Call { _c.Call.Return(_a0) return _c } -func (_c *GrafanaService_DeleteAllTokens_Call) RunAndReturn(run func() []string) *GrafanaService_DeleteAllTokens_Call { +func (_c *GrafanaService_DeleteAllUsers_Call) RunAndReturn(run func(filters.Filter) []string) *GrafanaService_DeleteAllUsers_Call { _c.Call.Return(run) return _c } -// DeleteAllUsers provides a mock function with given fields: filter -func (_m *GrafanaService) DeleteAllUsers(filter filters.Filter) []string { - ret := _m.Called(filter) +// DeleteServiceAccount provides a mock function with given fields: accountId +func (_m *GrafanaService) DeleteServiceAccount(accountId int64) error { + ret := _m.Called(accountId) if len(ret) == 0 { - panic("no return value specified for DeleteAllUsers") + panic("no return value specified for DeleteServiceAccount") } - var r0 []string - if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { - r0 = rf(filter) + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(accountId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + r0 = ret.Error(0) } return r0 } -// GrafanaService_DeleteAllUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllUsers' -type GrafanaService_DeleteAllUsers_Call struct { +// GrafanaService_DeleteServiceAccount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteServiceAccount' +type GrafanaService_DeleteServiceAccount_Call struct { *mock.Call } -// DeleteAllUsers is a helper method to define mock.On call -// - filter filters.Filter -func (_e *GrafanaService_Expecter) DeleteAllUsers(filter interface{}) *GrafanaService_DeleteAllUsers_Call { - return &GrafanaService_DeleteAllUsers_Call{Call: _e.mock.On("DeleteAllUsers", filter)} +// DeleteServiceAccount is a helper method to define mock.On call +// - accountId int64 +func (_e *GrafanaService_Expecter) DeleteServiceAccount(accountId interface{}) *GrafanaService_DeleteServiceAccount_Call { + return &GrafanaService_DeleteServiceAccount_Call{Call: _e.mock.On("DeleteServiceAccount", accountId)} } -func (_c *GrafanaService_DeleteAllUsers_Call) Run(run func(filter filters.Filter)) *GrafanaService_DeleteAllUsers_Call { +func (_c *GrafanaService_DeleteServiceAccount_Call) Run(run func(accountId int64)) *GrafanaService_DeleteServiceAccount_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(filters.Filter)) + run(args[0].(int64)) }) return _c } -func (_c *GrafanaService_DeleteAllUsers_Call) Return(_a0 []string) *GrafanaService_DeleteAllUsers_Call { +func (_c *GrafanaService_DeleteServiceAccount_Call) Return(_a0 error) *GrafanaService_DeleteServiceAccount_Call { _c.Call.Return(_a0) return _c } -func (_c *GrafanaService_DeleteAllUsers_Call) RunAndReturn(run func(filters.Filter) []string) *GrafanaService_DeleteAllUsers_Call { +func (_c *GrafanaService_DeleteServiceAccount_Call) RunAndReturn(run func(int64) error) *GrafanaService_DeleteServiceAccount_Call { _c.Call.Return(run) return _c } @@ -1818,53 +1757,6 @@ func (_c *GrafanaService_LintDashboards_Call) RunAndReturn(run func(types.LintRe return _c } -// ListAPIKeys provides a mock function with given fields: -func (_m *GrafanaService) ListAPIKeys() []*models.APIKeyDTO { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for ListAPIKeys") - } - - var r0 []*models.APIKeyDTO - if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*models.APIKeyDTO) - } - } - - return r0 -} - -// GrafanaService_ListAPIKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAPIKeys' -type GrafanaService_ListAPIKeys_Call struct { - *mock.Call -} - -// ListAPIKeys is a helper method to define mock.On call -func (_e *GrafanaService_Expecter) ListAPIKeys() *GrafanaService_ListAPIKeys_Call { - return &GrafanaService_ListAPIKeys_Call{Call: _e.mock.On("ListAPIKeys")} -} - -func (_c *GrafanaService_ListAPIKeys_Call) Run(run func()) *GrafanaService_ListAPIKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *GrafanaService_ListAPIKeys_Call) Return(_a0 []*models.APIKeyDTO) *GrafanaService_ListAPIKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *GrafanaService_ListAPIKeys_Call) RunAndReturn(run func() []*models.APIKeyDTO) *GrafanaService_ListAPIKeys_Call { - _c.Call.Return(run) - return _c -} - // ListConnectionPermissions provides a mock function with given fields: filter func (_m *GrafanaService) ListConnectionPermissions(filter filters.Filter) []internaltypes.ConnectionPermissionItem { ret := _m.Called(filter) diff --git a/internal/service/mocks/ServiceAccountApi.go b/internal/service/mocks/ServiceAccountApi.go index 733e9e2c..e4299540 100644 --- a/internal/service/mocks/ServiceAccountApi.go +++ b/internal/service/mocks/ServiceAccountApi.go @@ -82,9 +82,9 @@ func (_c *ServiceAccountApi_CreateServiceAccount_Call) RunAndReturn(run func(str return _c } -// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration -func (_m *ServiceAccountApi) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) +// CreateServiceAccountToken provides a mock function with given fields: serviceAccountId, role, expiration +func (_m *ServiceAccountApi) CreateServiceAccountToken(serviceAccountId int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(serviceAccountId, role, expiration) if len(ret) == 0 { panic("no return value specified for CreateServiceAccountToken") @@ -93,10 +93,10 @@ func (_m *ServiceAccountApi) CreateServiceAccountToken(name int64, role string, var r0 *models.NewAPIKeyResult var r1 error if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) + return rf(serviceAccountId, role, expiration) } if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) + r0 = rf(serviceAccountId, role, expiration) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*models.NewAPIKeyResult) @@ -104,7 +104,7 @@ func (_m *ServiceAccountApi) CreateServiceAccountToken(name int64, role string, } if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { - r1 = rf(name, role, expiration) + r1 = rf(serviceAccountId, role, expiration) } else { r1 = ret.Error(1) } @@ -118,14 +118,14 @@ type ServiceAccountApi_CreateServiceAccountToken_Call struct { } // CreateServiceAccountToken is a helper method to define mock.On call -// - name int64 +// - serviceAccountId int64 // - role string // - expiration int64 -func (_e *ServiceAccountApi_Expecter) CreateServiceAccountToken(name interface{}, role interface{}, expiration interface{}) *ServiceAccountApi_CreateServiceAccountToken_Call { - return &ServiceAccountApi_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", name, role, expiration)} +func (_e *ServiceAccountApi_Expecter) CreateServiceAccountToken(serviceAccountId interface{}, role interface{}, expiration interface{}) *ServiceAccountApi_CreateServiceAccountToken_Call { + return &ServiceAccountApi_CreateServiceAccountToken_Call{Call: _e.mock.On("CreateServiceAccountToken", serviceAccountId, role, expiration)} } -func (_c *ServiceAccountApi_CreateServiceAccountToken_Call) Run(run func(name int64, role string, expiration int64)) *ServiceAccountApi_CreateServiceAccountToken_Call { +func (_c *ServiceAccountApi_CreateServiceAccountToken_Call) Run(run func(serviceAccountId int64, role string, expiration int64)) *ServiceAccountApi_CreateServiceAccountToken_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(int64), args[1].(string), args[2].(int64)) }) @@ -189,6 +189,52 @@ func (_c *ServiceAccountApi_DeleteAllServiceAccounts_Call) RunAndReturn(run func return _c } +// DeleteServiceAccount provides a mock function with given fields: accountId +func (_m *ServiceAccountApi) DeleteServiceAccount(accountId int64) error { + ret := _m.Called(accountId) + + if len(ret) == 0 { + panic("no return value specified for DeleteServiceAccount") + } + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(accountId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ServiceAccountApi_DeleteServiceAccount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteServiceAccount' +type ServiceAccountApi_DeleteServiceAccount_Call struct { + *mock.Call +} + +// DeleteServiceAccount is a helper method to define mock.On call +// - accountId int64 +func (_e *ServiceAccountApi_Expecter) DeleteServiceAccount(accountId interface{}) *ServiceAccountApi_DeleteServiceAccount_Call { + return &ServiceAccountApi_DeleteServiceAccount_Call{Call: _e.mock.On("DeleteServiceAccount", accountId)} +} + +func (_c *ServiceAccountApi_DeleteServiceAccount_Call) Run(run func(accountId int64)) *ServiceAccountApi_DeleteServiceAccount_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int64)) + }) + return _c +} + +func (_c *ServiceAccountApi_DeleteServiceAccount_Call) Return(_a0 error) *ServiceAccountApi_DeleteServiceAccount_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ServiceAccountApi_DeleteServiceAccount_Call) RunAndReturn(run func(int64) error) *ServiceAccountApi_DeleteServiceAccount_Call { + _c.Call.Return(run) + return _c +} + // DeleteServiceAccountTokens provides a mock function with given fields: serviceId func (_m *ServiceAccountApi) DeleteServiceAccountTokens(serviceId int64) []string { ret := _m.Called(serviceId) diff --git a/internal/service/mocks/TokenApi.go b/internal/service/mocks/TokenApi.go deleted file mode 100644 index 880a21b1..00000000 --- a/internal/service/mocks/TokenApi.go +++ /dev/null @@ -1,189 +0,0 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. - -package mocks - -import ( - models "github.com/grafana/grafana-openapi-client-go/models" - mock "github.com/stretchr/testify/mock" -) - -// TokenApi is an autogenerated mock type for the TokenApi type -type TokenApi struct { - mock.Mock -} - -type TokenApi_Expecter struct { - mock *mock.Mock -} - -func (_m *TokenApi) EXPECT() *TokenApi_Expecter { - return &TokenApi_Expecter{mock: &_m.Mock} -} - -// CreateAPIKey provides a mock function with given fields: name, role, expiration -func (_m *TokenApi) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { - ret := _m.Called(name, role, expiration) - - if len(ret) == 0 { - panic("no return value specified for CreateAPIKey") - } - - var r0 *models.NewAPIKeyResult - var r1 error - if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { - return rf(name, role, expiration) - } - if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { - r0 = rf(name, role, expiration) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*models.NewAPIKeyResult) - } - } - - if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { - r1 = rf(name, role, expiration) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// TokenApi_CreateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAPIKey' -type TokenApi_CreateAPIKey_Call struct { - *mock.Call -} - -// CreateAPIKey is a helper method to define mock.On call -// - name string -// - role string -// - expiration int64 -func (_e *TokenApi_Expecter) CreateAPIKey(name interface{}, role interface{}, expiration interface{}) *TokenApi_CreateAPIKey_Call { - return &TokenApi_CreateAPIKey_Call{Call: _e.mock.On("CreateAPIKey", name, role, expiration)} -} - -func (_c *TokenApi_CreateAPIKey_Call) Run(run func(name string, role string, expiration int64)) *TokenApi_CreateAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(string), args[2].(int64)) - }) - return _c -} - -func (_c *TokenApi_CreateAPIKey_Call) Return(_a0 *models.NewAPIKeyResult, _a1 error) *TokenApi_CreateAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *TokenApi_CreateAPIKey_Call) RunAndReturn(run func(string, string, int64) (*models.NewAPIKeyResult, error)) *TokenApi_CreateAPIKey_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAllTokens provides a mock function with given fields: -func (_m *TokenApi) DeleteAllTokens() []string { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for DeleteAllTokens") - } - - var r0 []string - if rf, ok := ret.Get(0).(func() []string); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - return r0 -} - -// TokenApi_DeleteAllTokens_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllTokens' -type TokenApi_DeleteAllTokens_Call struct { - *mock.Call -} - -// DeleteAllTokens is a helper method to define mock.On call -func (_e *TokenApi_Expecter) DeleteAllTokens() *TokenApi_DeleteAllTokens_Call { - return &TokenApi_DeleteAllTokens_Call{Call: _e.mock.On("DeleteAllTokens")} -} - -func (_c *TokenApi_DeleteAllTokens_Call) Run(run func()) *TokenApi_DeleteAllTokens_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *TokenApi_DeleteAllTokens_Call) Return(_a0 []string) *TokenApi_DeleteAllTokens_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *TokenApi_DeleteAllTokens_Call) RunAndReturn(run func() []string) *TokenApi_DeleteAllTokens_Call { - _c.Call.Return(run) - return _c -} - -// ListAPIKeys provides a mock function with given fields: -func (_m *TokenApi) ListAPIKeys() []*models.APIKeyDTO { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for ListAPIKeys") - } - - var r0 []*models.APIKeyDTO - if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*models.APIKeyDTO) - } - } - - return r0 -} - -// TokenApi_ListAPIKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAPIKeys' -type TokenApi_ListAPIKeys_Call struct { - *mock.Call -} - -// ListAPIKeys is a helper method to define mock.On call -func (_e *TokenApi_Expecter) ListAPIKeys() *TokenApi_ListAPIKeys_Call { - return &TokenApi_ListAPIKeys_Call{Call: _e.mock.On("ListAPIKeys")} -} - -func (_c *TokenApi_ListAPIKeys_Call) Run(run func()) *TokenApi_ListAPIKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *TokenApi_ListAPIKeys_Call) Return(_a0 []*models.APIKeyDTO) *TokenApi_ListAPIKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *TokenApi_ListAPIKeys_Call) RunAndReturn(run func() []*models.APIKeyDTO) *TokenApi_ListAPIKeys_Call { - _c.Call.Return(run) - return _c -} - -// NewTokenApi creates a new instance of TokenApi. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewTokenApi(t interface { - mock.TestingT - Cleanup(func()) -}) *TokenApi { - mock := &TokenApi{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/service/serviceaccounts.go b/internal/service/serviceaccounts.go index b83c30fb..aae7a029 100644 --- a/internal/service/serviceaccounts.go +++ b/internal/service/serviceaccounts.go @@ -14,6 +14,7 @@ import ( "github.com/samber/lo" ) +// TODO: create a method to simply delete a service account. func (s *DashNGoImpl) CreateServiceAccount(name, role string, expiration int64) (*models.ServiceAccountDTO, error) { p := service_accounts.NewCreateServiceAccountParams() p.Body = &models.CreateServiceAccountForm{ @@ -80,12 +81,17 @@ func (s *DashNGoImpl) ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, e return response.GetPayload(), nil } +func (s *DashNGoImpl) DeleteServiceAccount(accountId int64) error { + _, err := s.GetClient().ServiceAccounts.DeleteServiceAccount(accountId) + return err +} + func (s *DashNGoImpl) DeleteAllServiceAccounts() []string { var accountNames []string accounts := s.ListServiceAccounts() for _, account := range accounts { accountId := account.ServiceAccount.ID - _, err := s.GetClient().ServiceAccounts.DeleteServiceAccount(accountId) + err := s.DeleteServiceAccount(accountId) if err != nil { slog.Warn("Failed to delete service account", "ServiceAccountId", accountId) } else { diff --git a/internal/service/tokens.go b/internal/service/tokens.go deleted file mode 100644 index cbb696c4..00000000 --- a/internal/service/tokens.go +++ /dev/null @@ -1,60 +0,0 @@ -package service - -import ( - "fmt" - "log" - "log/slog" - - "github.com/grafana/grafana-openapi-client-go/client/api_keys" - "github.com/grafana/grafana-openapi-client-go/models" -) - -// ListAPIKeys returns a list of all known API Keys and service accounts -func (s *DashNGoImpl) ListAPIKeys() []*models.APIKeyDTO { - params := api_keys.NewGetAPIkeysParams() - keys, err := s.GetBasicAuthClient().APIKeys.GetAPIkeys(params) - if err != nil { - log.Fatal("unable to list API Keys") - } - return keys.GetPayload() -} - -// DeleteAllTokens Deletes all known tokens -func (s *DashNGoImpl) DeleteAllTokens() []string { - deleted := []string{} - keys := s.ListAPIKeys() - for _, key := range keys { - err := s.deleteAPIKey(key.ID) - if err != nil { - slog.Warn("Failed to delete API key", "APIKeyID", key.ID, "APIKey", key.Name) - continue - } - deleted = append(deleted, key.Name) - } - - return deleted -} - -// CreateAPIKey create a new key for the given role and expiration specified -func (s *DashNGoImpl) CreateAPIKey(name, role string, expiration int64) (*models.NewAPIKeyResult, error) { - p := &models.AddAPIKeyCommand{ - Name: name, - Role: role, - } - if expiration != 0 { - p.SecondsToLive = expiration - } - newKey, err := s.GetClient().APIKeys.AddAPIkey(p) - if err != nil { - return nil, fmt.Errorf("unable to create a new API Key") - } - return newKey.GetPayload(), nil -} - -func (s *DashNGoImpl) deleteAPIKey(id int64) error { - _, err := s.GetClient().APIKeys.DeleteAPIkey(id) - if err != nil { - return fmt.Errorf("failed to delete API Key: %d", id) - } - return nil -} diff --git a/pkg/test_tooling/common.go b/pkg/test_tooling/common.go index 68dc0197..dff63b17 100644 --- a/pkg/test_tooling/common.go +++ b/pkg/test_tooling/common.go @@ -61,9 +61,11 @@ func InitTest(t *testing.T, cfgProvider config.Provider, envProp map[string]stri } // Setup Token Auth - apiClient.DeleteAllTokens() // Remove any old data - tokenName, _ := uuid.NewUUID() - newKey, err := apiClient.CreateAPIKey(tokenName.String(), "admin", 0) + apiClient.DeleteAllServiceAccounts() + serviceName, _ := uuid.NewUUID() + serviceAccnt, err := apiClient.CreateServiceAccount(serviceName.String(), "admin", 0) + assert.NoError(t, err, "Unable to create test service account") + newKey, err := apiClient.CreateServiceAccountToken(serviceAccnt.ID, "admin", 0) assert.Nil(t, err) cfg := cfgProvider() @@ -109,14 +111,13 @@ func InitTestLegacy(t *testing.T, cfgName *string, envProp map[string]string) (s err = yaml.Unmarshal(testData, &data) assert.Nil(t, err) - apiClient.DeleteAllTokens() // Remove any old data - tokenName, _ := uuid.NewUUID() - newKey, err := apiClient.CreateAPIKey(tokenName.String(), "admin", 0) + apiClient.DeleteAllServiceAccounts() + serviceName, _ := uuid.NewUUID() + serviceAccnt, err := apiClient.CreateServiceAccount(serviceName.String(), "admin", 0) + assert.NoError(t, err, "Unable to create test service account") + newKey, err := apiClient.CreateServiceAccountToken(serviceAccnt.ID, "admin", 0) assert.Nil(t, err) - wrapper := map[string]*config.GrafanaConfig{} - _ = wrapper - level1 := data["contexts"].(map[string]interface{}) level2 := level1["testing"].(map[string]interface{}) level2["token"] = newKey.Key diff --git a/test/common_test.go b/test/common_test.go index 72e873f6..feed5cda 100644 --- a/test/common_test.go +++ b/test/common_test.go @@ -4,6 +4,9 @@ import ( "log/slog" "os" "testing" + "time" + + "github.com/brianvoe/gofakeit/v6" "github.com/esnet/gdg/pkg/test_tooling" "github.com/esnet/gdg/pkg/test_tooling/path" @@ -16,6 +19,7 @@ const ( ) func TestMain(m *testing.M) { + gofakeit.Seed(time.Now().Unix()) // If 0 will use crypto/rand to generate a number err := path.FixTestDir("test", "..") if err != nil { panic(err) diff --git a/test/service_account_test.go b/test/service_account_test.go new file mode 100644 index 00000000..01e99a91 --- /dev/null +++ b/test/service_account_test.go @@ -0,0 +1,53 @@ +package test + +import ( + "log/slog" + "os" + "strings" + "testing" + + "github.com/brianvoe/gofakeit/v6" + "github.com/esnet/gdg/internal/config" + "github.com/esnet/gdg/internal/service" + "github.com/esnet/gdg/pkg/test_tooling" + "github.com/stretchr/testify/assert" +) + +func TestServiceAccountCrud(t *testing.T) { + config.InitGdgConfig("testing") + if os.Getenv(test_tooling.EnableTokenTestsEnv) == "1" { + t.Skip("Skipping Token configuration, Organization CRUD requires Basic SecureData") + } + apiClient, _, cleanup := test_tooling.InitTest(t, service.DefaultConfigProvider, nil) + defer func() { + err := cleanup() + if err != nil { + slog.Warn("Unable to clean up after service account testtests") + } + }() + + name := gofakeit.Name() + account, err := apiClient.CreateServiceAccount(name, "admin", 0) + assert.NoError(t, err) + assert.Equal(t, account.Name, name) + // another svc + _, err = apiClient.CreateServiceAccount(gofakeit.Name(), "admin", 0) + serviceAccounts := apiClient.ListServiceAccounts() + assert.Equal(t, len(serviceAccounts), 2) + tokenName := gofakeit.Name() + token, err := apiClient.CreateServiceAccountToken(account.ID, tokenName, 0) + + assert.NoError(t, err) + assert.True(t, strings.HasPrefix(token.Key, "glsa_")) + tokens, err := apiClient.ListServiceAccountsTokens(account.ID) + assert.NoError(t, err) + assert.Equal(t, len(tokens), 1) + assert.Equal(t, tokens[0].Name, tokenName) + assert.NoError(t, apiClient.DeleteServiceAccount(account.ID)) + serviceAccounts = apiClient.ListServiceAccounts() + assert.Equal(t, len(serviceAccounts), 1) + names := apiClient.DeleteAllServiceAccounts() + assert.Equal(t, len(names), 1) + serviceAccounts = apiClient.ListServiceAccounts() + assert.Equal(t, len(serviceAccounts), 0) +} diff --git a/website/content/docs/usage_guide/tools_guide.md b/website/content/docs/usage_guide/tools_guide.md index a394f6dc..4d53a16e 100644 --- a/website/content/docs/usage_guide/tools_guide.md +++ b/website/content/docs/usage_guide/tools_guide.md @@ -16,53 +16,23 @@ There are two sub commands for auth, service-accounts and tokens (will be deprec #### Token Management +No longer supported, Deprecated in v0.7.3 as it's been removed from the official grafana API. -```sh -./bin/gdg tools auth tokens list -- list current tokens (No access to the actual token secret) -./bin/gdg tools auth tokens new -- Create a new token. new [ttl in seconds, forever otherwise] -./bin/gdg tools auth tokens clear -- Deletes all tokens -``` - -{{< details "Token Listing" >}} -``` -┌────┬─────────┬───────┬───────────────┐ -│ ID │ NAME │ ROLE │ EXPIRATION │ -├────┼─────────┼───────┼───────────────┤ -│ 1 │ testing │ Admin │ No Expiration │ -└────┴─────────┴───────┴───────────────┘ -``` -{{< /details >}} - -Example of creating a new token. - -```sh -./bin/gdg auth tokens new foobar Admin 3600 -``` - -{{< details "New Token" >}} - -┌────┬────────┬─────────────────────────────────────────────────────────────┐ -│ ID │ NAME │ TOKEN │ -├────┼────────┼─────────────────────────────────────────────────────────────┤ -│ 2 │ foobar │ eyJrIjoiNzU2WVhiMEZpVWNlV3hWSUVZQTuIjoiZm9vYmFyIiwiaWQiOjF9 │ -└────┴────────┴─────────────────────────────────────────────────────────────┘ - -{{< /details >}} - +Please see below on how to add a token to a service account. #### Service Accounts ```sh ./bin/gdg tools auth svc clear delete all Service Accounts -./bin/gdg tools auth svc clearTokens delete all tokens for Service Account +./bin/gdg tools auth svc delete delete the given service account from grafana ./bin/gdg tools auth svc list list API Keys -./bin/gdg tools auth svc newService newService [ttl in seconds] -./bin/gdg tools auth svc newToken newToken [ttl in seconds] +./bin/gdg tools auth svc new newService [ttl in seconds] ``` + ```sh -./bin/gdg tools auth svc newService AwesomeSauceSvc admin +./bin/gdg tools auth svc new AwesomeSauceSvc admin ``` {{< details "New Service" >}} @@ -101,6 +71,29 @@ Example of creating a new token. └────┴─────────────────┴───────┴────────┴──────────┴──────────────┴───────────────┘ {{< /details >}} + +```sh +./bin/gdg tools auth service-accounts delete 4 +``` + +```sh +2025-01-26 16:54:00 INF Deleting Service Accounts for context context=testing serviceAccountId=4 +2025-01-26 16:54:00 INF Service account has been removed serviceAccountId=4 +``` + +#### Service Account Tokens + +```sh +./bin/gdg tools auth svc tokens new [ttl in seconds] +./bin/gdg tools auth svc tokens clear +``` + +Examples: +```sh +./bin/gdg tools auth svc tokens new 4 myToken 0 +./bin/gdg tools auth svc tokens clear 4 +``` + ### Dashboard Linter Integrated the official grafana [linter](https://github.com/grafana/dashboard-linter/) into GDG. Allows you to run the linter as part of gdg.