Skip to content

Commit

Permalink
fix: changed field origin-id to origin-key
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed Feb 13, 2023
1 parent 4c2bf7a commit e68fabf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion messages/origins/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
OriginsUpdateUsage = "update [flags]"
OriginsUpdateShortDescription = "Modifies an Origin"
OriginsUpdateLongDescription = "Modifies an Origin based on its ID to update its name, activity status, and other attributes"
OriginsUpdateFlagOriginID = "The Origins unique identifier"
OriginsUpdateFlagOriginKey = "The Origins unique identifier"
OriginsUpdateFlagEdgeApplicationId = "The Edge Application's unique identifier"
OriginsUpdateFlagName = "The Origin name"
OriginsUpdateFlagOriginType = "Origin Type is a field used to identify the source of a record. It is typically used to differentiate between records that were created manually or automatically. For example, a record may have an Origin Type of 'Manual' if it was created by a user, or 'Automatic' if it was created by a system. Origin Type can also be used to differentiate between records that were imported from an external source, such as a CSV file, or created within the system."
Expand Down
1 change: 1 addition & 0 deletions pkg/api/edge_applications/edge_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func (c *Client) CreateOrigins(ctx context.Context, edgeApplicationID int64, req
}
return &resp.Results, nil
}

func (c *Client) UpdateOrigins(ctx context.Context, edgeApplicationID int64, originKey string, req *UpdateOriginsRequest) (OriginsResponse, error) {
resp, httpResp, err := c.apiClient.EdgeApplicationsOriginsApi.
EdgeApplicationsEdgeApplicationIdOriginsOriginKeyPut(ctx, edgeApplicationID, originKey).UpdateOriginsRequest(req.UpdateOriginsRequest).Execute()
Expand Down
32 changes: 15 additions & 17 deletions pkg/cmd/origins/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

type Fields struct {
OriginID string
OriginKey string
ApplicationID int64
Name string
OriginType string
Expand All @@ -43,9 +43,9 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
SilenceUsage: true,
SilenceErrors: true,
Example: heredoc.Doc(`
$ azioncli origins update --application-id 1673635839 --name "ffcafe222sdsdffdf" --addresses "httpbin.org" --host-header "asdf.safe" --origin-type "single_origin" --origin-protocol-policy "http" --origin-path "/requests" --hmac-authentication "false"
$ azioncli origins update --application-id 1673635839 --name "drink coffe" --addresses "asdfg.asd" --host-header "host"
$ azioncli origins update --application-id 1673635839 --in "update.json"
$ azioncli origins update --application-id 1673635839 --origin-key "58755fef-e830-4ea4-b9e0-6481f1ef496d" --name "ffcafe222sdsdffdf" --addresses "httpbin.org" --host-header "asdf.safe" --origin-type "single_origin" --origin-protocol-policy "http" --origin-path "/requests" --hmac-authentication "false"
$ azioncli origins update --application-id 1673635839 --origin-key "58755fef-e830-4ea4-b9e0-6481f1ef496d" --name "drink coffe" --addresses "asdfg.asd" --host-header "host"
$ azioncli origins update --application-id 1673635839 --origin-key "58755fef-e830-4ea4-b9e0-6481f1ef496d" --in "update.json"
`),
RunE: func(cmd *cobra.Command, args []string) error {
request := api.UpdateOriginsRequest{}
Expand All @@ -67,18 +67,16 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
return utils.ErrorUnmarshalReader
}
} else {
if !cmd.Flags().Changed("application-id") || !cmd.Flags().Changed("origin-id") {

if !cmd.Flags().Changed("application-id") || !cmd.Flags().Changed("origin-key") ||
!cmd.Flags().Changed("name") || !cmd.Flags().Changed("addresses") || !cmd.Flags().Changed("host-header") { // flags requireds
return msg.ErrorMandatoryUpdateFlags
}
if cmd.Flags().Changed("name") {
request.SetName(fields.Name)
}
if cmd.Flags().Changed("addresses") {
request.SetAddresses(prepareAddresses(fields.Addresses))
}
if cmd.Flags().Changed("host-header") {
request.SetHostHeader(fields.HostHeader)
}

request.SetName(fields.Name)
request.SetAddresses(prepareAddresses(fields.Addresses))
request.SetHostHeader(fields.HostHeader)

if cmd.Flags().Changed("origin-type") {
request.SetOriginType(fields.OriginType)
}
Expand Down Expand Up @@ -107,17 +105,17 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
}

client := api.NewClient(f.HttpClient, f.Config.GetString("api_url"), f.Config.GetString("token"))
response, err := client.UpdateOrigins(context.Background(), fields.ApplicationID, fields.OriginID, &request)
response, err := client.UpdateOrigins(context.Background(), fields.ApplicationID, fields.OriginKey, &request)
if err != nil {
return fmt.Errorf(msg.ErrorUpdateOrigin.Error(), err)
}
fmt.Fprintf(f.IOStreams.Out, msg.OriginsCreateOutputSuccess, response.GetOriginId())
fmt.Fprintf(f.IOStreams.Out, msg.OriginsUpdateOutputSuccess, response.GetOriginId())
return nil
},
}

flags := cmd.Flags()
flags.StringVarP(&fields.OriginID, "origin-id", "o", "", msg.OriginsUpdateFlagOriginID)
flags.StringVarP(&fields.OriginKey, "origin-key", "o", "", msg.OriginsUpdateFlagOriginKey)
flags.Int64VarP(&fields.ApplicationID, "application-id", "a", 0, msg.OriginsCreateFlagEdgeApplicationId)
flags.StringVar(&fields.Name, "name", "", msg.OriginsCreateFlagName)
flags.StringVar(&fields.OriginType, "origin-type", "", msg.OriginsCreateFlagOriginType)
Expand Down

0 comments on commit e68fabf

Please sign in to comment.