github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/commands/serviceauth/update.go (about) 1 package serviceauth 2 3 import ( 4 "io" 5 6 "github.com/fastly/go-fastly/v9/fastly" 7 8 "github.com/fastly/cli/pkg/argparser" 9 "github.com/fastly/cli/pkg/global" 10 "github.com/fastly/cli/pkg/text" 11 ) 12 13 // UpdateCommand calls the Fastly API to update service authorizations. 14 type UpdateCommand struct { 15 argparser.Base 16 17 input fastly.UpdateServiceAuthorizationInput 18 } 19 20 // NewUpdateCommand returns a usable command registered under the parent. 21 func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateCommand { 22 c := UpdateCommand{ 23 Base: argparser.Base{ 24 Globals: g, 25 }, 26 } 27 c.CmdClause = parent.Command("update", "Update service authorization") 28 29 // Required. 30 c.CmdClause.Flag("id", "ID of the service authorization to delete").Required().StringVar(&c.input.ID) 31 c.CmdClause.Flag("permission", "The permission the user has in relation to the service").Required().HintOptions(Permissions...).Short('p').EnumVar(&c.input.Permission, Permissions...) 32 return &c 33 } 34 35 // Exec invokes the application logic for the command. 36 func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { 37 s, err := c.Globals.APIClient.UpdateServiceAuthorization(&c.input) 38 if err != nil { 39 c.Globals.ErrLog.AddWithContext(err, map[string]any{ 40 "Service Authorization ID": c.input.ID, 41 }) 42 return err 43 } 44 45 text.Success(out, "Updated service authorization %s", s.ID) 46 return nil 47 }