Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/cmd/argus/instance/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
InstanceName: utils.Ptr("example-name"),
PlanId: utils.Ptr(testPlanId),
Expand Down Expand Up @@ -134,6 +135,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
PlanId: utils.Ptr(testPlanId),
InstanceName: utils.Ptr(""),
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/argus/instance/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: testInstanceId,
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/argus/instance/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: testInstanceId,
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/argus/instance/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Limit: utils.Ptr(int64(10)),
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/argus/instance/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: testInstanceId,
PlanId: utils.Ptr(testNewPlanId),
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/argus/plans/plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Limit: utils.Ptr(int64(10)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
cliErr "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/print"

"github.com/spf13/cobra"
sdkAuth "github.com/stackitcloud/stackit-sdk-go/core/auth"
Expand All @@ -31,7 +32,7 @@ type inputModel struct {
JwksCustomEndpoint string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "activate-service-account",
Short: "Authenticates using a service account",
Expand Down Expand Up @@ -72,11 +73,12 @@ func NewCmd() *cobra.Command {
// Initializes the authentication flow
rt, err := sdkAuth.SetupAuth(cfg)
if err != nil {
p.Debug(print.ErrorLevel, "setup auth: %v", err)
return &cliErr.ActivateServiceAccountError{}
}

// Authenticates the service account and stores credentials
email, err := auth.AuthenticateServiceAccount(rt)
email, err := auth.AuthenticateServiceAccount(p, rt)
if err != nil {
var activateServiceAccountError *cliErr.ActivateServiceAccountError
if !errors.As(err, &activateServiceAccountError) {
Expand All @@ -85,7 +87,7 @@ func NewCmd() *cobra.Command {
return err
}

cmd.Printf("You have been successfully authenticated to the STACKIT CLI!\nService account email: %s\n", email)
p.Info("You have been successfully authenticated to the STACKIT CLI!\nService account email: %s\n", email)

return nil
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
activateserviceaccount "github.com/stackitcloud/stackit-cli/internal/cmd/auth/activate-service-account"
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/login"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "auth",
Short: "Provides authentication functionality",
Long: "Provides authentication functionality.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd)
addSubcommands(cmd, p)
return cmd
}

func addSubcommands(cmd *cobra.Command) {
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(login.NewCmd())
cmd.AddCommand(activateserviceaccount.NewCmd())
cmd.AddCommand(activateserviceaccount.NewCmd(p))
}
9 changes: 5 additions & 4 deletions internal/cmd/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
recordset "github.com/stackitcloud/stackit-cli/internal/cmd/dns/record-set"
"github.com/stackitcloud/stackit-cli/internal/cmd/dns/zone"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "dns",
Short: "Provides functionality for DNS",
Long: "Provides functionality for DNS.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd)
addSubcommands(cmd, p)
return cmd
}

func addSubcommands(cmd *cobra.Command) {
cmd.AddCommand(zone.NewCmd())
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(zone.NewCmd(p))
cmd.AddCommand(recordset.NewCmd())
}
4 changes: 4 additions & 0 deletions internal/cmd/dns/record-set/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
Name: utils.Ptr("example.com"),
Expand Down Expand Up @@ -104,6 +105,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
Name: utils.Ptr("example.com"),
Expand All @@ -125,6 +127,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
Name: utils.Ptr(""),
Expand Down Expand Up @@ -305,6 +308,7 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
Name: utils.Ptr("example.com"),
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/dns/record-set/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/dns/record-set/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/dns/record-set/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
NameLike: utils.Ptr("some-pattern"),
Expand Down Expand Up @@ -133,6 +134,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
PageSize: 100, // Default value
Expand Down Expand Up @@ -302,6 +304,7 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
PageSize: 10,
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/dns/record-set/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand Down Expand Up @@ -127,6 +128,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand All @@ -147,6 +149,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand Down Expand Up @@ -317,6 +320,7 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
RecordSetId: testRecordSetId,
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/dns/zone/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"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/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
Expand Down Expand Up @@ -52,7 +53,7 @@ type inputModel struct {
ContactEmail *string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Creates a DNS zone",
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewCmd() *cobra.Command {
if model.Async {
operationState = "Triggered creation of"
}
cmd.Printf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, zoneId)
p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, zoneId)
return nil
},
}
Expand Down
6 changes: 5 additions & 1 deletion internal/cmd/dns/zone/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr("example"),
DnsName: utils.Ptr("example.com"),
Expand Down Expand Up @@ -122,6 +123,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr("example"),
DnsName: utils.Ptr("example.com"),
Expand Down Expand Up @@ -149,6 +151,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr(""),
DnsName: utils.Ptr(""),
Expand Down Expand Up @@ -212,7 +215,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down Expand Up @@ -281,6 +284,7 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
Name: utils.Ptr("example"),
DnsName: utils.Ptr("example.com"),
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/dns/zone/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/dns/zone/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
ZoneId: testZoneId,
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/dns/zone/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
NameLike: utils.Ptr("some-pattern"),
OrderByName: utils.Ptr("asc"),
Expand Down Expand Up @@ -129,6 +130,7 @@ func TestParseInput(t *testing.T) {
expectedModel: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
PageSize: pageSizeDefault,
},
Expand Down Expand Up @@ -297,6 +299,7 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Verbosity: globalflags.VerbosityDefault,
},
PageSize: pageSizeDefault,
},
Expand Down
Loading