Skip to content

Commit

Permalink
chore: remove cla
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed Jul 5, 2024
2 parents 9525d3c + ccbca19 commit 9305228
Show file tree
Hide file tree
Showing 17 changed files with 717 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ changelog:
- title: "Documentation Updates"
regexp: ^.*?docs(\([[:word:]]+\))??!?:.+$
order: 50
- title: "Tests"
regexp: ^.*?tests(\([[:word:]]+\))??!?:.+$
order: 60
- title: Other Work
order: 999
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -84,14 +83,11 @@ require (
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
14 changes: 0 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand All @@ -147,7 +143,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down Expand Up @@ -400,8 +395,6 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI=
golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -470,7 +463,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
Expand Down Expand Up @@ -549,8 +541,6 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down Expand Up @@ -602,10 +592,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/delete/edge_application/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/aziontech/azion-cli/pkg/output"
)

func (del *DeleteCmd) Cascade(ctx context.Context) error {
func CascadeDelete(ctx context.Context, del *DeleteCmd) error {
azionJson, err := del.GetAzion(ProjectConf)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return msg.ErrorMissingAzionJson
} else {
return err //message with error
return err
}
}
if azionJson.Application.ID == 0 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/delete/edge_application/edge_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DeleteCmd struct {
GetAzion func(confPath string) (*contracts.AzionApplicationOptions, error)
f *cmdutil.Factory
UpdateJson func(cmd *DeleteCmd) error
Cascade func(ctx context.Context, del *DeleteCmd) error
}

func NewCmd(f *cmdutil.Factory) *cobra.Command {
Expand All @@ -40,6 +41,7 @@ func NewDeleteCmd(f *cmdutil.Factory) *DeleteCmd {
GetAzion: utils.GetAzionJsonContent,
f: f,
UpdateJson: updateAzionJson,
Cascade: CascadeDelete,
}
}

