Skip to content

Commit

Permalink
lxc/auth: use errors.New() where appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Sep 5, 2024
1 parent 71381e6 commit 7fe4f50
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lxc/auth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -119,7 +120,7 @@ func (c *cmdGroupCreate) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// Create the group
Expand Down Expand Up @@ -173,7 +174,7 @@ func (c *cmdGroupDelete) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// Delete the group
Expand Down Expand Up @@ -251,7 +252,7 @@ func (c *cmdGroupEdit) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// If stdin isn't a terminal, read text from it
Expand Down Expand Up @@ -413,7 +414,7 @@ func (c *cmdGroupRename) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// Rename the group
Expand Down Expand Up @@ -462,7 +463,7 @@ func (c *cmdGroupShow) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// Show the group
Expand Down Expand Up @@ -537,7 +538,7 @@ func (c *cmdGroupPermissionAdd) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

group, eTag, err := resource.server.GetAuthGroup(resource.name)
Expand Down Expand Up @@ -596,7 +597,7 @@ func (c *cmdGroupPermissionRemove) run(cmd *cobra.Command, args []string) error
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

group, eTag, err := resource.server.GetAuthGroup(resource.name)
Expand Down Expand Up @@ -859,7 +860,7 @@ func (c *cmdIdentityShow) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity argument"))
return errors.New(i18n.G("Missing identity argument"))
}

authenticationMethod, nameOrID, ok := strings.Cut(resource.name, "/")
Expand Down Expand Up @@ -1000,7 +1001,7 @@ func (c *cmdIdentityEdit) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity argument"))
return errors.New(i18n.G("Missing identity argument"))
}

authenticationMethod, nameOrID, ok := strings.Cut(resource.name, "/")
Expand Down Expand Up @@ -1128,7 +1129,7 @@ func (c *cmdIdentityGroupAdd) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity argument"))
return errors.New(i18n.G("Missing identity argument"))
}

authenticationMethod, nameOrID, ok := strings.Cut(resource.name, "/")
Expand Down Expand Up @@ -1186,7 +1187,7 @@ func (c *cmdIdentityGroupRemove) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity argument"))
return errors.New(i18n.G("Missing identity argument"))
}

authenticationMethod, nameOrID, ok := strings.Cut(resource.name, "/")
Expand Down Expand Up @@ -1492,7 +1493,7 @@ func (c *cmdIdentityProviderGroupCreate) run(cmd *cobra.Command, args []string)
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name"))
return errors.New(i18n.G("Missing identity provider group name"))
}

// Create the identity provider group
Expand Down Expand Up @@ -1545,7 +1546,7 @@ func (c *cmdIdentityProviderGroupDelete) run(cmd *cobra.Command, args []string)
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name"))
return errors.New(i18n.G("Missing identity provider group name"))
}

// Delete the identity provider group
Expand Down Expand Up @@ -1611,7 +1612,7 @@ func (c *cmdIdentityProviderGroupEdit) run(cmd *cobra.Command, args []string) er
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name"))
return errors.New(i18n.G("Missing identity provider group name"))
}

// If stdin isn't a terminal, read text from it
Expand Down Expand Up @@ -1773,7 +1774,7 @@ func (c *cmdIdentityProviderGroupRename) run(cmd *cobra.Command, args []string)
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name"))
return errors.New(i18n.G("Missing identity provider group name"))
}

// Rename the group
Expand Down Expand Up @@ -1822,7 +1823,7 @@ func (c *cmdIdentityProviderGroupShow) run(cmd *cobra.Command, args []string) er
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing group name"))
return errors.New(i18n.G("Missing group name"))
}

// Show the group
Expand Down Expand Up @@ -1896,7 +1897,7 @@ func (c *cmdIdentityProviderGroupGroupAdd) run(cmd *cobra.Command, args []string
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name argument"))
return errors.New(i18n.G("Missing identity provider group name argument"))
}

idpGroup, eTag, err := resource.server.GetIdentityProviderGroup(resource.name)
Expand Down Expand Up @@ -1949,7 +1950,7 @@ func (c *cmdIdentityProviderGroupGroupRemove) run(cmd *cobra.Command, args []str
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing identity provider group name argument"))
return errors.New(i18n.G("Missing identity provider group name argument"))
}

idpGroup, eTag, err := resource.server.GetIdentityProviderGroup(resource.name)
Expand Down

0 comments on commit 7fe4f50

Please sign in to comment.