Skip to content

Commit

Permalink
chore: address pr feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Helfand <helfand.4@gmail.com>
  • Loading branch information
danielhelfand committed Jul 8, 2022
1 parent f3e16c6 commit 37ae168
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
12 changes: 4 additions & 8 deletions cmd/argocd/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,13 @@ argocd cluster rotate-auth cluster-name`,
}
conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie()
defer io.Close(conn)
clusterQuery := getQueryBySelector(args[0])

cluster := args[0]
clusterQuery := getQueryBySelector(cluster)
_, err := clusterIf.RotateAuth(ctx, clusterQuery)
errors.CheckError(err)

var clstNameOrServer string
if clusterQuery.Name != "" {
clstNameOrServer = clusterQuery.Name
} else {
clstNameOrServer = clusterQuery.Server
}
fmt.Printf("Cluster '%s' rotated auth\n", clstNameOrServer)
fmt.Printf("Cluster '%s' rotated auth\n", cluster)
},
}
return command
Expand Down
7 changes: 4 additions & 3 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"context"

"github.com/argoproj/gitops-engine/pkg/utils/kube"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -303,16 +304,16 @@ func (s *Server) RotateAuth(ctx context.Context, q *cluster.ClusterQuery) (*clus
if q.Name != "" {
servers, err = s.db.GetClusterServersByName(ctx, q.Name)
if err != nil {
return nil, err
return nil, status.Errorf(codes.NotFound, "failed to get cluster servers by name: %v", err)
}
for _, server := range servers {
if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionUpdate, createRBACObject(clust.Project, server)); err != nil {
return nil, err
return nil, status.Errorf(codes.PermissionDenied, "encountered permissions issue while processing request: %v", err)
}
}
} else {
if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionUpdate, createRBACObject(clust.Project, q.Server)); err != nil {
return nil, err
return nil, status.Errorf(codes.PermissionDenied, "encountered permissions issue while processing request: %v", err)
}
servers = append(servers, q.Server)
}
Expand Down
2 changes: 1 addition & 1 deletion server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func TestRotateAuth(t *testing.T) {
assert.EqualError(t, err, `rpc error: code = PermissionDenied desc = permission denied`)
})

// While this tests results for the next two tests result in an error, they do
// While the tests results for the next two tests result in an error, they do
// demonstrate the proper mapping of cluster names/server to server info (i.e. my-cluster-name
// results in https://my-cluster-name info being used and https://my-cluster-name results in https://my-cluster-name).
t.Run("RotateAuth by Name - Error from no such host", func(t *testing.T) {
Expand Down

0 comments on commit 37ae168

Please sign in to comment.