You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

225 lines
8.2 KiB

  1. // Copyright 2018 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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package oslogin
  16. import (
  17. "time"
  18. "cloud.google.com/go/internal/version"
  19. gax "github.com/googleapis/gax-go"
  20. "golang.org/x/net/context"
  21. "google.golang.org/api/option"
  22. "google.golang.org/api/transport"
  23. commonpb "google.golang.org/genproto/googleapis/cloud/oslogin/common"
  24. osloginpb "google.golang.org/genproto/googleapis/cloud/oslogin/v1"
  25. "google.golang.org/grpc"
  26. "google.golang.org/grpc/codes"
  27. "google.golang.org/grpc/metadata"
  28. )
  29. // CallOptions contains the retry settings for each method of Client.
  30. type CallOptions struct {
  31. DeletePosixAccount []gax.CallOption
  32. DeleteSshPublicKey []gax.CallOption
  33. GetLoginProfile []gax.CallOption
  34. GetSshPublicKey []gax.CallOption
  35. ImportSshPublicKey []gax.CallOption
  36. UpdateSshPublicKey []gax.CallOption
  37. }
  38. func defaultClientOptions() []option.ClientOption {
  39. return []option.ClientOption{
  40. option.WithEndpoint("oslogin.googleapis.com:443"),
  41. option.WithScopes(DefaultAuthScopes()...),
  42. }
  43. }
  44. func defaultCallOptions() *CallOptions {
  45. retry := map[[2]string][]gax.CallOption{
  46. {"default", "idempotent"}: {
  47. gax.WithRetry(func() gax.Retryer {
  48. return gax.OnCodes([]codes.Code{
  49. codes.DeadlineExceeded,
  50. codes.Unavailable,
  51. }, gax.Backoff{
  52. Initial: 100 * time.Millisecond,
  53. Max: 60000 * time.Millisecond,
  54. Multiplier: 1.3,
  55. })
  56. }),
  57. },
  58. }
  59. return &CallOptions{
  60. DeletePosixAccount: retry[[2]string{"default", "idempotent"}],
  61. DeleteSshPublicKey: retry[[2]string{"default", "idempotent"}],
  62. GetLoginProfile: retry[[2]string{"default", "idempotent"}],
  63. GetSshPublicKey: retry[[2]string{"default", "idempotent"}],
  64. ImportSshPublicKey: retry[[2]string{"default", "idempotent"}],
  65. UpdateSshPublicKey: retry[[2]string{"default", "idempotent"}],
  66. }
  67. }
  68. // Client is a client for interacting with Google Cloud OS Login API.
  69. //
  70. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  71. type Client struct {
  72. // The connection to the service.
  73. conn *grpc.ClientConn
  74. // The gRPC API client.
  75. client osloginpb.OsLoginServiceClient
  76. // The call options for this service.
  77. CallOptions *CallOptions
  78. // The x-goog-* metadata to be sent with each request.
  79. xGoogMetadata metadata.MD
  80. }
  81. // NewClient creates a new os login service client.
  82. //
  83. // Cloud OS Login API
  84. //
  85. // The Cloud OS Login API allows you to manage users and their associated SSH
  86. // public keys for logging into virtual machines on Google Cloud Platform.
  87. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
  88. conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
  89. if err != nil {
  90. return nil, err
  91. }
  92. c := &Client{
  93. conn: conn,
  94. CallOptions: defaultCallOptions(),
  95. client: osloginpb.NewOsLoginServiceClient(conn),
  96. }
  97. c.setGoogleClientInfo()
  98. return c, nil
  99. }
  100. // Connection returns the client's connection to the API service.
  101. func (c *Client) Connection() *grpc.ClientConn {
  102. return c.conn
  103. }
  104. // Close closes the connection to the API service. The user should invoke this when
  105. // the client is no longer required.
  106. func (c *Client) Close() error {
  107. return c.conn.Close()
  108. }
  109. // setGoogleClientInfo sets the name and version of the application in
  110. // the `x-goog-api-client` header passed on each request. Intended for
  111. // use by Google-written clients.
  112. func (c *Client) setGoogleClientInfo(keyval ...string) {
  113. kv := append([]string{"gl-go", version.Go()}, keyval...)
  114. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  115. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  116. }
  117. // DeletePosixAccount deletes a POSIX account.
  118. func (c *Client) DeletePosixAccount(ctx context.Context, req *osloginpb.DeletePosixAccountRequest, opts ...gax.CallOption) error {
  119. ctx = insertMetadata(ctx, c.xGoogMetadata)
  120. opts = append(c.CallOptions.DeletePosixAccount[0:len(c.CallOptions.DeletePosixAccount):len(c.CallOptions.DeletePosixAccount)], opts...)
  121. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  122. var err error
  123. _, err = c.client.DeletePosixAccount(ctx, req, settings.GRPC...)
  124. return err
  125. }, opts...)
  126. return err
  127. }
  128. // DeleteSshPublicKey deletes an SSH public key.
  129. func (c *Client) DeleteSshPublicKey(ctx context.Context, req *osloginpb.DeleteSshPublicKeyRequest, opts ...gax.CallOption) error {
  130. ctx = insertMetadata(ctx, c.xGoogMetadata)
  131. opts = append(c.CallOptions.DeleteSshPublicKey[0:len(c.CallOptions.DeleteSshPublicKey):len(c.CallOptions.DeleteSshPublicKey)], opts...)
  132. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  133. var err error
  134. _, err = c.client.DeleteSshPublicKey(ctx, req, settings.GRPC...)
  135. return err
  136. }, opts...)
  137. return err
  138. }
  139. // GetLoginProfile retrieves the profile information used for logging in to a virtual machine
  140. // on Google Compute Engine.
  141. func (c *Client) GetLoginProfile(ctx context.Context, req *osloginpb.GetLoginProfileRequest, opts ...gax.CallOption) (*osloginpb.LoginProfile, error) {
  142. ctx = insertMetadata(ctx, c.xGoogMetadata)
  143. opts = append(c.CallOptions.GetLoginProfile[0:len(c.CallOptions.GetLoginProfile):len(c.CallOptions.GetLoginProfile)], opts...)
  144. var resp *osloginpb.LoginProfile
  145. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  146. var err error
  147. resp, err = c.client.GetLoginProfile(ctx, req, settings.GRPC...)
  148. return err
  149. }, opts...)
  150. if err != nil {
  151. return nil, err
  152. }
  153. return resp, nil
  154. }
  155. // GetSshPublicKey retrieves an SSH public key.
  156. func (c *Client) GetSshPublicKey(ctx context.Context, req *osloginpb.GetSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
  157. ctx = insertMetadata(ctx, c.xGoogMetadata)
  158. opts = append(c.CallOptions.GetSshPublicKey[0:len(c.CallOptions.GetSshPublicKey):len(c.CallOptions.GetSshPublicKey)], opts...)
  159. var resp *commonpb.SshPublicKey
  160. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  161. var err error
  162. resp, err = c.client.GetSshPublicKey(ctx, req, settings.GRPC...)
  163. return err
  164. }, opts...)
  165. if err != nil {
  166. return nil, err
  167. }
  168. return resp, nil
  169. }
  170. // ImportSshPublicKey adds an SSH public key and returns the profile information. Default POSIX
  171. // account information is set when no username and UID exist as part of the
  172. // login profile.
  173. func (c *Client) ImportSshPublicKey(ctx context.Context, req *osloginpb.ImportSshPublicKeyRequest, opts ...gax.CallOption) (*osloginpb.ImportSshPublicKeyResponse, error) {
  174. ctx = insertMetadata(ctx, c.xGoogMetadata)
  175. opts = append(c.CallOptions.ImportSshPublicKey[0:len(c.CallOptions.ImportSshPublicKey):len(c.CallOptions.ImportSshPublicKey)], opts...)
  176. var resp *osloginpb.ImportSshPublicKeyResponse
  177. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  178. var err error
  179. resp, err = c.client.ImportSshPublicKey(ctx, req, settings.GRPC...)
  180. return err
  181. }, opts...)
  182. if err != nil {
  183. return nil, err
  184. }
  185. return resp, nil
  186. }
  187. // UpdateSshPublicKey updates an SSH public key and returns the profile information. This method
  188. // supports patch semantics.
  189. func (c *Client) UpdateSshPublicKey(ctx context.Context, req *osloginpb.UpdateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
  190. ctx = insertMetadata(ctx, c.xGoogMetadata)
  191. opts = append(c.CallOptions.UpdateSshPublicKey[0:len(c.CallOptions.UpdateSshPublicKey):len(c.CallOptions.UpdateSshPublicKey)], opts...)
  192. var resp *commonpb.SshPublicKey
  193. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  194. var err error
  195. resp, err = c.client.UpdateSshPublicKey(ctx, req, settings.GRPC...)
  196. return err
  197. }, opts...)
  198. if err != nil {
  199. return nil, err
  200. }
  201. return resp, nil
  202. }