Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

224 wiersze
8.1 KiB

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