@@ -101,6 +101,8 @@ type authAccountCommand struct {
101
101
prefix string
102
102
tags []string
103
103
rmTags []string
104
+ mapSource string
105
+ mapTarget string
104
106
}
105
107
106
108
func configureAuthAccountCommand (auth commandHost ) {
@@ -278,6 +280,95 @@ func configureAuthAccountCommand(auth commandHost) {
278
280
skrm .Flag ("key" , "The key to remove" ).StringVar (& c .skRole )
279
281
skrm .Flag ("operator" , "Operator to act on" ).StringVar (& c .operatorName )
280
282
skrm .Flag ("force" , "Removes without prompting" ).Short ('f' ).UnNegatableBoolVar (& c .force )
283
+
284
+ mappings := acct .Command ("mappings" , "Manage account level subject mapping and partitioning" ).Alias ("m" )
285
+
286
+ mappingsaAdd := mappings .Command ("add" , "Add a new mapping" ).Alias ("new" ).Alias ("a" ).Action (c .mappingAddAction )
287
+ mappingsaAdd .Arg ("name" , "Account to act on" ).StringVar (& c .accountName )
288
+ mappingsaAdd .Arg ("source" , "The source subject of the mapping" ).StringVar (& c .mapSource )
289
+ mappingsaAdd .Arg ("target" , "The target subject of the mapping" ).StringVar (& c .mapTarget )
290
+
291
+ mappingsaAdd .Flag ("operator" , "Operator to act on" ).StringVar (& c .operatorName )
292
+
293
+ mappingsls := mappings .Command ("ls" , "List mappings" ).Alias ("list" ).Action (c .mappingListAction )
294
+ mappingsls .Arg ("name" , "Account to act on" ).StringVar (& c .accountName )
295
+ mappingsls .Flag ("operator" , "Operator to act on" ).StringVar (& c .operatorName )
296
+
297
+ mappingsrm := mappings .Command ("rm" , "Remove a mapping" ).Action (c .mappingRmAction )
298
+ mappingsrm .Arg ("name" , "Account to act on" ).StringVar (& c .accountName )
299
+ mappingsrm .Arg ("source" , "The source subject of the mapping" ).StringVar (& c .mapSource )
300
+ mappingsrm .Arg ("target" , "The target subject of the mapping" ).StringVar (& c .mapTarget )
301
+
302
+ mappingsrm .Flag ("operator" , "Operator to act on" ).StringVar (& c .operatorName )
303
+ }
304
+
305
+ func (c * authAccountCommand ) mappingAddAction (_ * fisk.ParseContext ) error {
306
+ _ , _ , _ , err := c .selectAccount (true )
307
+ if err != nil {
308
+ return err
309
+ }
310
+
311
+ if c .mapSource == "" {
312
+ err := iu .AskOne (& survey.Input {
313
+ Message : "Source stream" ,
314
+ Help : "The source stream of the mapping" ,
315
+ }, & c .mapSource , survey .WithValidator (survey .Required ))
316
+ if err != nil {
317
+ return err
318
+ }
319
+ }
320
+
321
+ if c .mapTarget == "" {
322
+ err := iu .AskOne (& survey.Input {
323
+ Message : "Target stream" ,
324
+ Help : "The target stream of the mapping" ,
325
+ }, & c .mapTarget , survey .WithValidator (survey .Required ))
326
+ if err != nil {
327
+ return err
328
+ }
329
+ }
330
+
331
+ // Add mapping claim to jwt
332
+
333
+ fmt .Printf ("Created mapping {%s %s}\n " , c .mapSource , c .mapTarget )
334
+
335
+ return nil
336
+ }
337
+
338
+ func (c * authAccountCommand ) mappingListAction (_ * fisk.ParseContext ) error {
339
+ _ , _ , _ , err := c .selectAccount (true )
340
+ if err != nil {
341
+ return err
342
+ }
343
+ return nil
344
+ }
345
+
346
+ func (c * authAccountCommand ) mappingRmAction (_ * fisk.ParseContext ) error {
347
+ _ , _ , _ , err := c .selectAccount (true )
348
+ if err != nil {
349
+ return err
350
+ }
351
+
352
+ // show all mappings for account
353
+ mappings := []string {
354
+ "foo.bar bar.foo" ,
355
+ "foo.baz baz.foo" ,
356
+ "foo.prod foo.dev" }
357
+
358
+ selected := ""
359
+ err = iu .AskOne (& survey.Select {
360
+ Message : "Select a mapping to delete" ,
361
+ Options : mappings ,
362
+ PageSize : iu .SelectPageSize (len (mappings )),
363
+ }, & selected )
364
+ if err != nil {
365
+ return err
366
+ }
367
+
368
+ // Delete selected from the jwt
369
+
370
+ fmt .Printf ("Deleted mapping {%s}\n " , selected )
371
+ return nil
281
372
}
282
373
283
374
func (c * authAccountCommand ) selectAccount (pick bool ) (* ab.AuthImpl , ab.Operator , ab.Account , error ) {
0 commit comments