Expand Down Expand Up @@ -72,7 +74,7 @@ func (del *DeleteCmd) run(cmd *cobra.Command, application_id int64) error {
ctx := context.Background()

if cmd.Flags().Changed("cascade") {
err := del.Cascade(ctx)
err := del.Cascade(ctx, del)
if err != nil {
return err
}
Expand Down
91 changes: 59 additions & 32 deletions pkg/cmd/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,77 @@ import (
msg "github.com/aziontech/azion-cli/messages/logout"
api "github.com/aziontech/azion-cli/pkg/api/personal_token"
"github.com/aziontech/azion-cli/pkg/cmdutil"
"github.com/aziontech/azion-cli/pkg/iostreams"
"github.com/aziontech/azion-cli/pkg/output"
"github.com/aziontech/azion-cli/pkg/token"
"github.com/spf13/cobra"
)

func NewCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
type LogoutCmd struct {
Io *iostreams.IOStreams
ReadSettings func() (token.Settings, error)
WriteSettings func(token.Settings) error
DeleteToken func(context.Context, string) error
}

func NewLogoutCmd(f *cmdutil.Factory) *LogoutCmd {
return &LogoutCmd{
Io: f.IOStreams,
ReadSettings: token.ReadSettings,
WriteSettings: token.WriteSettings,
DeleteToken: func(ctx context.Context, uuid string) error {
client := api.NewClient(f.HttpClient, f.Config.GetString("api_url"), f.Config.GetString("token"))
return client.Delete(ctx, uuid)
},
}
}

func NewCobraCmd(logout *LogoutCmd, f *cmdutil.Factory) *cobra.Command {
cobraCmd := &cobra.Command{
Use: msg.USAGE,
Short: msg.SHORTDESCRIPTION,
Long: msg.LONGDESCRIPTION,
Example: heredoc.Doc(`
$ azion logout --help
`),
`),
RunE: func(cmd *cobra.Command, args []string) error {
settings, err := token.ReadSettings()
if err != nil {
return err
}

if settings.UUID != "" {
client := api.NewClient(f.HttpClient, f.Config.GetString("api_url"), f.Config.GetString("token"))
err = client.Delete(context.Background(), settings.UUID)
if err != nil {
return fmt.Errorf(msg.ErrorLogout, err.Error())
}
}

settings.UUID = ""
settings.Token = ""
err = token.WriteSettings(settings)
if err != nil {
return err
}

logoutOut := output.GeneralOutput{
Msg: msg.SUCCESS,
Out: f.IOStreams.Out,
}

return output.Print(&logoutOut)
return logout.run()
},
}

flags := cmd.Flags()
flags.BoolP("help", "h", false, msg.FLAGHELP)
return cmd
cobraCmd.Flags().BoolP("help", "h", false, msg.FLAGHELP)

return cobraCmd
}

func NewCmd(f *cmdutil.Factory) *cobra.Command {
return NewCobraCmd(NewLogoutCmd(f), f)
}

func (cmd *LogoutCmd) run() error {
settings, err := cmd.ReadSettings()
if err != nil {
return err
}

if settings.UUID != "" {
err = cmd.DeleteToken(context.Background(), settings.UUID)
if err != nil {
return fmt.Errorf(msg.ErrorLogout, err.Error())
}
}

settings.UUID = ""
settings.Token = ""
err = cmd.WriteSettings(settings)
if err != nil {
return err
}

logoutOut := output.GeneralOutput{
Msg: msg.SUCCESS,
Out: cmd.Io.Out,
}

return output.Print(&logoutOut)
}
122 changes: 122 additions & 0 deletions pkg/cmd/logout/logout_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package logout

import (
"context"
"errors"
"fmt"
"testing"

msg "github.com/aziontech/azion-cli/messages/logout"
"github.com/aziontech/azion-cli/pkg/httpmock"
"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/pkg/testutils"
"github.com/aziontech/azion-cli/pkg/token"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
)

func TestLogout(t *testing.T) {
logger.New(zapcore.DebugLevel)

tests := []struct {
name string
tokenSettings token.Settings
mockReadError error
mockDeleteError error
mockWriteError error
expectedOutput string
expectedError error
}{
{
name: "logout - successful logout",
tokenSettings: token.Settings{
UUID: "1234-5678",
},
mockReadError: nil,
mockDeleteError: nil,
mockWriteError: nil,
expectedOutput: msg.SUCCESS,
expectedError: nil,
},
{
name: "logout - no UUID",
tokenSettings: token.Settings{
UUID: "",
},
mockReadError: nil,
mockDeleteError: nil,
mockWriteError: nil,
expectedOutput: msg.SUCCESS,
expectedError: nil,
},
{
name: "logout - failed to read settings",
tokenSettings: token.Settings{},
mockReadError: errors.New("failed to get token dir"),
mockDeleteError: nil,
mockWriteError: nil,
expectedOutput: "",
expectedError: errors.New("failed to get token dir"),
},
{
name: "logout - failed to delete token",
tokenSettings: token.Settings{
UUID: "1234-5678",
},
mockReadError: nil,
mockDeleteError: errors.New("failed to delete token"),
mockWriteError: nil,
expectedOutput: "",
expectedError: fmt.Errorf(msg.ErrorLogout, "failed to delete token"),
},
{
name: "logout - failed to write settings",
tokenSettings: token.Settings{
UUID: "1234-5678",
},
mockReadError: nil,
mockDeleteError: nil,
mockWriteError: errors.New("Failed to write settings.toml file"),
expectedOutput: "",
expectedError: errors.New("Failed to write settings.toml file"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockReadSettings := func() (token.Settings, error) {
return tt.tokenSettings, tt.mockReadError
}

mockWriteSettings := func(settings token.Settings) error {
return tt.mockWriteError
}

mockDeleteToken := func(ctx context.Context, uuid string) error {
return tt.mockDeleteError
}

mock := &httpmock.Registry{}

f, out, _ := testutils.NewFactory(mock)

logoutCmd := &LogoutCmd{
Io: f.IOStreams,
ReadSettings: mockReadSettings,
WriteSettings: mockWriteSettings,
DeleteToken: mockDeleteToken,
}
cmd := NewCobraCmd(logoutCmd, f)

_, err := cmd.ExecuteC()
if tt.expectedError != nil {
require.Error(t, err)
assert.Equal(t, tt.expectedError.Error(), err.Error())
} else {
require.NoError(t, err)
assert.Equal(t, tt.expectedOutput, out.String())
}
})
}
}
Loading

0 comments on commit 9305228

Please sign in to comment.