@@ -3,12 +3,10 @@ package cmd
33import (
44 "bufio"
55 "bytes"
6- "context"
76 "crypto/x509"
87 "encoding/pem"
98 "fmt"
109 "io"
11- "io/ioutil"
1210 "math/rand"
1311 "net/url"
1412 "os"
@@ -22,7 +20,6 @@ import (
2220 "time"
2321 "unicode"
2422
25- "github.com/docker/docker/pkg/namesgenerator"
2623 "github.com/ghodss/yaml"
2724 "github.com/pkg/errors"
2825 "github.com/rancher/cli/cliclient"
@@ -33,6 +30,8 @@ import (
3330 managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3"
3431 "github.com/sirupsen/logrus"
3532 "github.com/urfave/cli"
33+ "golang.org/x/text/cases"
34+ "golang.org/x/text/language"
3635 "k8s.io/client-go/tools/clientcmd/api"
3736)
3837
@@ -43,7 +42,6 @@ const (
4342)
4443
4544var (
46- errNoURL = errors .New ("RANCHER_URL environment or --Url is not set, run `login`" )
4745 // ManagementResourceTypes lists the types we use the management client for
4846 ManagementResourceTypes = []string {"cluster" , "node" , "project" }
4947 // ProjectResourceTypes lists the types we use the cluster client for
@@ -151,7 +149,7 @@ func getKubeConfigForUser(ctx *cli.Context, user string) (*api.Config, error) {
151149 }
152150
153151 focusedServer := cf .FocusedServer ()
154- kubeConfig , _ := focusedServer .KubeConfigs [fmt .Sprintf (kubeConfigKeyFormat , user , focusedServer .FocusedCluster ())]
152+ kubeConfig := focusedServer .KubeConfigs [fmt .Sprintf (kubeConfigKeyFormat , user , focusedServer .FocusedCluster ())]
155153 return kubeConfig , nil
156154}
157155
@@ -230,7 +228,7 @@ func getRancherServerVersion(c *cliclient.MasterClient) (string, error) {
230228}
231229
232230func loadAndVerifyCert (path string ) (string , error ) {
233- caCert , err := ioutil .ReadFile (path )
231+ caCert , err := os .ReadFile (path )
234232 if err != nil {
235233 return "" , err
236234 }
@@ -301,21 +299,21 @@ func GetClient(ctx *cli.Context) (*cliclient.MasterClient, error) {
301299func GetResourceType (c * cliclient.MasterClient , resource string ) (string , error ) {
302300 if c .ManagementClient != nil {
303301 for key := range c .ManagementClient .APIBaseClient .Types {
304- if strings .ToLower (key ) == strings . ToLower ( resource ) {
302+ if strings .EqualFold (key , resource ) {
305303 return key , nil
306304 }
307305 }
308306 }
309307 if c .ProjectClient != nil {
310308 for key := range c .ProjectClient .APIBaseClient .Types {
311- if strings .ToLower (key ) == strings . ToLower ( resource ) {
309+ if strings .EqualFold (key , resource ) {
312310 return key , nil
313311 }
314312 }
315313 }
316314 if c .ClusterClient != nil {
317315 for key := range c .ClusterClient .APIBaseClient .Types {
318- if strings .ToLower (key ) == strings . ToLower ( resource ) {
316+ if strings .EqualFold (key , resource ) {
319317 return key , nil
320318 }
321319 }
@@ -417,13 +415,8 @@ func Lookup(c *cliclient.MasterClient, name string, types ...string) (*ntypes.Re
417415 return byName , nil
418416}
419417
420- func RandomName () string {
421- return strings .Replace (namesgenerator .GetRandomName (0 ), "_" , "-" , - 1 )
422- }
423-
424418// RandomLetters returns a string with random letters of length n
425419func RandomLetters (n int ) string {
426- rand .Seed (time .Now ().UnixNano ())
427420 b := make ([]byte , n )
428421 for i := range b {
429422 b [i ] = letters [rand .Intn (len (letters ))]
@@ -461,8 +454,7 @@ func SimpleFormat(values [][]string) (string, string) {
461454func defaultAction (fn func (ctx * cli.Context ) error ) func (ctx * cli.Context ) error {
462455 return func (ctx * cli.Context ) error {
463456 if ctx .Bool ("help" ) {
464- cli .ShowAppHelp (ctx )
465- return nil
457+ return cli .ShowAppHelp (ctx )
466458 }
467459 return fn (ctx )
468460 }
@@ -519,14 +511,6 @@ func SplitOnColon(s string) []string {
519511 return strings .Split (s , ":" )
520512}
521513
522- func parseClusterAndProjectName (name string ) (string , string , error ) {
523- parts := strings .SplitN (name , "/" , 2 )
524- if len (parts ) == 2 {
525- return parts [0 ], parts [1 ], nil
526- }
527- return "" , "" , fmt .Errorf ("Unable to extract clustername and projectname from [%s]" , name )
528- }
529-
530514func parseClusterAndProjectID (id string ) (string , string , error ) {
531515 // Validate id
532516 // Examples:
@@ -543,7 +527,7 @@ func parseClusterAndProjectID(id string) (string, string, error) {
543527
544528// Return a JSON blob of the file at path
545529func readFileReturnJSON (path string ) ([]byte , error ) {
546- file , err := ioutil .ReadFile (path )
530+ file , err := os .ReadFile (path )
547531 if err != nil {
548532 return []byte {}, err
549533 }
@@ -577,21 +561,6 @@ func hasPrefix(buf []byte, prefix []byte) bool {
577561 return bytes .HasPrefix (trim , prefix )
578562}
579563
580- func settingsToMap (client * cliclient.MasterClient ) (map [string ]string , error ) {
581- configMap := make (map [string ]string )
582-
583- settings , err := client .ManagementClient .Setting .List (baseListOpts ())
584- if err != nil {
585- return nil , err
586- }
587-
588- for _ , setting := range settings .Data {
589- configMap [setting .Name ] = setting .Value
590- }
591-
592- return configMap , nil
593- }
594-
595564// getClusterNames maps cluster ID to name and defaults to ID if name is blank
596565func getClusterNames (ctx * cli.Context , c * cliclient.MasterClient ) (map [string ]string , error ) {
597566 clusterNames := make (map [string ]string )
@@ -617,15 +586,6 @@ func getClusterName(cluster *managementClient.Cluster) string {
617586 return cluster .ID
618587}
619588
620- func findStringInArray (s string , a []string ) bool {
621- for _ , val := range a {
622- if s == val {
623- return true
624- }
625- }
626- return false
627- }
628-
629589func createdTimetoHuman (t string ) (string , error ) {
630590 parsedTime , err := time .Parse (time .RFC3339 , t )
631591 if err != nil {
@@ -652,9 +612,11 @@ func outputMembers(ctx *cli.Context, c *cliclient.MasterClient, members []manage
652612 if err != nil {
653613 return err
654614 }
615+
616+ memberType := fmt .Sprintf ("%s %s" , principal .Provider , principal .PrincipalType )
655617 writer .Write (& MemberData {
656618 Name : principal .Name ,
657- MemberType : strings .Title (fmt . Sprintf ( "%s %s" , principal . Provider , principal . PrincipalType ) ),
619+ MemberType : cases .Title (language . Und ). String ( memberType ),
658620 AccessType : m .AccessType ,
659621 })
660622 }
@@ -699,15 +661,6 @@ func deleteMembersByNames(ctx *cli.Context, c *cliclient.MasterClient, members [
699661 return members , nil
700662}
701663
702- func tickerContext (ctx context.Context , duration time.Duration ) <- chan time.Time {
703- ticker := time .NewTicker (duration )
704- go func () {
705- <- ctx .Done ()
706- ticker .Stop ()
707- }()
708- return ticker .C
709- }
710-
711664func ConfigDir () (string , error ) {
712665 homeDir , err := os .UserHomeDir ()
713666 if err != nil {
0 commit comments