-
Notifications
You must be signed in to change notification settings - Fork 247
/
wildcards.go
57 lines (43 loc) · 1.39 KB
/
wildcards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package actions
import (
"context"
"fmt"
"github.com/smallstep/cli/internal/command"
"github.com/smallstep/cli/utils/cautils"
)
// AllowWildcardsAction updates the policy to allow wildcard names.
func AllowWildcardsAction(ctx context.Context) (err error) {
clictx := command.CLIContextFromContext(ctx)
client, err := cautils.NewAdminClient(clictx)
if err != nil {
return fmt.Errorf("error creating admin client: %w", err)
}
policy, err := retrieveAndInitializePolicy(ctx, client)
if err != nil {
return fmt.Errorf("error retrieving policy: %w", err)
}
policy.X509.AllowWildcardNames = true
updatedPolicy, err := updatePolicy(ctx, client, policy)
if err != nil {
return fmt.Errorf("error updating policy: %w", err)
}
return prettyPrint(updatedPolicy)
}
// DenyWildcardsAction updates the policy to deny wildcard names.
func DenyWildcardsAction(ctx context.Context) (err error) {
clictx := command.CLIContextFromContext(ctx)
client, err := cautils.NewAdminClient(clictx)
if err != nil {
return fmt.Errorf("error creating admin client: %w", err)
}
policy, err := retrieveAndInitializePolicy(ctx, client)
if err != nil {
return fmt.Errorf("error retrieving policy: %w", err)
}
policy.X509.AllowWildcardNames = false
updatedPolicy, err := updatePolicy(ctx, client, policy)
if err != nil {
return fmt.Errorf("error updating policy: %w", err)
}
return prettyPrint(updatedPolicy)
}