package orgpolicy
import "cloud.google.com/go/orgpolicy/apiv2"
Package orgpolicy is an auto-generated package for the Organization Policy API.
The Organization Policy API allows users to configure governance rules on their Google Cloud resources across the resource hierarchy.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/orgpolicy/apiv2@latest ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := orgpolicy.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req := &orgpolicypb.CreateCustomConstraintRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#CreateCustomConstraintRequest. } resp, err := c.CreateCustomConstraint(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Index ¶
- func DefaultAuthScopes() []string
- type CallOptions
- type Client
- func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)
- func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) Connection() *grpc.ClientConn
- func (c *Client) CreateCustomConstraint(ctx context.Context, req *orgpolicypb.CreateCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
- func (c *Client) CreatePolicy(ctx context.Context, req *orgpolicypb.CreatePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
- func (c *Client) DeleteCustomConstraint(ctx context.Context, req *orgpolicypb.DeleteCustomConstraintRequest, opts ...gax.CallOption) error
- func (c *Client) DeletePolicy(ctx context.Context, req *orgpolicypb.DeletePolicyRequest, opts ...gax.CallOption) error
- func (c *Client) GetCustomConstraint(ctx context.Context, req *orgpolicypb.GetCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
- func (c *Client) GetEffectivePolicy(ctx context.Context, req *orgpolicypb.GetEffectivePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
- func (c *Client) GetPolicy(ctx context.Context, req *orgpolicypb.GetPolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
- func (c *Client) ListConstraints(ctx context.Context, req *orgpolicypb.ListConstraintsRequest, opts ...gax.CallOption) *ConstraintIterator
- func (c *Client) ListCustomConstraints(ctx context.Context, req *orgpolicypb.ListCustomConstraintsRequest, opts ...gax.CallOption) *CustomConstraintIterator
- func (c *Client) ListPolicies(ctx context.Context, req *orgpolicypb.ListPoliciesRequest, opts ...gax.CallOption) *PolicyIterator
- func (c *Client) UpdateCustomConstraint(ctx context.Context, req *orgpolicypb.UpdateCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
- func (c *Client) UpdatePolicy(ctx context.Context, req *orgpolicypb.UpdatePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
- type ConstraintIterator
- func (it *ConstraintIterator) All() iter.Seq2[*orgpolicypb.Constraint, error]
- func (it *ConstraintIterator) Next() (*orgpolicypb.Constraint, error)
- func (it *ConstraintIterator) PageInfo() *iterator.PageInfo
- type CustomConstraintIterator
- func (it *CustomConstraintIterator) All() iter.Seq2[*orgpolicypb.CustomConstraint, error]
- func (it *CustomConstraintIterator) Next() (*orgpolicypb.CustomConstraint, error)
- func (it *CustomConstraintIterator) PageInfo() *iterator.PageInfo
- type PolicyIterator
Examples ¶
- Client.CreateCustomConstraint
- Client.CreatePolicy
- Client.DeleteCustomConstraint
- Client.DeletePolicy
- Client.GetCustomConstraint
- Client.GetEffectivePolicy
- Client.GetPolicy
- Client.ListConstraints
- Client.ListConstraints (All)
- Client.ListCustomConstraints
- Client.ListCustomConstraints (All)
- Client.ListPolicies
- Client.ListPolicies (All)
- Client.UpdateCustomConstraint
- Client.UpdatePolicy
- NewClient
- NewRESTClient
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type CallOptions ¶
type CallOptions struct { ListConstraints []gax.CallOption ListPolicies []gax.CallOption GetPolicy []gax.CallOption GetEffectivePolicy []gax.CallOption CreatePolicy []gax.CallOption UpdatePolicy []gax.CallOption DeletePolicy []gax.CallOption CreateCustomConstraint []gax.CallOption UpdateCustomConstraint []gax.CallOption GetCustomConstraint []gax.CallOption ListCustomConstraints []gax.CallOption DeleteCustomConstraint []gax.CallOption }
CallOptions contains the retry settings for each method of Client.
type Client ¶
type Client struct { // The call options for this service. CallOptions *CallOptions // contains filtered or unexported fields }
Client is a client for interacting with Organization Policy API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
An interface for managing organization policies.
The Organization Policy Service provides a simple mechanism for organizations to restrict the allowed configurations across their entire resource hierarchy.
You can use a policy to configure restrictions on resources. For example, you can enforce a policy that restricts which Google Cloud APIs can be activated in a certain part of your resource hierarchy, or prevents serial port access to VM instances in a particular folder.
Policies are inherited down through the resource hierarchy. A policy applied to a parent resource automatically applies to all its child resources unless overridden with a policy lower in the hierarchy.
A constraint defines an aspect of a resource’s configuration that can be controlled by an organization’s policy administrator. Policies are a collection of constraints that defines their allowable configuration on a particular resource and its child resources.
func NewClient ¶
NewClient creates a new org policy client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
An interface for managing organization policies.
The Organization Policy Service provides a simple mechanism for organizations to restrict the allowed configurations across their entire resource hierarchy.
You can use a policy to configure restrictions on resources. For example, you can enforce a policy that restricts which Google Cloud APIs can be activated in a certain part of your resource hierarchy, or prevents serial port access to VM instances in a particular folder.
Policies are inherited down through the resource hierarchy. A policy applied to a parent resource automatically applies to all its child resources unless overridden with a policy lower in the hierarchy.
A constraint defines an aspect of a resource’s configuration that can be
controlled by an organization’s policy administrator. Policies are a
collection of constraints that defines their allowable configuration on a
particular resource and its child resources.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewRESTClient ¶
NewRESTClient creates a new org policy rest client.
An interface for managing organization policies.
The Organization Policy Service provides a simple mechanism for organizations to restrict the allowed configurations across their entire resource hierarchy.
You can use a policy to configure restrictions on resources. For example, you can enforce a policy that restricts which Google Cloud APIs can be activated in a certain part of your resource hierarchy, or prevents serial port access to VM instances in a particular folder.
Policies are inherited down through the resource hierarchy. A policy applied to a parent resource automatically applies to all its child resources unless overridden with a policy lower in the hierarchy.
A constraint defines an aspect of a resource’s configuration that can be
controlled by an organization’s policy administrator. Policies are a
collection of constraints that defines their allowable configuration on a
particular resource and its child resources.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*Client) Close ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Connection ¶
func (c *Client) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*Client) CreateCustomConstraint ¶
func (c *Client) CreateCustomConstraint(ctx context.Context, req *orgpolicypb.CreateCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
CreateCustomConstraint creates a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
organization does not exist.
Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the
constraint already exists on the given organization.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.CreateCustomConstraintRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#CreateCustomConstraintRequest.
}
resp, err := c.CreateCustomConstraint(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) CreatePolicy ¶
func (c *Client) CreatePolicy(ctx context.Context, req *orgpolicypb.CreatePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
CreatePolicy creates a policy.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint does not exist.
Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the
policy already exists on the given Google Cloud resource.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.CreatePolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#CreatePolicyRequest.
}
resp, err := c.CreatePolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) DeleteCustomConstraint ¶
func (c *Client) DeleteCustomConstraint(ctx context.Context, req *orgpolicypb.DeleteCustomConstraintRequest, opts ...gax.CallOption) error
DeleteCustomConstraint deletes a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint does not exist.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.DeleteCustomConstraintRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#DeleteCustomConstraintRequest.
}
err = c.DeleteCustomConstraint(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*Client) DeletePolicy ¶
func (c *Client) DeletePolicy(ctx context.Context, req *orgpolicypb.DeletePolicyRequest, opts ...gax.CallOption) error
DeletePolicy deletes a policy.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint or organization policy does not exist.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.DeletePolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#DeletePolicyRequest.
}
err = c.DeletePolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*Client) GetCustomConstraint ¶
func (c *Client) GetCustomConstraint(ctx context.Context, req *orgpolicypb.GetCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
GetCustomConstraint gets a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
custom constraint does not exist.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.GetCustomConstraintRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#GetCustomConstraintRequest.
}
resp, err := c.GetCustomConstraint(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) GetEffectivePolicy ¶
func (c *Client) GetEffectivePolicy(ctx context.Context, req *orgpolicypb.GetEffectivePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
GetEffectivePolicy gets the effective policy on a resource. This is the result of merging
policies in the resource hierarchy and evaluating conditions. The
returned policy will not have an etag or condition set because it is
an evaluated policy across multiple resources.
Subtrees of Resource Manager resource hierarchy with ‘under:’ prefix will
not be expanded.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.GetEffectivePolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#GetEffectivePolicyRequest.
}
resp, err := c.GetEffectivePolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) GetPolicy ¶
func (c *Client) GetPolicy(ctx context.Context, req *orgpolicypb.GetPolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
GetPolicy gets a policy on a resource.
If no policy is set on the resource, NOT_FOUND is returned. The
etag value can be used with UpdatePolicy() to update a
policy during read-modify-write.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.GetPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#GetPolicyRequest.
}
resp, err := c.GetPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) ListConstraints ¶
func (c *Client) ListConstraints(ctx context.Context, req *orgpolicypb.ListConstraintsRequest, opts ...gax.CallOption) *ConstraintIterator
ListConstraints lists constraints that could be applied on the specified resource.
Code:play
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListConstraintsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListConstraintsRequest.
}
it := c.ListConstraints(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*orgpolicypb.ListConstraintsResponse)
}
}
Example (All)¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListConstraintsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListConstraintsRequest.
}
for resp, err := range c.ListConstraints(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*Client) ListCustomConstraints ¶
func (c *Client) ListCustomConstraints(ctx context.Context, req *orgpolicypb.ListCustomConstraintsRequest, opts ...gax.CallOption) *CustomConstraintIterator
ListCustomConstraints retrieves all of the custom constraints that exist on a particular
organization resource.
Code:play
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListCustomConstraintsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListCustomConstraintsRequest.
}
it := c.ListCustomConstraints(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*orgpolicypb.ListCustomConstraintsResponse)
}
}
Example (All)¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListCustomConstraintsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListCustomConstraintsRequest.
}
for resp, err := range c.ListCustomConstraints(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*Client) ListPolicies ¶
func (c *Client) ListPolicies(ctx context.Context, req *orgpolicypb.ListPoliciesRequest, opts ...gax.CallOption) *PolicyIterator
ListPolicies retrieves all of the policies that exist on a particular resource.
Code:play
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListPoliciesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListPoliciesRequest.
}
it := c.ListPolicies(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*orgpolicypb.ListPoliciesResponse)
}
}
Example (All)¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.ListPoliciesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#ListPoliciesRequest.
}
for resp, err := range c.ListPolicies(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*Client) UpdateCustomConstraint ¶
func (c *Client) UpdateCustomConstraint(ctx context.Context, req *orgpolicypb.UpdateCustomConstraintRequest, opts ...gax.CallOption) (*orgpolicypb.CustomConstraint, error)
UpdateCustomConstraint updates a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist.
Note: the supplied policy will perform a full overwrite of all
fields.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.UpdateCustomConstraintRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#UpdateCustomConstraintRequest.
}
resp, err := c.UpdateCustomConstraint(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) UpdatePolicy ¶
func (c *Client) UpdatePolicy(ctx context.Context, req *orgpolicypb.UpdatePolicyRequest, opts ...gax.CallOption) (*orgpolicypb.Policy, error)
UpdatePolicy updates a policy.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or the policy do not exist. Returns a google.rpc.Status with google.rpc.Code.ABORTED if the etag supplied in the request does not match the persisted etag of the policy
Note: the supplied policy will perform a full overwrite of all
fields.
Code:play
Example¶
package main
import (
"context"
orgpolicy "cloud.google.com/go/orgpolicy/apiv2"
orgpolicypb "cloud.google.com/go/orgpolicy/apiv2/orgpolicypb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := orgpolicy.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &orgpolicypb.UpdatePolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/orgpolicy/apiv2/orgpolicypb#UpdatePolicyRequest.
}
resp, err := c.UpdatePolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
type ConstraintIterator ¶
type ConstraintIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*orgpolicypb.Constraint, nextPageToken string, err error) // contains filtered or unexported fields }
ConstraintIterator manages a stream of *orgpolicypb.Constraint.
func (*ConstraintIterator) All ¶
func (it *ConstraintIterator) All() iter.Seq2[*orgpolicypb.Constraint, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*ConstraintIterator) Next ¶
func (it *ConstraintIterator) Next() (*orgpolicypb.Constraint, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*ConstraintIterator) PageInfo ¶
func (it *ConstraintIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type CustomConstraintIterator ¶
type CustomConstraintIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*orgpolicypb.CustomConstraint, nextPageToken string, err error) // contains filtered or unexported fields }
CustomConstraintIterator manages a stream of *orgpolicypb.CustomConstraint.
func (*CustomConstraintIterator) All ¶
func (it *CustomConstraintIterator) All() iter.Seq2[*orgpolicypb.CustomConstraint, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*CustomConstraintIterator) Next ¶
func (it *CustomConstraintIterator) Next() (*orgpolicypb.CustomConstraint, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*CustomConstraintIterator) PageInfo ¶
func (it *CustomConstraintIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type PolicyIterator ¶
type PolicyIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*orgpolicypb.Policy, nextPageToken string, err error) // contains filtered or unexported fields }
PolicyIterator manages a stream of *orgpolicypb.Policy.
func (*PolicyIterator) All ¶
func (it *PolicyIterator) All() iter.Seq2[*orgpolicypb.Policy, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*PolicyIterator) Next ¶
func (it *PolicyIterator) Next() (*orgpolicypb.Policy, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*PolicyIterator) PageInfo ¶
func (it *PolicyIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
Source Files ¶
auxiliary.go auxiliary_go123.go doc.go helpers.go org_policy_client.go version.go
Directories ¶
Path | Synopsis |
---|---|
apiv2/orgpolicypb |
- Version
- v1.14.2 (latest)
- Published
- Jan 2, 2025
- Platform
- linux/amd64
- Imports
- 26 packages
- Last checked
- 3 days ago –
Tools for package owners.