...

Source file src/cloud.google.com/go/iam/admin/apiv1/doc.go

Documentation: cloud.google.com/go/iam/admin/apiv1

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package admin is an auto-generated package for the
    16  // Identity and Access Management (IAM) API.
    17  //
    18  // Manages identity and access control for Google Cloud Platform resources,
    19  // including the creation of service accounts, which you can use to
    20  // authenticate to Google and make API calls.
    21  //
    22  //	NOTE: This package is in beta. It is not stable, and may be subject to changes.
    23  //
    24  // # Example usage
    25  //
    26  // To get started with this package, create a client.
    27  //
    28  //	ctx := context.Background()
    29  //	// This snippet has been automatically generated and should be regarded as a code template only.
    30  //	// It will require modifications to work:
    31  //	// - It may require correct/in-range values for request initialization.
    32  //	// - It may require specifying regional endpoints when creating the service client as shown in:
    33  //	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    34  //	c, err := admin.NewIamClient(ctx)
    35  //	if err != nil {
    36  //		// TODO: Handle error.
    37  //	}
    38  //	defer c.Close()
    39  //
    40  // The client will use your default application credentials. Clients should be reused instead of created as needed.
    41  // The methods of Client are safe for concurrent use by multiple goroutines.
    42  // The returned client must be Closed when it is done being used.
    43  //
    44  // # Using the Client
    45  //
    46  // The following is an example of making an API call with the newly created client.
    47  //
    48  //	ctx := context.Background()
    49  //	// This snippet has been automatically generated and should be regarded as a code template only.
    50  //	// It will require modifications to work:
    51  //	// - It may require correct/in-range values for request initialization.
    52  //	// - It may require specifying regional endpoints when creating the service client as shown in:
    53  //	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    54  //	c, err := admin.NewIamClient(ctx)
    55  //	if err != nil {
    56  //		// TODO: Handle error.
    57  //	}
    58  //	defer c.Close()
    59  //
    60  //	req := &adminpb.ListServiceAccountsRequest{
    61  //		// TODO: Fill request struct fields.
    62  //		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/iam/admin/v1#ListServiceAccountsRequest.
    63  //	}
    64  //	it := c.ListServiceAccounts(ctx, req)
    65  //	for {
    66  //		resp, err := it.Next()
    67  //		if err == iterator.Done {
    68  //			break
    69  //		}
    70  //		if err != nil {
    71  //			// TODO: Handle error.
    72  //		}
    73  //		// TODO: Use resp.
    74  //		_ = resp
    75  //	}
    76  //
    77  // # Use of Context
    78  //
    79  // The ctx passed to NewIamClient is used for authentication requests and
    80  // for creating the underlying connection, but is not used for subsequent calls.
    81  // Individual methods on the client use the ctx given to them.
    82  //
    83  // To close the open connection, use the Close() method.
    84  //
    85  // For information about setting deadlines, reusing contexts, and more
    86  // please visit https://pkg.go.dev/cloud.google.com/go.
    87  package admin // import "cloud.google.com/go/iam/admin/apiv1"
    88  
    89  import (
    90  	"context"
    91  	"os"
    92  	"strconv"
    93  
    94  	"google.golang.org/api/option"
    95  	"google.golang.org/grpc/metadata"
    96  )
    97  
    98  // For more information on implementing a client constructor hook, see
    99  // https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
   100  type clientHookParams struct{}
   101  type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
   102  
   103  var versionClient string
   104  
   105  func getVersionClient() string {
   106  	if versionClient == "" {
   107  		return "UNKNOWN"
   108  	}
   109  	return versionClient
   110  }
   111  
   112  func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
   113  	out, _ := metadata.FromOutgoingContext(ctx)
   114  	out = out.Copy()
   115  	for _, md := range mds {
   116  		for k, v := range md {
   117  			out[k] = append(out[k], v...)
   118  		}
   119  	}
   120  	return metadata.NewOutgoingContext(ctx, out)
   121  }
   122  
   123  func checkDisableDeadlines() (bool, error) {
   124  	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
   125  	if !ok {
   126  		return false, nil
   127  	}
   128  
   129  	b, err := strconv.ParseBool(raw)
   130  	return b, err
   131  }
   132  
   133  // DefaultAuthScopes reports the default set of authentication scopes to use with this package.
   134  func DefaultAuthScopes() []string {
   135  	return []string{
   136  		"https://www.googleapis.com/auth/cloud-platform",
   137  	}
   138  }
   139  

View as plain text