Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute instance: implement reset-password command #535

Closed
wants to merge 2 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
73 changes: 73 additions & 0 deletions cmd/instance_reset_password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cmd

import (
"context"
"fmt"

"github.com/google/uuid"
"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/client"
"github.com/exoscale/cli/pkg/instance"
"github.com/exoscale/egoscale/v3/oapi"
)

type instanceResetPasswordCmd struct {
cliCommandSettings `cli-cmd:"-"`

_ bool `cli-cmd:"reset-password"`

Instance string `cli-arg:"#" cli-usage:"NAME|ID"`

Zone string `cli-short:"z" cli-usage:"instance zone"`
}

func (c *instanceResetPasswordCmd) cmdAliases() []string { return gRemoveAlias }

func (c *instanceResetPasswordCmd) cmdShort() string {
return "Reset the password of a Compute instance"
}

func (c *instanceResetPasswordCmd) cmdLong() string { return "" }

func (c *instanceResetPasswordCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}

func (c *instanceResetPasswordCmd) cmdRun(_ *cobra.Command, _ []string) error {
var (
err error
ctx = context.Background()
)

v3Client, err := client.Get()
if err != nil {
return err
}

v3Client.SetZone(oapi.ZoneName(c.Zone))

instanceUUID, err := uuid.Parse(c.Instance)
if err != nil {
instance, err := instance.FindInstanceByName(ctx, &v3Client.Client, c.Instance)
if err != nil {
return err
}

if instance == nil {
return fmt.Errorf("unable to find instance by name %q", c.Instance)
}

instanceUUID = *instance.Id
}

_, err = v3Client.Compute().Instance().ResetPassword(ctx, instanceUUID)
return err
}

func init() {
cobra.CheckErr(registerCLICommand(instanceCmd, &instanceResetPasswordCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}
58 changes: 44 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module github.com/exoscale/cli

replace gopkg.ini/ini.v1 => github.com/go-ini/ini v1.42.0
replace (
github.com/exoscale/egoscale/v3 => github.com/exoscale/egoscale/v3 v3.0.0-20230830163612-a8c92b4e9a83
gopkg.ini/ini.v1 => github.com/go-ini/ini v1.42.0
)

require (
github.com/aws/aws-sdk-go-v2 v1.2.0
Expand All @@ -11,10 +14,12 @@ require (
github.com/aws/smithy-go v1.1.0
github.com/dustin/go-humanize v1.0.0
github.com/exoscale/egoscale v0.100.3
github.com/exoscale/egoscale/v3 v3.0.0-00010101000000-000000000000
github.com/exoscale/openapi-cli-generator v1.1.0
github.com/fatih/camelcase v1.0.0
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.0
github.com/iancoleman/strcase v0.2.0
github.com/iancoleman/strcase v0.3.0
github.com/izumin5210/gentleman-logger v1.0.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/manifoldco/promptui v0.3.2
Expand All @@ -25,13 +30,13 @@ require (
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.3
github.com/vbauerster/mpb/v4 v4.12.2
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/crypto v0.1.0
golang.org/x/term v0.5.0
golang.org/x/text v0.7.0
golang.org/x/crypto v0.9.0
golang.org/x/term v0.8.0
golang.org/x/text v0.9.0
gopkg.in/h2non/gentleman.v2 v2.0.4
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -42,55 +47,80 @@ require (
github.com/alecthomas/chroma v0.7.3 // indirect
github.com/alecthomas/gometalinter v2.0.11+incompatible // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/client9/misspell v0.3.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/danielgtaylor/go-jmespath-plus v0.0.0-20200228063638-e0b6f132acba // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deepmap/oapi-codegen v1.9.1 // indirect
github.com/deepmap/oapi-codegen v1.13.0 // indirect
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 // indirect
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/izumin5210/httplogger v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nicksnyder/go-i18n v1.10.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/tools v0.9.2 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading