@@ -16,6 +16,7 @@ package cmd
1616
1717import (
1818 "context"
19+ "encoding/json"
1920 "fmt"
2021
2122 "github.com/rs/zerolog/log"
@@ -79,6 +80,9 @@ var migratePamCmd = &cobra.Command{
7980 return returnHttpErr (httpResponse , rErr )
8081 }
8182
83+ jobject , _ := json .MarshalIndent (listPamProvidersInUse , "" , " " )
84+ fmt .Println (string (jobject ))
85+
8286 // TODO: ensure only 1 returned PAM Provider definition
8387
8488 // get PAM Type definition for PAM Provider migrating <<FROM>>
@@ -93,33 +97,53 @@ var migratePamCmd = &cobra.Command{
9397 return returnHttpErr (httpResponse , rErr )
9498 }
9599
100+ // jobject, _ = json.MarshalIndent(pamTypes, "", " ")
101+ // fmt.Println(string(jobject))
102+
96103 // assess <<FROM>> source PAM Type to create map for storing existing data
97104 // this map has the first string key record the parameter field name
98105 // the inner map tracks PAM instance GUIDs to that instances value for the field
99106 // map[fieldname] -> map[InstanceGuid] = set value
100107 inUsePamParamValues := map [string ]map [string ]string {}
101108 for _ , pamType := range pamTypes {
102- if pamType .Id == listPamProvidersInUse [0 ].ProviderType .Id {
103- for _ , pamParamType := range pamType .ProviderTypeParams {
104- if * pamParamType .InstanceLevel {
109+ if * pamType .Id == * listPamProvidersInUse [0 ].ProviderType .Id {
110+ // TODO: remove debugging
111+ jobject , _ := json .MarshalIndent (pamType , "" , " " )
112+ fmt .Println (string (jobject ))
113+ jobject , _ = json .MarshalIndent (pamType .AdditionalProperties ["Parameters" ], "" , " " )
114+ fmt .Println (string (jobject ))
115+ // TODO: check typing, have to access "Parameters" instead of ProviderTypeParams
116+ for _ , pamParamType := range pamType .AdditionalProperties ["Parameters" ].([]interface {}) {
117+ jobject , _ := json .MarshalIndent (pamParamType , "" , " " )
118+ fmt .Println (string (jobject ))
119+ if pamParamType .(map [string ]interface {})["InstanceLevel" ].(bool ) {
105120 // found definition of an instance level param for the type in question
106121 // create key in map for the field name
107- inUsePamParamValues [* pamParamType .Name ] = map [string ]string {}
122+ inUsePamParamValues [pamParamType .(map [string ]interface {})["Name" ].(string )] = map [string ]string {}
123+ fmt .Println ("made it!" )
108124 }
109125 }
110126 }
111127 }
128+ jobject , _ = json .MarshalIndent (inUsePamParamValues , "" , " " )
129+ fmt .Println (string (jobject ))
112130
113131 // step through list of every defined param value
114132 // record unique GUIDs of every param value on InstanceLevel : true
115133 // don't count InstanceLevel : false because those are Secret (DataType:2) instances for the Provider itself, not actual usages
116134 for _ , pamParam := range listPamProvidersInUse [0 ].ProviderTypeParamValues {
135+ jobject , _ = json .MarshalIndent (pamParam , "" , " " )
136+ fmt .Println (string (jobject ))
117137 if * pamParam .ProviderTypeParam .InstanceLevel {
118138 fieldName := * pamParam .ProviderTypeParam .Name
119139 usageGuid := * pamParam .InstanceGuid
120140 inUsePamParamValues [fieldName ][usageGuid ] = * pamParam .Value
121141 }
122142 }
143+ jobject , _ = json .MarshalIndent (inUsePamParamValues , "" , " " )
144+ fmt .Println (string (jobject ))
145+
146+ return nil
123147
124148 // TODO: make sure every field has the same number of GUIDs tracked
125149 // tally GUID count for logging
@@ -173,3 +197,41 @@ var migratePamCmd = &cobra.Command{
173197 // submit PUT for updating Store definition
174198 },
175199}
200+
201+ func init () {
202+ var from string
203+ var to string
204+ var appendName string
205+
206+ RootCmd .AddCommand (migrateCmd )
207+
208+ migrateCmd .AddCommand (migratePamCmd )
209+
210+ migratePamCmd .Flags ().StringVarP (
211+ & from ,
212+ "from" ,
213+ "f" ,
214+ "" ,
215+ "Name of the defined PAM Provider to migrate to a new type" ,
216+ )
217+
218+ migratePamCmd .Flags ().StringVarP (
219+ & to ,
220+ "to" ,
221+ "t" ,
222+ "" ,
223+ "Name of the PAM Provider Type to migrate to" ,
224+ )
225+
226+ migratePamCmd .Flags ().StringVarP (
227+ & appendName ,
228+ "append-name" ,
229+ "a" ,
230+ "" ,
231+ "Text to append to current PAM Provider Name in newly created Provider" ,
232+ )
233+
234+ migratePamCmd .MarkFlagRequired ("from" )
235+ migratePamCmd .MarkFlagRequired ("to" )
236+ migratePamCmd .MarkFlagRequired ("append-name" )
237+ }
0 commit comments