@@ -68,17 +68,26 @@ func runTemplateApplyCommand(flags *applyFlags) error {
6868 return fmt .Errorf ("retrieving credentials: %w" , err )
6969 }
7070
71- deviceNetCredentials := make (map [string ]string )
72- if flags .netCredentials != "" {
73- configNetArray := strings .Split (strings .Trim (flags .netCredentials , " " ), "," )
74- for _ , netConfig := range configNetArray {
75- netConfigArray := strings .Split (netConfig , "=" )
76- if len (netConfigArray ) != 2 {
77- return fmt .Errorf ("invalid network configuration: %s" , netConfig )
78- }
79- deviceNetCredentials [netConfigArray [0 ]] = netConfigArray [1 ]
80- }
71+ deviceNetCredentials , err := parseCredentials (flags .netCredentials )
72+ if err != nil {
73+ return fmt .Errorf ("parsing network credentials: %w" , err )
8174 }
82-
75+
8376 return template .ApplyCustomTemplates (cred , flags .templateId , flags .deviceId , flags .templatePrefix , deviceNetCredentials )
8477}
78+
79+ func parseCredentials (credentials string ) (map [string ]string , error ) {
80+ credentialsMap := make (map [string ]string )
81+ if credentials == "" {
82+ return credentialsMap , nil
83+ }
84+ credentialsArray := strings .Split (credentials , "," )
85+ for _ , credential := range credentialsArray {
86+ credentialArray := strings .Split (credential , "=" )
87+ if len (credentialArray ) != 2 {
88+ return nil , fmt .Errorf ("invalid network credential: %s" , credential )
89+ }
90+ credentialsMap [credentialArray [0 ]] = credentialArray [1 ]
91+ }
92+ return credentialsMap , nil
93+ }
0 commit comments