https://cerbos.dev logo
#help
Title
# help
a

ANILA SOMAN

09/02/2023, 3:56 PM
Hi Team, func ListPolicies() { list, err := admcli.ListPolicies(context.Background()) if err != nil { fmt.Printf("error getting lists: %v", err) } for _, v := range list { fmt.Printf(" %s \n", v) } } policy ID necessary for disabling a policy, could you please provide more context about how we get the policy ID?
d

Dennis (Cerbos)

09/03/2023, 8:58 PM
The
ListPolicies
method returns a slice of policy IDs, which can be used, for example, to disable a policy. Here’s a fragment of a test:
Copy code
have, err := ac.ListPolicies(ctx, WithIncludeDisabled())
		require.NoError(t, err)
		require.NotEmpty(t, have)

		id := have[0]
		p, err := ac.GetPolicy(ctx, id)
		require.NoError(t, err)
		require.Len(t, p, 1)
		require.False(t, p[0].Disabled)

		n, err := ac.DisablePolicy(ctx, id)
		require.NoError(t, err)
		require.Equal(t, uint32(1), n)

		p, err = ac.GetPolicy(ctx, id)
		require.NoError(t, err)
		require.Len(t, p, 1)
		require.True(t, p[0].Disabled)
a

ANILA SOMAN

09/04/2023, 4:12 AM
@Dennis (Cerbos) i have tried with ListPolicies method but it only give slice of policy name, not policy ID.
Do we have any other method to get the policy ID?
d

Dennis (Cerbos)

09/04/2023, 4:40 AM
These policy names are effectively policy IDs, which can be used to disable policies as per my example. Sorry if I am missing your point. What do you want to do with the policy ID?
2 Views