@@ -16,37 +16,41 @@ import (
1616
1717 "github.com/smallstep/cli/command/ca/policy/policycontext"
1818 "github.com/smallstep/cli/internal/command"
19- "github.com/smallstep/cli/internal/provisionerflag"
2019)
2120
2221var provisionerFilterFlag = cli.StringFlag {
2322 Name : "provisioner" ,
2423 Usage : `The provisioner <name>` ,
2524}
2625
27- // ignoreProvisionerFlagIfRequired is a helper function that marks the provisioner
28- // flag to be ignored when managing a provisioner or ACME account level policy. In
29- // those cases the provisioner flag is used to filter which provisioner the policy
30- // applies to, as opposed to its normal usage, where it can be used to select the
31- // (admin) provisioner to use for authentication.
32- func ignoreProvisionerFlagIfRequired (ctx context.Context ) {
26+ func retrieveAndUnsetProvisionerFlagIfRequired (ctx context.Context ) string {
27+ // when managing policies on the authority level there's no need
28+ // to select a provisioner, so the flag does not need to be unset.
29+ if policycontext .IsAuthorityPolicyLevel (ctx ) {
30+ return ""
31+ }
32+
3333 clictx := command .CLIContextFromContext (ctx )
34- if policycontext .IsProvisionerPolicyLevel (ctx ) || policycontext .IsACMEPolicyLevel (ctx ) {
35- provisionerflag .Ignore (clictx )
34+ provisioner := clictx .String ("provisioner" )
35+
36+ // unset the provisioner flag value, so that it's not used
37+ // automatically in token flows.
38+ if err := clictx .Set ("provisioner" , "" ); err != nil {
39+ panic (fmt .Errorf ("failed unsetting provisioner flag: %w" , err ))
3640 }
41+
42+ return provisioner
3743}
3844
39- func retrieveAndInitializePolicy (ctx context.Context , client * ca.AdminClient ) (* linkedca.Policy , error ) {
45+ func retrieveAndInitializePolicy (ctx context.Context , client * ca.AdminClient , provisioner string ) (* linkedca.Policy , error ) {
4046 var (
41- policy * linkedca.Policy
42- err error
47+ clictx = command .CLIContextFromContext (ctx )
48+ reference = clictx .String ("eab-key-reference" )
49+ keyID = clictx .String ("eab-key-id" )
50+ policy * linkedca.Policy
51+ err error
4352 )
4453
45- clictx := command .CLIContextFromContext (ctx )
46- provisioner := clictx .String ("provisioner" )
47- reference := clictx .String ("eab-key-reference" )
48- keyID := clictx .String ("eab-key-id" )
49-
5054 switch {
5155 case policycontext .IsAuthorityPolicyLevel (ctx ):
5256 policy , err = client .GetAuthorityPolicy ()
@@ -160,13 +164,11 @@ func initPolicy(p *linkedca.Policy) *linkedca.Policy {
160164 return p
161165}
162166
163- func updatePolicy (ctx context.Context , client * ca.AdminClient , policy * linkedca.Policy ) (* linkedca.Policy , error ) {
164- clictx := command .CLIContextFromContext (ctx )
165- provisioner := clictx .String ("provisioner" )
166- reference := clictx .String ("eab-key-reference" )
167- keyID := clictx .String ("eab-key-id" )
168-
167+ func updatePolicy (ctx context.Context , client * ca.AdminClient , policy * linkedca.Policy , provisioner string ) (* linkedca.Policy , error ) {
169168 var (
169+ clictx = command .CLIContextFromContext (ctx )
170+ reference = clictx .String ("eab-key-reference" )
171+ keyID = clictx .String ("eab-key-id" )
170172 updatedPolicy * linkedca.Policy
171173 err error
172174 )
0 commit comments