github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/policies/doc.go (about)

     1  /*
     2  Package policies provides information and interaction with the policies API
     3  resource for the OpenStack Identity service.
     4  
     5  Example to List Policies
     6  
     7  	listOpts := policies.ListOpts{
     8  		Type: "application/json",
     9  	}
    10  
    11  	allPages, err := policies.List(identityClient, listOpts).AllPages()
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	allPolicies, err := policies.ExtractPolicies(allPages)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	for _, policy := range allPolicies {
    22  		fmt.Printf("%+v\n", policy)
    23  	}
    24  
    25  Example to Create a Policy
    26  
    27  	createOpts := policies.CreateOpts{
    28  		Type: "application/json",
    29  		Blob: []byte("{'foobar_user': 'role:compute-user'}"),
    30  		Extra: map[string]interface{}{
    31  			"description": "policy for foobar_user",
    32  		},
    33  	}
    34  
    35  	policy, err := policies.Create(identityClient, createOpts).Extract()
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  
    40  Example to Get a Policy
    41  
    42  	policyID := "0fe36e73809d46aeae6705c39077b1b3"
    43  	policy, err := policies.Get(identityClient, policyID).Extract()
    44  	if err != nil {
    45  		panic(err)
    46  	}
    47  
    48  	fmt.Printf("%+v\n", policy)
    49  
    50  Example to Update a Policy
    51  
    52  	policyID := "0fe36e73809d46aeae6705c39077b1b3"
    53  
    54  	updateOpts := policies.UpdateOpts{
    55  		Type: "application/json",
    56  		Blob: []byte("{'foobar_user': 'role:compute-user'}"),
    57  		Extra: map[string]interface{}{
    58  			"description": "policy for foobar_user",
    59  		},
    60  	}
    61  
    62  	policy, err := policies.Update(identityClient, policyID, updateOpts).Extract()
    63  	if err != nil {
    64  		panic(err)
    65  	}
    66  
    67  	fmt.Printf("%+v\n", policy)
    68  
    69  Example to Delete a Policy
    70  
    71  	policyID := "0fe36e73809d46aeae6705c39077b1b3"
    72  	err := policies.Delete(identityClient, policyID).ExtractErr()
    73  	if err != nil {
    74  		panic(err)
    75  	}
    76  */
    77  package policies