Skip to content
Open
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
6 changes: 3 additions & 3 deletions docs/stackit_service-account_token_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ stackit service-account token create [flags]
### Options

```
-e, --email string Service account email
-h, --help Help for "stackit service-account token create"
--ttl-days int How long (in days) the new access token is valid (default 90)
-e, --email string Service account email
-h, --help Help for "stackit service-account token create"
--ttl-days int32 How long (in days) the new access token is valid (default 90)
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.20.0
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7
github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 h1:sQ3fdtUjgIL2Ul8nRYVVacHOwi5aSMTGGbYVL30oQBU=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6/go.mod h1:3fjlL+9YtuI9Oocl1ZeYIK48ImtY4DwPggFhqAygr7o=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0/go.mod h1:EXq8/J7t9p8zPmdIq+atuxyAbnQwxrQT18fI+Qpv98k=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.20.0 h1:4/xfpcqHLkKkaVS/HOOIWa3n7Z/O0DysPc+/+FVSltE=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.20.0/go.mod h1:xJNa86o89czK2o60+s46vz8+NSKDTbQduFGFaztJnsA=
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 h1:M2PYLF8k3zmAwYWSKfUiCTNTXr7ROGuJganVVEQA3YI=
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7/go.mod h1:jitkQuP2K/SH63Qor0C4pcqz1GDCy/lK2H4t8/VDse4=
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0 h1:JWAFnskRbNKT8x62pZcAMCC+p5hyTEkAyxqFwy39jFA=
Expand Down
15 changes: 7 additions & 8 deletions internal/cmd/service-account/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (

"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
Expand All @@ -14,10 +17,6 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
)

const (
Expand All @@ -26,7 +25,7 @@ const (

type inputModel struct {
*globalflags.GlobalFlagModel
Name *string
Name string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand Down Expand Up @@ -94,15 +93,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,

model := inputModel{
GlobalFlagModel: globalFlags,
Name: flags.FlagToStringPointer(p, cmd, nameFlag),
Name: flags.FlagToStringValue(p, cmd, nameFlag),
}

p.DebugInputModel(model)
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceaccount.APIClient) serviceaccount.ApiCreateServiceAccountRequest {
req := apiClient.CreateServiceAccount(ctx, model.ProjectId)
req := apiClient.DefaultAPI.CreateServiceAccount(ctx, model.ProjectId)
req = req.CreateServiceAccountPayload(serviceaccount.CreateServiceAccountPayload{
Name: model.Name,
})
Expand All @@ -115,7 +114,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, serviceAc
}

return p.OutputResult(outputFormat, serviceAccount, func() error {
p.Outputf("Created service account for project %q. Email: %s\n", projectLabel, utils.PtrString(serviceAccount.Email))
p.Outputf("Created service account for project %q. Email: %s\n", projectLabel, serviceAccount.Email)
return nil
})
}
23 changes: 11 additions & 12 deletions internal/cmd/service-account/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serviceaccount.APIClient{}
var testClient = &serviceaccount.APIClient{DefaultAPI: &serviceaccount.DefaultAPIService{}}
var testProjectId = uuid.NewString()

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
Expand All @@ -40,7 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr("example"),
Name: "example",
}
for _, mod := range mods {
mod(model)
Expand All @@ -49,9 +48,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serviceaccount.ApiCreateServiceAccountRequest)) serviceaccount.ApiCreateServiceAccountRequest {
request := testClient.CreateServiceAccount(testCtx, testProjectId)
request := testClient.DefaultAPI.CreateServiceAccount(testCtx, testProjectId)
request = request.CreateServiceAccountPayload(serviceaccount.CreateServiceAccountPayload{
Name: utils.Ptr("example"),
Name: "example",
})
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestParseInput(t *testing.T) {
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr(""),
Name: "",
},
},
{
Expand Down Expand Up @@ -142,7 +141,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serviceaccount.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/service-account/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

const (
Expand Down Expand Up @@ -91,6 +91,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceaccount.APIClient) serviceaccount.ApiDeleteServiceAccountRequest {
req := apiClient.DeleteServiceAccount(ctx, model.ProjectId, model.Email)
req := apiClient.DefaultAPI.DeleteServiceAccount(ctx, model.ProjectId, model.Email)
return req
}
8 changes: 4 additions & 4 deletions internal/cmd/service-account/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serviceaccount.APIClient{}
var testClient = &serviceaccount.APIClient{DefaultAPI: &serviceaccount.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testEmail = "service-account-email-1234567@sa.stackit.cloud"

Expand Down Expand Up @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serviceaccount.ApiDeleteServiceAccountRequest)) serviceaccount.ApiDeleteServiceAccountRequest {
request := testClient.DeleteServiceAccount(testCtx, testProjectId, testEmail)
request := testClient.DefaultAPI.DeleteServiceAccount(testCtx, testProjectId, testEmail)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serviceaccount.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/service-account/get-jwks/get_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

const (
Expand Down Expand Up @@ -54,7 +54,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("get JWKS: %w", err)
}
jwks := *resp.Keys
jwks := resp.Keys
if len(jwks) == 0 {
params.Printer.Info("Empty JWKS for service account %s\n", model.Email)
return nil
Expand All @@ -79,7 +79,7 @@ func parseInput(p *print.Printer, _ *cobra.Command, inputArgs []string) (*inputM
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceaccount.APIClient) serviceaccount.ApiGetJWKSRequest {
req := apiClient.GetJWKS(ctx, model.Email)
req := apiClient.DefaultAPI.GetJWKS(ctx, model.Email)
return req
}

Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/service-account/get-jwks/get_jwks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"

Expand All @@ -16,7 +16,7 @@ import (
type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serviceaccount.APIClient{}
var testClient = &serviceaccount.APIClient{DefaultAPI: &serviceaccount.DefaultAPIService{}}
var testEmail = "service-account-email-1234567@sa.stackit.cloud"

func fixtureArgValues(mods ...func(argValues []string)) []string {
Expand All @@ -40,7 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serviceaccount.ApiGetJWKSRequest)) serviceaccount.ApiGetJWKSRequest {
request := testClient.GetJWKS(testCtx, testEmail)
request := testClient.DefaultAPI.GetJWKS(testCtx, testEmail)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serviceaccount.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/service-account/key/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

const (
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("create service account key: %w", err)
}

params.Printer.Info("Created key for service account %s with ID %q\n", model.ServiceAccountEmail, *resp.Id)
params.Printer.Outputf("Created key for service account %s with ID %q\n", model.ServiceAccountEmail, resp.Id)

key, err := json.MarshalIndent(resp, "", " ")
if err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceaccount.APIClient, now time.Time) serviceaccount.ApiCreateServiceAccountKeyRequest {
req := apiClient.CreateServiceAccountKey(ctx, model.ProjectId, model.ServiceAccountEmail)
req := apiClient.DefaultAPI.CreateServiceAccountKey(ctx, model.ProjectId, model.ServiceAccountEmail)

var validUntil *time.Time
validUntil = nil
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/service-account/key/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serviceaccount.APIClient{}
var testClient = &serviceaccount.APIClient{DefaultAPI: &serviceaccount.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testServiceAccountEmail = "my-service-account-1234567@sa.stackit.cloud"
var testNow = time.Now()
Expand Down Expand Up @@ -53,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serviceaccount.ApiCreateServiceAccountKeyRequest)) serviceaccount.ApiCreateServiceAccountKeyRequest {
request := testClient.CreateServiceAccountKey(testCtx, testProjectId, testServiceAccountEmail)
request := testClient.DefaultAPI.CreateServiceAccountKey(testCtx, testProjectId, testServiceAccountEmail)
request = request.CreateServiceAccountKeyPayload(serviceaccount.CreateServiceAccountKeyPayload{})
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serviceaccount.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/service-account/key/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

const (
Expand Down Expand Up @@ -112,6 +112,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceaccount.APIClient) serviceaccount.ApiDeleteServiceAccountKeyRequest {
req := apiClient.DeleteServiceAccountKey(ctx, model.ProjectId, model.ServiceAccountEmail, model.KeyId)
req := apiClient.DefaultAPI.DeleteServiceAccountKey(ctx, model.ProjectId, model.ServiceAccountEmail, model.KeyId)
return req
}
8 changes: 4 additions & 4 deletions internal/cmd/service-account/key/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serviceaccount"
serviceaccount "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount/v2api"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serviceaccount.APIClient{}
var testClient = &serviceaccount.APIClient{DefaultAPI: &serviceaccount.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testServiceAccountEmail = "my-service-account-1234567@sa.stackit.cloud"
var testKeyId = uuid.NewString()
Expand Down Expand Up @@ -60,7 +60,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serviceaccount.ApiDeleteServiceAccountKeyRequest)) serviceaccount.ApiDeleteServiceAccountKeyRequest {
request := testClient.DeleteServiceAccountKey(testCtx, testProjectId, testServiceAccountEmail, testKeyId)
request := testClient.DefaultAPI.DeleteServiceAccountKey(testCtx, testProjectId, testServiceAccountEmail, testKeyId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serviceaccount.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
Loading
Loading