Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/stackit_logs_access-token_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ stackit logs access-token create [flags]
--display-name string Display name for the access token
-h, --help Help for "stackit logs access-token create"
--instance-id string ID of the Logs instance
--lifetime int Lifetime of the access token in days [1 - 180]
--lifetime int32 Lifetime of the access token in days [1 - 180]
--permissions strings Permissions of the access token ["read" "write"]
```

Expand Down
10 changes: 5 additions & 5 deletions docs/stackit_logs_instance_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ stackit logs instance create [flags]
### Options

```
--acl strings Access control list
--description string Description
--display-name string Display name
-h, --help Help for "stackit logs instance create"
--retention-days int The days for how long the logs should be stored before being cleaned up
--acl strings Access control list
--description string Description
--display-name string Display name
-h, --help Help for "stackit logs instance create"
--retention-days int32 The days for how long the logs should be stored before being cleaned up
```

### Options inherited from parent commands
Expand Down
10 changes: 5 additions & 5 deletions docs/stackit_logs_instance_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ stackit logs instance update INSTANCE_ID [flags]
### Options

```
--acl strings Access control list
--description string Description
--display-name string Display name
-h, --help Help for "stackit logs instance update"
--retention-days int The days for how long the logs should be stored before being cleaned up
--acl strings Access control list
--description string Description
--display-name string Display name
-h, --help Help for "stackit logs instance update"
--retention-days int32 The days for how long the logs should be stored before being cleaned up
```

### 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 @@ -24,7 +24,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0 h1:1dvL7tX9
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0/go.mod h1:+Ld3dn648I+YKcBV3fEkYpDSr3fel421+LurJGywSBs=
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.6 h1:4x30lC+YBmo7XpsAzTn0W+C/oP5flnLVgIh5u3O/P0o=
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.6/go.mod h1:ewaYUiZcBTSS6urE5zEJBPCqxu70w2IjnBHCvnKdFKE=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 h1:vr4atxFRT+EL+DqONMT5R44f7AzEMbePa9U7PEE0THU=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2/go.mod h1:CAPsiTX7osAImfrG5RnIjaJ/Iz3QpoBKuH2fS346wuQ=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0 h1:g7zpfQFFq3UhAWrMK9rPaZY6dLMAuMJf5g6+r7VRTXc=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0/go.mod h1:tvRejL8w5KpGBbLFPQ+dXOJURgZ3OMbZmwxlKQrGMuA=
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6 h1:Y/byRjX2u/OZl0gKS/Rau6ob2bDyv26xnw6A6JNkKJk=
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.6/go.mod h1:sY66ZgCgBc1mScPV95ek5WtUEGYizdP1RMsGaqbdbhw=
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8 h1:S7t4wcT6SN8ZzdoY8d6VbF903zFpGjzqrU0FN27rJPg=
Expand Down
23 changes: 13 additions & 10 deletions internal/cmd/logs/access_token/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/stackitcloud/stackit-sdk-go/services/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -35,7 +35,7 @@ type inputModel struct {
InstanceId string
Description *string
DisplayName string
Lifetime *int64
Lifetime *int32
Permissions []string
}

Expand Down Expand Up @@ -80,7 +80,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
projectLabel = model.ProjectId
}

instanceLabel, err := logsUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId)
instanceLabel, err := logsUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = model.InstanceId
Expand Down Expand Up @@ -110,7 +110,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the Logs instance")
cmd.Flags().String(displayNameFlag, "", "Display name for the access token")
cmd.Flags().String(descriptionFlag, "", "Description of the access token")
cmd.Flags().Int64(lifetimeFlag, 0, "Lifetime of the access token in days [1 - 180]")
cmd.Flags().Int32(lifetimeFlag, 0, "Lifetime of the access token in days [1 - 180]")
cmd.Flags().StringSlice(permissionsFlag, []string{}, `Permissions of the access token ["read" "write"]`)

err := flags.MarkFlagsRequired(cmd, instanceIdFlag, displayNameFlag, permissionsFlag)
Expand All @@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
DisplayName: flags.FlagToStringValue(p, cmd, displayNameFlag),
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
Lifetime: flags.FlagToInt64Pointer(p, cmd, lifetimeFlag),
Lifetime: flags.FlagToInt32Pointer(p, cmd, lifetimeFlag),
Permissions: flags.FlagToStringSliceValue(p, cmd, permissionsFlag),
}

Expand All @@ -137,13 +137,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiCreateAccessTokenRequest {
req := apiClient.CreateAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId)

req := apiClient.DefaultAPI.CreateAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId)
permissions := make([]logs.PermissionsInner, len(model.Permissions))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you copy that map function to our CLI (if not already present, pls check): https://github.com/stackitcloud/terraform-provider-stackit/blob/ffa60e66b90353ccdc074632a90c76bc3fe9cb0a/stackit/internal/utils/utils.go#L222-L229

Then it's just an inline call which is needed, see below

return req.CreateAccessTokenPayload(logs.CreateAccessTokenPayload{
		Description: model.Description,
		DisplayName: model.DisplayName,
		Lifetime:    model.Lifetime,
		Permissions: utils.Map(model.Permissions, func (t string) logs.PermissionsInner{
                return logs.PermissionsInner(t)
        }),
	})
``

for i, permission := range model.Permissions {
permissions[i] = logs.PermissionsInner(permission)
}
return req.CreateAccessTokenPayload(logs.CreateAccessTokenPayload{
Description: model.Description,
DisplayName: &model.DisplayName,
DisplayName: model.DisplayName,
Lifetime: model.Lifetime,
Permissions: &model.Permissions,
Permissions: permissions,
})
}

Expand All @@ -152,7 +155,7 @@ func outputResult(p *print.Printer, outputFormat, instanceLabel string, accessTo
return fmt.Errorf("access token cannot be nil")
}
return p.OutputResult(outputFormat, accessToken, func() error {
p.Outputf("Created access token for Logs instance %q.\n\nID: %s\nToken: %s\n", instanceLabel, utils.PtrValue(accessToken.Id), utils.PtrValue(accessToken.AccessToken))
p.Outputf("Created access token for Logs instance %q.\n\nID: %s\nToken: %s\n", instanceLabel, accessToken.Id, utils.PtrValue(accessToken.AccessToken))
return nil
})
}
32 changes: 17 additions & 15 deletions internal/cmd/logs/access_token/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
)

const (
Expand All @@ -26,7 +26,7 @@ type testCtxKey struct{}

var (
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
testClient = &logs.APIClient{}
testClient = &logs.APIClient{DefaultAPI: &logs.DefaultAPIService{}}
testProjectId = uuid.NewString()
testInstanceId = uuid.NewString()
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
InstanceId: testInstanceId,
Description: utils.Ptr(testDescription),
DisplayName: testDisplayName,
Lifetime: utils.Ptr(int64(0)),
Lifetime: utils.Ptr(int32(0)),
Permissions: []string{
"read",
"write",
Expand All @@ -72,7 +72,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *logs.ApiCreateAccessTokenRequest)) logs.ApiCreateAccessTokenRequest {
request := testClient.CreateAccessToken(testCtx, testProjectId, testRegion, testInstanceId)
request := testClient.DefaultAPI.CreateAccessToken(testCtx, testProjectId, testRegion, testInstanceId)
request = request.CreateAccessTokenPayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand All @@ -82,13 +82,13 @@ func fixtureRequest(mods ...func(request *logs.ApiCreateAccessTokenRequest)) log

func fixturePayload(mods ...func(payload *logs.CreateAccessTokenPayload)) logs.CreateAccessTokenPayload {
payload := logs.CreateAccessTokenPayload{
DisplayName: utils.Ptr(testDisplayName),
DisplayName: testDisplayName,
Description: utils.Ptr(testDescription),
Lifetime: utils.Ptr(int64(0)),
Permissions: utils.Ptr([]string{
Lifetime: utils.Ptr(int32(0)),
Permissions: []logs.PermissionsInner{
"read",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"read",
logme.PERMISSIONSINNER_READ,
logme.PERMISSIONSINNER_WRITE,

Why not use the constants?

"write",
}),
},
}
for _, mod := range mods {
mod(&payload)
Expand Down Expand Up @@ -216,6 +216,8 @@ func TestBuildRequest(t *testing.T) {
diff := cmp.Diff(tt.expectedRequest, request,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, logs.DefaultAPIService{}),

and then remove the line below

cmpopts.IgnoreFields(tt.expectedRequest, "ApiService"),

cmpopts.IgnoreFields(tt.expectedRequest, "ApiService"),
cmpopts.EquateEmpty(),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand All @@ -240,16 +242,16 @@ func TestOutputResult(t *testing.T) {
args: args{
instanceLabel: "",
accessToken: utils.Ptr(logs.AccessToken{
Id: utils.Ptr(uuid.NewString()),
Permissions: utils.Ptr([]string{
Id: uuid.NewString(),
Permissions: []logs.PermissionsInner{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"read",
"write",
}),
DisplayName: utils.Ptr("Token"),
},
DisplayName: "Token",
AccessToken: utils.Ptr("Secret access token"),
Creator: utils.Ptr(uuid.NewString()),
Expires: utils.Ptr(false),
Status: utils.Ptr(logs.ACCESSTOKENSTATUS_ACTIVE),
Creator: uuid.NewString(),
Expires: false,
Status: logs.ACCESSTOKENSTATUS_ACTIVE,
}),
},
wantErr: false,
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/logs/access_token/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-sdk-go/services/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"

"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
Expand Down Expand Up @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
}

// Get the display name for confirmation
accessTokenLabel, err := logUtils.GetAccessTokenName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
accessTokenLabel, err := logUtils.GetAccessTokenName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get access token: %v", err)
}
Expand Down Expand Up @@ -113,5 +113,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiDeleteAccessTokenRequest {
return apiClient.DeleteAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
return apiClient.DefaultAPI.DeleteAccessToken(ctx, model.ProjectId, model.Region, model.InstanceId, model.AccessTokenId)
}
8 changes: 4 additions & 4 deletions internal/cmd/logs/access_token/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
)

const (
Expand All @@ -21,7 +21,7 @@ type testCtxKey struct{}

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

testProjectId = uuid.NewString()
testInstanceId = uuid.NewString()
Expand Down Expand Up @@ -69,7 +69,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *logs.ApiDeleteAccessTokenRequest)) logs.ApiDeleteAccessTokenRequest {
request := testClient.DeleteAccessToken(testCtx, testProjectId, testRegion, testInstanceId, testAccessTokenId)
request := testClient.DefaultAPI.DeleteAccessToken(testCtx, testProjectId, testRegion, testInstanceId, testAccessTokenId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, tt.expectedRequest),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that change needed? 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's the same as above, the thing you aim to do should look like this

Suggested change
cmpopts.EquateComparable(testCtx, tt.expectedRequest),
cmpopts.EquateComparable(testCtx, logs.DefaultAPIService{}),

)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
14 changes: 6 additions & 8 deletions internal/cmd/logs/access_token/delete_all/delete_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-sdk-go/services/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"

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

"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/client"
logUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logs/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -55,7 +53,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return err
}

instanceLabel, err := logUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId)
instanceLabel, err := logUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = model.InstanceId
Expand All @@ -77,7 +75,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("delete all access token: nil result")
}

params.Printer.Outputf("Deleted %d access token(s)\n", len(utils.PtrValue(items.Tokens)))
params.Printer.Outputf("Deleted %d access token(s)\n", len(items.Tokens))
return nil
},
}
Expand Down Expand Up @@ -108,5 +106,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APIClient) logs.ApiDeleteAllAccessTokensRequest {
return apiClient.DeleteAllAccessTokens(ctx, model.ProjectId, model.Region, model.InstanceId)
return apiClient.DefaultAPI.DeleteAllAccessTokens(ctx, model.ProjectId, model.Region, model.InstanceId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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/logs"
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
)

const (
Expand All @@ -21,7 +21,7 @@ type testCtxKey struct{}

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

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

func fixtureRequest(mods ...func(request *logs.ApiDeleteAllAccessTokensRequest)) logs.ApiDeleteAllAccessTokensRequest {
request := testClient.DeleteAllAccessTokens(testCtx, testProjectId, testRegion, testInstanceId)
request := testClient.DefaultAPI.DeleteAllAccessTokens(testCtx, testProjectId, testRegion, testInstanceId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, tt.expectedRequest),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
Loading
Loading