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
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BINARY=taikun
GOLANGCI_LINTERS_VERSION := v2.11.4
GOLANGCI_LINTERS_VERSION := v2.12.2

default: install

Expand All @@ -12,7 +12,7 @@ goreleaser-install: ## Installs goreleaser binary with go install
go install github.com/goreleaser/goreleaser/v2@latest

go-linters-install: ## Installs Golang's linters locally for verification
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin ${GOLANGCI_LINTERS_VERSION}
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(shell go env GOPATH)/bin ${GOLANGCI_LINTERS_VERSION}

.PHONY: build
build: go-vendor ## Builds taikun-cli binary
Expand Down
11 changes: 6 additions & 5 deletions cmd/accessprofile/add/add.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package add

import (
"context"

"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
"github.com/itera-io/taikun-cli/utils/out/field"
Expand Down Expand Up @@ -56,7 +54,7 @@ func NewCmdAdd() *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.Name = args[0]
return addRun(&opts)
return addRun(cmd, &opts)
},
}

Expand All @@ -71,7 +69,10 @@ func NewCmdAdd() *cobra.Command {
return cmd
}

func addRun(opts *AddOptions) error {
func addRun(cmd *cobra.Command, opts *AddOptions) error {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

orgID, err := cmdutils.ResolveOrgID(opts.OrganizationID, cmdutils.IsRobotAuth())
if err != nil {
return err
Expand Down Expand Up @@ -112,7 +113,7 @@ func addRun(opts *AddOptions) error {
}

// Execute a query into the API + graceful exit
data, response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesCreate(context.TODO()).CreateAccessProfileCommand(body).Execute()
data, response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesCreate(ctx).CreateAccessProfileCommand(body).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/accessprofile/allowedhost/add/add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package add

import (
"context"
"fmt"
"github.com/itera-io/taikun-cli/utils/out"
tk "github.com/itera-io/taikungoclient"
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewCmdAdd() *cobra.Command {
return fmt.Errorf("mask bits must be in the range of [0, 32]")
}

return addRun(&opts)
return addRun(cmd, &opts)
},
}

Expand All @@ -78,7 +77,10 @@ func NewCmdAdd() *cobra.Command {
return cmd
}

func addRun(opts *AddOptions) (err error) {
func addRun(cmd *cobra.Command, opts *AddOptions) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

Expand All @@ -91,7 +93,7 @@ func addRun(opts *AddOptions) (err error) {
}

// Execute a query into the API + graceful exit
data, response, err := myApiClient.Client.AllowedHostAPI.AllowedhostCreate(context.TODO()).CreateAllowedHostCommand(body).Execute()
data, response, err := myApiClient.Client.AllowedHostAPI.AllowedhostCreate(ctx).CreateAllowedHostCommand(body).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/accessprofile/allowedhost/list/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package list

import (
"context"
"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
Expand Down Expand Up @@ -50,7 +49,7 @@ func NewCmdList() *cobra.Command {
return cmderr.ErrIDArgumentNotANumber
}
opts.AccessProfileID = accessProfileID
return listRun(&opts)
return listRun(cmd, &opts)
},
Aliases: cmdutils.ListAliases,
}
Expand All @@ -61,9 +60,12 @@ func NewCmdList() *cobra.Command {
return cmd
}

func listRun(opts *ListOptions) (err error) {
func listRun(cmd *cobra.Command, opts *ListOptions) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

myApiClient := tk.NewClient()
myRequest := myApiClient.Client.AllowedHostAPI.AllowedhostList(context.TODO(), opts.AccessProfileID)
myRequest := myApiClient.Client.AllowedHostAPI.AllowedhostList(ctx, opts.AccessProfileID)

var allowedHosts []interface{}
for {
Expand Down
21 changes: 12 additions & 9 deletions cmd/accessprofile/allowedhost/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@ package remove

import (
"context"
"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
"github.com/itera-io/taikun-cli/utils/types"
tk "github.com/itera-io/taikungoclient"
"github.com/spf13/cobra"
)

func NewCmdDelete() *cobra.Command {
var id int32
cmd := &cobra.Command{
Use: "delete <allowed-host-id>...",
Short: "Delete an allowed host",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
id, err = types.Atoi32(args[0])
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()
ids, err := cmdutils.ArgsToNumericalIDs(args)
if err != nil {
return
return cmderr.ErrIDArgumentNotANumber
}
return deleteRun(id)
return cmdutils.DeleteMultiple(ids, func(id int32) error {
return deleteRun(ctx, id)
})
},
Aliases: cmdutils.DeleteAliases,
}

return cmd
}

func deleteRun(allowedHostID int32) (err error) {
func deleteRun(ctx context.Context, allowedHostID int32) (err error) {
// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

// Execute a query into the API + graceful exit
response, err := myApiClient.Client.AllowedHostAPI.AllowedhostDelete(context.TODO(), allowedHostID).Execute()
response, err := myApiClient.Client.AllowedHostAPI.AllowedhostDelete(ctx, allowedHostID).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/accessprofile/list/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package list

import (
"context"
"github.com/itera-io/taikun-cli/api"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/config"
Expand Down Expand Up @@ -57,7 +56,7 @@ func NewCmdList() *cobra.Command {
Use: "list",
Short: "List access profiles",
RunE: func(cmd *cobra.Command, args []string) error {
return listRun(&opts)
return listRun(cmd, &opts)
},
Args: cobra.NoArgs,
Aliases: cmdutils.ListAliases,
Expand All @@ -72,7 +71,10 @@ func NewCmdList() *cobra.Command {
return cmd
}

func listRun(opts *ListOptions) (err error) {
func listRun(cmd *cobra.Command, opts *ListOptions) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

orgID, err := cmdutils.ResolveOrgID(opts.OrganizationID, cmdutils.IsRobotAuth())
if err != nil {
return err
Expand All @@ -83,7 +85,7 @@ func listRun(opts *ListOptions) (err error) {
myApiClient := tk.NewClient()

// Prepare the arguments for the query
myRequest := myApiClient.Client.AccessProfilesAPI.AccessprofilesList(context.TODO())
myRequest := myApiClient.Client.AccessProfilesAPI.AccessprofilesList(ctx)
if opts.OrganizationID != 0 {
myRequest = myRequest.OrganizationId(opts.OrganizationID)
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/accessprofile/lock/lock.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package lock

import (
"context"
"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/utils/out"
"github.com/itera-io/taikun-cli/utils/types"
tk "github.com/itera-io/taikungoclient"
taikuncore "github.com/itera-io/taikungoclient/client"
"github.com/spf13/cobra"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
)

func NewCmdLock() *cobra.Command {
Expand All @@ -20,20 +20,23 @@ func NewCmdLock() *cobra.Command {
if err != nil {
return cmderr.ErrIDArgumentNotANumber
}
return lockRun(id)
return lockRun(cmd, id)
},
}

return cmd
}

func lockRun(accessProfileID int32) (err error) {
func lockRun(cmd *cobra.Command, accessProfileID int32) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

myApiClient := tk.NewClient()
body := taikuncore.AccessProfilesLockManagementCommand{
Id: &accessProfileID,
Mode: *taikuncore.NewNullableString(&types.LockedMode),
}
response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesLockManager(context.TODO()).AccessProfilesLockManagementCommand(body).Execute()
response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesLockManager(ctx).AccessProfilesLockManagementCommand(body).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/accessprofile/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package remove

import (
"context"

"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
Expand All @@ -15,25 +16,28 @@ func NewCmdDelete() *cobra.Command {
Short: "Delete one or more access profiles",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()
ids, err := cmdutils.ArgsToNumericalIDs(args)
if err != nil {
return cmderr.ErrIDArgumentNotANumber
}
return cmdutils.DeleteMultiple(ids, deleteRun)
return cmdutils.DeleteMultiple(ids, func(id int32) error {
return deleteRun(ctx, id)
})
},
Aliases: cmdutils.DeleteAliases,
}

return cmd
}

func deleteRun(accessProfileID int32) (err error) {
func deleteRun(ctx context.Context, accessProfileID int32) (err error) {
myApiClient := tk.NewClient()
response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesDelete(context.TODO(), accessProfileID).Execute()
response, err := myApiClient.Client.AccessProfilesAPI.AccessprofilesDelete(ctx, accessProfileID).Execute()
if err != nil {
return tk.CreateError(response, err)
}
out.PrintDeleteSuccess("Access profile", accessProfileID)
return

}
19 changes: 12 additions & 7 deletions cmd/accessprofile/sshuser/add/add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package add

import (
"context"
"fmt"
"github.com/itera-io/taikun-cli/utils/out"
tk "github.com/itera-io/taikungoclient"
Expand Down Expand Up @@ -47,15 +46,15 @@ func NewCmdAdd() *cobra.Command {
return
}

isValid, err := sshPublicKeyIsValid(opts.PublicKey)
isValid, err := sshPublicKeyIsValid(cmd, opts.PublicKey)
if err != nil {
return
}
if !isValid {
return fmt.Errorf("SSH public key must be valid")
}

return addRun(&opts)
return addRun(cmd, &opts)
},
}

Expand All @@ -71,7 +70,10 @@ func NewCmdAdd() *cobra.Command {
return cmd
}

func sshPublicKeyIsValid(sshPublicKey string) (bool, error) {
func sshPublicKeyIsValid(cmd *cobra.Command, sshPublicKey string) (bool, error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

Expand All @@ -81,15 +83,18 @@ func sshPublicKeyIsValid(sshPublicKey string) (bool, error) {
}

// Execute a query into the API + graceful exit
response, err := myApiClient.Client.CheckerAPI.CheckerSsh(context.TODO()).SshKeyCommand(body).Execute()
response, err := myApiClient.Client.CheckerAPI.CheckerSsh(ctx).SshKeyCommand(body).Execute()
if err != nil {
return false, tk.CreateError(response, err)
}
return true, nil

}

func addRun(opts *AddOptions) (err error) {
func addRun(cmd *cobra.Command, opts *AddOptions) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

Expand All @@ -101,7 +106,7 @@ func addRun(opts *AddOptions) (err error) {
}

// Execute a query into the API + graceful exit
data, response, err := myApiClient.Client.SshUsersAPI.SshusersCreate(context.TODO()).CreateSshUserCommand(body).Execute()
data, response, err := myApiClient.Client.SshUsersAPI.SshusersCreate(ctx).CreateSshUserCommand(body).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/accessprofile/sshuser/list/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package list

import (
"context"
"github.com/itera-io/taikun-cli/cmd/cmderr"
"github.com/itera-io/taikun-cli/cmd/cmdutils"
"github.com/itera-io/taikun-cli/utils/out"
Expand Down Expand Up @@ -47,7 +46,7 @@ func NewCmdList() *cobra.Command {
return cmderr.ErrIDArgumentNotANumber
}
opts.AccessProfileID = accessProfileID
return listRun(&opts)
return listRun(cmd, &opts)
},
Aliases: cmdutils.ListAliases,
}
Expand All @@ -58,12 +57,15 @@ func NewCmdList() *cobra.Command {
return cmd
}

func listRun(opts *ListOptions) (err error) {
func listRun(cmd *cobra.Command, opts *ListOptions) (err error) {
ctx, cancel := cmdutils.APIContext(cmd)
defer cancel()

// Create and authenticated client to the Taikun API
myApiClient := tk.NewClient()

// Execute a query into the API + graceful exit
data, response, err := myApiClient.Client.SshUsersAPI.SshusersList(context.TODO(), opts.AccessProfileID).Execute()
data, response, err := myApiClient.Client.SshUsersAPI.SshusersList(ctx, opts.AccessProfileID).Execute()
if err != nil {
return tk.CreateError(response, err)
}
Expand Down
Loading