google-cloud-os_login 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,429 @@
1
+ # Copyright 2017 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
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/cloud/oslogin/v1beta/oslogin.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+ #
22
+ # The only allowed edits are to method and file documentation. A 3-way
23
+ # merge preserves those additions if the generated source changes.
24
+
25
+ require "json"
26
+ require "pathname"
27
+
28
+ require "google/gax"
29
+
30
+ require "google/cloud/oslogin/v1beta/oslogin_pb"
31
+ require "google/cloud/os_login/credentials"
32
+
33
+ module Google
34
+ module Cloud
35
+ module OsLogin
36
+ module V1beta
37
+ # Cloud OS Login API
38
+ #
39
+ # The Cloud OS Login API allows you to manage users and their associated SSH
40
+ # public keys for logging into virtual machines on Google Cloud Platform.
41
+ #
42
+ # @!attribute [r] os_login_service_stub
43
+ # @return [Google::Cloud::Oslogin::V1beta::OsLoginService::Stub]
44
+ class OsLoginServiceClient
45
+ attr_reader :os_login_service_stub
46
+
47
+ # The default address of the service.
48
+ SERVICE_ADDRESS = "oslogin.googleapis.com".freeze
49
+
50
+ # The default port of the service.
51
+ DEFAULT_SERVICE_PORT = 443
52
+
53
+ DEFAULT_TIMEOUT = 30
54
+
55
+ # The scopes needed to make gRPC calls to all of the methods defined in
56
+ # this service.
57
+ ALL_SCOPES = [
58
+ "https://www.googleapis.com/auth/cloud-platform",
59
+ "https://www.googleapis.com/auth/cloud-platform.read-only",
60
+ "https://www.googleapis.com/auth/compute",
61
+ "https://www.googleapis.com/auth/compute.readonly"
62
+ ].freeze
63
+
64
+
65
+ USER_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
66
+ "users/{user}"
67
+ )
68
+
69
+ private_constant :USER_PATH_TEMPLATE
70
+
71
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
72
+ "users/{user}/projects/{project}"
73
+ )
74
+
75
+ private_constant :PROJECT_PATH_TEMPLATE
76
+
77
+ FINGERPRINT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
78
+ "users/{user}/sshPublicKeys/{fingerprint}"
79
+ )
80
+
81
+ private_constant :FINGERPRINT_PATH_TEMPLATE
82
+
83
+ # Returns a fully-qualified user resource name string.
84
+ # @param user [String]
85
+ # @return [String]
86
+ def self.user_path user
87
+ USER_PATH_TEMPLATE.render(
88
+ :"user" => user
89
+ )
90
+ end
91
+
92
+ # Returns a fully-qualified project resource name string.
93
+ # @param user [String]
94
+ # @param project [String]
95
+ # @return [String]
96
+ def self.project_path user, project
97
+ PROJECT_PATH_TEMPLATE.render(
98
+ :"user" => user,
99
+ :"project" => project
100
+ )
101
+ end
102
+
103
+ # Returns a fully-qualified fingerprint resource name string.
104
+ # @param user [String]
105
+ # @param fingerprint [String]
106
+ # @return [String]
107
+ def self.fingerprint_path user, fingerprint
108
+ FINGERPRINT_PATH_TEMPLATE.render(
109
+ :"user" => user,
110
+ :"fingerprint" => fingerprint
111
+ )
112
+ end
113
+
114
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
115
+ # Provides the means for authenticating requests made by the client. This parameter can
116
+ # be many types.
117
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
118
+ # authenticating requests made by this client.
119
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
120
+ # credentials for this client.
121
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
122
+ # credentials for this client.
123
+ # A `GRPC::Core::Channel` will be used to make calls through.
124
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
125
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
126
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
127
+ # metadata for requests, generally, to give OAuth credentials.
128
+ # @param scopes [Array<String>]
129
+ # The OAuth scopes for this service. This parameter is ignored if
130
+ # an updater_proc is supplied.
131
+ # @param client_config [Hash]
132
+ # A Hash for call options for each method. See
133
+ # Google::Gax#construct_settings for the structure of
134
+ # this data. Falls back to the default config if not specified
135
+ # or the specified config is missing data points.
136
+ # @param timeout [Numeric]
137
+ # The default timeout, in seconds, for calls made through this client.
138
+ def initialize \
139
+ credentials: nil,
140
+ scopes: ALL_SCOPES,
141
+ client_config: {},
142
+ timeout: DEFAULT_TIMEOUT,
143
+ lib_name: nil,
144
+ lib_version: ""
145
+ # These require statements are intentionally placed here to initialize
146
+ # the gRPC module only when it's required.
147
+ # See https://github.com/googleapis/toolkit/issues/446
148
+ require "google/gax/grpc"
149
+ require "google/cloud/oslogin/v1beta/oslogin_services_pb"
150
+
151
+ credentials ||= Google::Cloud::OsLogin::Credentials.default
152
+
153
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
154
+ updater_proc = Google::Cloud::OsLogin::Credentials.new(credentials).updater_proc
155
+ end
156
+ if credentials.is_a?(GRPC::Core::Channel)
157
+ channel = credentials
158
+ end
159
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
160
+ chan_creds = credentials
161
+ end
162
+ if credentials.is_a?(Proc)
163
+ updater_proc = credentials
164
+ end
165
+ if credentials.is_a?(Google::Auth::Credentials)
166
+ updater_proc = credentials.updater_proc
167
+ end
168
+
169
+ package_version = Gem.loaded_specs['google-cloud-os_login'].version.version
170
+
171
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
172
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
173
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
174
+ google_api_client << " grpc/#{GRPC::VERSION}"
175
+ google_api_client.freeze
176
+
177
+ headers = { :"x-goog-api-client" => google_api_client }
178
+ client_config_file = Pathname.new(__dir__).join(
179
+ "os_login_service_client_config.json"
180
+ )
181
+ defaults = client_config_file.open do |f|
182
+ Google::Gax.construct_settings(
183
+ "google.cloud.oslogin.v1beta.OsLoginService",
184
+ JSON.parse(f.read),
185
+ client_config,
186
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
187
+ timeout,
188
+ errors: Google::Gax::Grpc::API_ERRORS,
189
+ kwargs: headers
190
+ )
191
+ end
192
+
193
+ # Allow overriding the service path/port in subclasses.
194
+ service_path = self.class::SERVICE_ADDRESS
195
+ port = self.class::DEFAULT_SERVICE_PORT
196
+ @os_login_service_stub = Google::Gax::Grpc.create_stub(
197
+ service_path,
198
+ port,
199
+ chan_creds: chan_creds,
200
+ channel: channel,
201
+ updater_proc: updater_proc,
202
+ scopes: scopes,
203
+ &Google::Cloud::Oslogin::V1beta::OsLoginService::Stub.method(:new)
204
+ )
205
+
206
+ @delete_posix_account = Google::Gax.create_api_call(
207
+ @os_login_service_stub.method(:delete_posix_account),
208
+ defaults["delete_posix_account"]
209
+ )
210
+ @delete_ssh_public_key = Google::Gax.create_api_call(
211
+ @os_login_service_stub.method(:delete_ssh_public_key),
212
+ defaults["delete_ssh_public_key"]
213
+ )
214
+ @get_login_profile = Google::Gax.create_api_call(
215
+ @os_login_service_stub.method(:get_login_profile),
216
+ defaults["get_login_profile"]
217
+ )
218
+ @get_ssh_public_key = Google::Gax.create_api_call(
219
+ @os_login_service_stub.method(:get_ssh_public_key),
220
+ defaults["get_ssh_public_key"]
221
+ )
222
+ @import_ssh_public_key = Google::Gax.create_api_call(
223
+ @os_login_service_stub.method(:import_ssh_public_key),
224
+ defaults["import_ssh_public_key"]
225
+ )
226
+ @update_ssh_public_key = Google::Gax.create_api_call(
227
+ @os_login_service_stub.method(:update_ssh_public_key),
228
+ defaults["update_ssh_public_key"]
229
+ )
230
+ end
231
+
232
+ # Service calls
233
+
234
+ # Deletes a POSIX account.
235
+ #
236
+ # @param name [String]
237
+ # A reference to the POSIX account to update. POSIX accounts are identified
238
+ # by the project ID they are associated with. A reference to the POSIX
239
+ # account is in format +users/{user}/projects/{project}+.
240
+ # @param options [Google::Gax::CallOptions]
241
+ # Overrides the default settings for this call, e.g, timeout,
242
+ # retries, etc.
243
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
244
+ # @example
245
+ # require "google/cloud/os_login/v1beta"
246
+ #
247
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
248
+ # formatted_name = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.project_path("[USER]", "[PROJECT]")
249
+ # os_login_service_client.delete_posix_account(formatted_name)
250
+
251
+ def delete_posix_account \
252
+ name,
253
+ options: nil
254
+ req = {
255
+ name: name
256
+ }.delete_if { |_, v| v.nil? }
257
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::DeletePosixAccountRequest)
258
+ @delete_posix_account.call(req, options)
259
+ nil
260
+ end
261
+
262
+ # Deletes an SSH public key.
263
+ #
264
+ # @param name [String]
265
+ # The fingerprint of the public key to update. Public keys are identified by
266
+ # their SHA-256 fingerprint. The fingerprint of the public key is in format
267
+ # +users/{user}/sshPublicKeys/{fingerprint}+.
268
+ # @param options [Google::Gax::CallOptions]
269
+ # Overrides the default settings for this call, e.g, timeout,
270
+ # retries, etc.
271
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
272
+ # @example
273
+ # require "google/cloud/os_login/v1beta"
274
+ #
275
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
276
+ # formatted_name = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.fingerprint_path("[USER]", "[FINGERPRINT]")
277
+ # os_login_service_client.delete_ssh_public_key(formatted_name)
278
+
279
+ def delete_ssh_public_key \
280
+ name,
281
+ options: nil
282
+ req = {
283
+ name: name
284
+ }.delete_if { |_, v| v.nil? }
285
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::DeleteSshPublicKeyRequest)
286
+ @delete_ssh_public_key.call(req, options)
287
+ nil
288
+ end
289
+
290
+ # Retrieves the profile information used for logging in to a virtual machine
291
+ # on Google Compute Engine.
292
+ #
293
+ # @param name [String]
294
+ # The unique ID for the user in format +users/{user}+.
295
+ # @param options [Google::Gax::CallOptions]
296
+ # Overrides the default settings for this call, e.g, timeout,
297
+ # retries, etc.
298
+ # @return [Google::Cloud::Oslogin::V1beta::LoginProfile]
299
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
300
+ # @example
301
+ # require "google/cloud/os_login/v1beta"
302
+ #
303
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
304
+ # formatted_name = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.user_path("[USER]")
305
+ # response = os_login_service_client.get_login_profile(formatted_name)
306
+
307
+ def get_login_profile \
308
+ name,
309
+ options: nil
310
+ req = {
311
+ name: name
312
+ }.delete_if { |_, v| v.nil? }
313
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::GetLoginProfileRequest)
314
+ @get_login_profile.call(req, options)
315
+ end
316
+
317
+ # Retrieves an SSH public key.
318
+ #
319
+ # @param name [String]
320
+ # The fingerprint of the public key to retrieve. Public keys are identified
321
+ # by their SHA-256 fingerprint. The fingerprint of the public key is in
322
+ # format +users/{user}/sshPublicKeys/{fingerprint}+.
323
+ # @param options [Google::Gax::CallOptions]
324
+ # Overrides the default settings for this call, e.g, timeout,
325
+ # retries, etc.
326
+ # @return [Google::Cloud::Oslogin::Common::SshPublicKey]
327
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
328
+ # @example
329
+ # require "google/cloud/os_login/v1beta"
330
+ #
331
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
332
+ # formatted_name = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.fingerprint_path("[USER]", "[FINGERPRINT]")
333
+ # response = os_login_service_client.get_ssh_public_key(formatted_name)
334
+
335
+ def get_ssh_public_key \
336
+ name,
337
+ options: nil
338
+ req = {
339
+ name: name
340
+ }.delete_if { |_, v| v.nil? }
341
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::GetSshPublicKeyRequest)
342
+ @get_ssh_public_key.call(req, options)
343
+ end
344
+
345
+ # Adds an SSH public key and returns the profile information. Default POSIX
346
+ # account information is set when no username and UID exist as part of the
347
+ # login profile.
348
+ #
349
+ # @param parent [String]
350
+ # The unique ID for the user in format +users/{user}+.
351
+ # @param ssh_public_key [Google::Cloud::Oslogin::Common::SshPublicKey | Hash]
352
+ # The SSH public key and expiration time.
353
+ # A hash of the same form as `Google::Cloud::Oslogin::Common::SshPublicKey`
354
+ # can also be provided.
355
+ # @param project_id [String]
356
+ # The project ID of the Google Cloud Platform project.
357
+ # @param options [Google::Gax::CallOptions]
358
+ # Overrides the default settings for this call, e.g, timeout,
359
+ # retries, etc.
360
+ # @return [Google::Cloud::Oslogin::V1beta::ImportSshPublicKeyResponse]
361
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
362
+ # @example
363
+ # require "google/cloud/os_login/v1beta"
364
+ #
365
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
366
+ # formatted_parent = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.user_path("[USER]")
367
+ # ssh_public_key = {}
368
+ # response = os_login_service_client.import_ssh_public_key(formatted_parent, ssh_public_key)
369
+
370
+ def import_ssh_public_key \
371
+ parent,
372
+ ssh_public_key,
373
+ project_id: nil,
374
+ options: nil
375
+ req = {
376
+ parent: parent,
377
+ ssh_public_key: ssh_public_key,
378
+ project_id: project_id
379
+ }.delete_if { |_, v| v.nil? }
380
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::ImportSshPublicKeyRequest)
381
+ @import_ssh_public_key.call(req, options)
382
+ end
383
+
384
+ # Updates an SSH public key and returns the profile information. This method
385
+ # supports patch semantics.
386
+ #
387
+ # @param name [String]
388
+ # The fingerprint of the public key to update. Public keys are identified by
389
+ # their SHA-256 fingerprint. The fingerprint of the public key is in format
390
+ # +users/{user}/sshPublicKeys/{fingerprint}+.
391
+ # @param ssh_public_key [Google::Cloud::Oslogin::Common::SshPublicKey | Hash]
392
+ # The SSH public key and expiration time.
393
+ # A hash of the same form as `Google::Cloud::Oslogin::Common::SshPublicKey`
394
+ # can also be provided.
395
+ # @param update_mask [Google::Protobuf::FieldMask | Hash]
396
+ # Mask to control which fields get updated. Updates all if not present.
397
+ # A hash of the same form as `Google::Protobuf::FieldMask`
398
+ # can also be provided.
399
+ # @param options [Google::Gax::CallOptions]
400
+ # Overrides the default settings for this call, e.g, timeout,
401
+ # retries, etc.
402
+ # @return [Google::Cloud::Oslogin::Common::SshPublicKey]
403
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
404
+ # @example
405
+ # require "google/cloud/os_login/v1beta"
406
+ #
407
+ # os_login_service_client = Google::Cloud::OsLogin::V1beta.new
408
+ # formatted_name = Google::Cloud::OsLogin::V1beta::OsLoginServiceClient.fingerprint_path("[USER]", "[FINGERPRINT]")
409
+ # ssh_public_key = {}
410
+ # response = os_login_service_client.update_ssh_public_key(formatted_name, ssh_public_key)
411
+
412
+ def update_ssh_public_key \
413
+ name,
414
+ ssh_public_key,
415
+ update_mask: nil,
416
+ options: nil
417
+ req = {
418
+ name: name,
419
+ ssh_public_key: ssh_public_key,
420
+ update_mask: update_mask
421
+ }.delete_if { |_, v| v.nil? }
422
+ req = Google::Gax::to_proto(req, Google::Cloud::Oslogin::V1beta::UpdateSshPublicKeyRequest)
423
+ @update_ssh_public_key.call(req, options)
424
+ end
425
+ end
426
+ end
427
+ end
428
+ end
429
+ end
@@ -0,0 +1,56 @@
1
+ {
2
+ "interfaces": {
3
+ "google.cloud.oslogin.v1beta.OsLoginService": {
4
+ "retry_codes": {
5
+ "idempotent": [
6
+ "DEADLINE_EXCEEDED",
7
+ "UNAVAILABLE"
8
+ ],
9
+ "non_idempotent": []
10
+ },
11
+ "retry_params": {
12
+ "default": {
13
+ "initial_retry_delay_millis": 100,
14
+ "retry_delay_multiplier": 1.3,
15
+ "max_retry_delay_millis": 60000,
16
+ "initial_rpc_timeout_millis": 10000,
17
+ "rpc_timeout_multiplier": 1.0,
18
+ "max_rpc_timeout_millis": 10000,
19
+ "total_timeout_millis": 600000
20
+ }
21
+ },
22
+ "methods": {
23
+ "DeletePosixAccount": {
24
+ "timeout_millis": 10000,
25
+ "retry_codes_name": "idempotent",
26
+ "retry_params_name": "default"
27
+ },
28
+ "DeleteSshPublicKey": {
29
+ "timeout_millis": 10000,
30
+ "retry_codes_name": "idempotent",
31
+ "retry_params_name": "default"
32
+ },
33
+ "GetLoginProfile": {
34
+ "timeout_millis": 10000,
35
+ "retry_codes_name": "idempotent",
36
+ "retry_params_name": "default"
37
+ },
38
+ "GetSshPublicKey": {
39
+ "timeout_millis": 10000,
40
+ "retry_codes_name": "idempotent",
41
+ "retry_params_name": "default"
42
+ },
43
+ "ImportSshPublicKey": {
44
+ "timeout_millis": 10000,
45
+ "retry_codes_name": "idempotent",
46
+ "retry_params_name": "default"
47
+ },
48
+ "UpdateSshPublicKey": {
49
+ "timeout_millis": 10000,
50
+ "retry_codes_name": "idempotent",
51
+ "retry_params_name": "default"
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }