-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat-origins-updated
- Loading branch information
Showing
15 changed files
with
145 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
API_URL=https://${AZION_API} | ||
AUTH_URL=https://${AZION_SSO}/api/user/me | ||
STORAGE_URL=https://${STORAGE_API} | ||
TEMPLATE_BRANCH=dev | ||
TEMPLATE_MAJOR=0 | ||
STORAGE_URL=${STORAGE_API} | ||
TEMPLATE_MAJOR=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package delete | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
msg "github.com/aziontech/azion-cli/messages/origins" | ||
api "github.com/aziontech/azion-cli/pkg/api/edge_applications" | ||
"github.com/spf13/cobra" | ||
"github.com/aziontech/azion-cli/pkg/cmdutil" | ||
) | ||
|
||
|
||
|
||
func NewCmd(f *cmdutil.Factory) *cobra.Command { | ||
var applicationID int64 | ||
var originKey string | ||
cmd := &cobra.Command{ | ||
Use: msg.OriginsDeleteUsage, | ||
Short: msg.OriginsDeleteShortDescription, | ||
Long: msg.OriginsDeleteLongDescription, | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
Example: heredoc.Doc(` | ||
$ azioncli origins delete --application-id 1234 --origin-key 03a6e7bf-8e26-49c7-a66e-ab8eaa425086 | ||
$ azioncli origins delete -a 1234 -o 03a6e7bf-8e26-49c7-a66e-ab8eaa425086 | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if !cmd.Flags().Changed("application-id") || !cmd.Flags().Changed("origin-key") { | ||
return msg.ErrorMissingArgumentsDelete | ||
} | ||
if err := api.NewClient(f.HttpClient, f.Config.GetString("api_url"), f.Config.GetString("token")). | ||
DeleteOrigins(context.Background(), applicationID, originKey); err != nil { | ||
return fmt.Errorf(msg.ErrorFailToDelete.Error(), err) | ||
} | ||
fmt.Fprintf(f.IOStreams.Out, msg.OriginsDeleteOutputSuccess, originKey) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().Int64VarP(&applicationID, "application-id", "a", 0, msg.OriginsDeleteFlagApplicationID) | ||
cmd.Flags().StringVarP(&originKey, "origin-key", "o", "", msg.OriginsDeleteFlagOriginKey) | ||
cmd.Flags().BoolP("help", "h", false, msg.OriginsDeleteHelpFlag) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package delete | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aziontech/azion-cli/pkg/httpmock" | ||
"github.com/aziontech/azion-cli/pkg/testutils" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
msg "github.com/aziontech/azion-cli/messages/origins" | ||
) | ||
|
||
func TestCreate(t *testing.T) { | ||
|
||
t.Run("delete domain by id", func(t *testing.T) { | ||
mock := &httpmock.Registry{} | ||
|
||
mock.Register( | ||
httpmock.REST("DELETE", "edge_applications/1673635839/origins/58755fef-e830-4ea4-b9e0-6481f1ef496d"), | ||
httpmock.StatusStringResponse(204, ""), | ||
) | ||
|
||
f, stdout, _ := testutils.NewFactory(mock) | ||
cmd := NewCmd(f) | ||
cmd.SetArgs([]string{"--application-id", "1673635839", "--origin-key", "58755fef-e830-4ea4-b9e0-6481f1ef496d"}) | ||
|
||
_, err := cmd.ExecuteC() | ||
require.NoError(t, err) | ||
assert.Equal(t, fmt.Sprintf(msg.OriginsDeleteOutputSuccess, "58755fef-e830-4ea4-b9e0-6481f1ef496d"), stdout.String()) | ||
}) | ||
|
||
t.Run("delete domain that is not found", func(t *testing.T) { | ||
mock := &httpmock.Registry{} | ||
|
||
mock.Register( | ||
httpmock.REST("DELETE", "edge_applications/1673635839/origins/58755fef-e830-4ea4-b9e0-6481f1ef497a"), | ||
httpmock.StatusStringResponse(404, "Not Found"), | ||
) | ||
|
||
f, _, _ := testutils.NewFactory(mock) | ||
cmd := NewCmd(f) | ||
cmd.SetArgs([]string{"-d", "1234"}) | ||
|
||
_, err := cmd.ExecuteC() | ||
require.Error(t, err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters