ibm_cloud_iam 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/README.md +131 -0
- data/Rakefile +10 -0
- data/docs/ApiKey.md +43 -0
- data/docs/ApiKeyInsideCreateServiceIdRequest.md +23 -0
- data/docs/ApiKeyList.md +29 -0
- data/docs/CreateApiKeyRequest.md +27 -0
- data/docs/CreateServiceIdRequest.md +25 -0
- data/docs/EnityHistoryRecord.md +27 -0
- data/docs/Error.md +23 -0
- data/docs/ExceptionResponse.md +23 -0
- data/docs/ExceptionResponseContext.md +39 -0
- data/docs/IdentityOperationsApi.md +828 -0
- data/docs/InlineObject.md +19 -0
- data/docs/InlineObject1.md +23 -0
- data/docs/InlineObject2.md +21 -0
- data/docs/InlineObject3.md +25 -0
- data/docs/MFARequirementsResponse.md +21 -0
- data/docs/OidcExceptionResponse.md +25 -0
- data/docs/ResponseContext.md +37 -0
- data/docs/ServiceId.md +43 -0
- data/docs/ServiceIdList.md +29 -0
- data/docs/TokenOperationsApi.md +226 -0
- data/docs/TokenResponse.md +27 -0
- data/docs/UpdateApiKeyRequest.md +19 -0
- data/docs/UpdateServiceIdRequest.md +21 -0
- data/git_push.sh +58 -0
- data/ibm_cloud_iam-1.0.0.gem +0 -0
- data/ibm_cloud_iam.gemspec +38 -0
- data/lib/ibm_cloud_iam.rb +62 -0
- data/lib/ibm_cloud_iam/api/identity_operations_api.rb +1083 -0
- data/lib/ibm_cloud_iam/api/token_operations_api.rb +351 -0
- data/lib/ibm_cloud_iam/api_client.rb +387 -0
- data/lib/ibm_cloud_iam/api_error.rb +57 -0
- data/lib/ibm_cloud_iam/configuration.rb +241 -0
- data/lib/ibm_cloud_iam/models/api_key.rb +381 -0
- data/lib/ibm_cloud_iam/models/api_key_inside_create_service_id_request.rb +245 -0
- data/lib/ibm_cloud_iam/models/api_key_list.rb +276 -0
- data/lib/ibm_cloud_iam/models/create_api_key_request.rb +270 -0
- data/lib/ibm_cloud_iam/models/create_service_id_request.rb +261 -0
- data/lib/ibm_cloud_iam/models/enity_history_record.rb +292 -0
- data/lib/ibm_cloud_iam/models/error.rb +255 -0
- data/lib/ibm_cloud_iam/models/exception_response.rb +251 -0
- data/lib/ibm_cloud_iam/models/exception_response_context.rb +320 -0
- data/lib/ibm_cloud_iam/models/inline_object.rb +229 -0
- data/lib/ibm_cloud_iam/models/inline_object1.rb +254 -0
- data/lib/ibm_cloud_iam/models/inline_object2.rb +244 -0
- data/lib/ibm_cloud_iam/models/inline_object3.rb +269 -0
- data/lib/ibm_cloud_iam/models/mfa_requirements_response.rb +245 -0
- data/lib/ibm_cloud_iam/models/oidc_exception_response.rb +258 -0
- data/lib/ibm_cloud_iam/models/response_context.rb +310 -0
- data/lib/ibm_cloud_iam/models/service_id.rb +377 -0
- data/lib/ibm_cloud_iam/models/service_id_list.rb +276 -0
- data/lib/ibm_cloud_iam/models/token_response.rb +260 -0
- data/lib/ibm_cloud_iam/models/update_api_key_request.rb +220 -0
- data/lib/ibm_cloud_iam/models/update_service_id_request.rb +232 -0
- data/lib/ibm_cloud_iam/version.rb +15 -0
- data/spec/api/identity_operations_api_spec.rb +253 -0
- data/spec/api/token_operations_api_spec.rb +94 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/api_key_inside_create_service_id_request_spec.rb +59 -0
- data/spec/models/api_key_list_spec.rb +77 -0
- data/spec/models/api_key_spec.rb +119 -0
- data/spec/models/create_api_key_request_spec.rb +71 -0
- data/spec/models/create_service_id_request_spec.rb +65 -0
- data/spec/models/enity_history_record_spec.rb +71 -0
- data/spec/models/error_spec.rb +59 -0
- data/spec/models/exception_response_context_spec.rb +107 -0
- data/spec/models/exception_response_spec.rb +59 -0
- data/spec/models/inline_object1_spec.rb +59 -0
- data/spec/models/inline_object2_spec.rb +53 -0
- data/spec/models/inline_object3_spec.rb +65 -0
- data/spec/models/inline_object_spec.rb +47 -0
- data/spec/models/mfa_requirements_response_spec.rb +53 -0
- data/spec/models/oidc_exception_response_spec.rb +65 -0
- data/spec/models/response_context_spec.rb +101 -0
- data/spec/models/service_id_list_spec.rb +77 -0
- data/spec/models/service_id_spec.rb +119 -0
- data/spec/models/token_response_spec.rb +71 -0
- data/spec/models/update_api_key_request_spec.rb +47 -0
- data/spec/models/update_service_id_request_spec.rb +53 -0
- data/spec/spec_helper.rb +111 -0
- metadata +192 -0
@@ -0,0 +1,351 @@
|
|
1
|
+
=begin
|
2
|
+
#IAM Identity Services API
|
3
|
+
|
4
|
+
#The IAM Identity Service API allows for the management of Identities (Service IDs, ApiKeys).
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.0.0-beta2
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module IbmCloudIam
|
16
|
+
class TokenOperationsApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# Create an IAM access token for a user or service ID using an API key
|
23
|
+
# Creates a non-opaque access token for an API key.
|
24
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:apikey`.
|
25
|
+
# @param apikey [String] The value of the api key
|
26
|
+
# @param [Hash] opts the optional parameters
|
27
|
+
# @return [TokenResponse]
|
28
|
+
def get_token_api_key(grant_type, apikey, opts = {})
|
29
|
+
data, _status_code, _headers = get_token_api_key_with_http_info(grant_type, apikey, opts)
|
30
|
+
data
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create an IAM access token for a user or service ID using an API key
|
34
|
+
# Creates a non-opaque access token for an API key.
|
35
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:apikey`.
|
36
|
+
# @param apikey [String] The value of the api key
|
37
|
+
# @param [Hash] opts the optional parameters
|
38
|
+
# @return [Array<(TokenResponse, Integer, Hash)>] TokenResponse data, response status code and response headers
|
39
|
+
def get_token_api_key_with_http_info(grant_type, apikey, opts = {})
|
40
|
+
if @api_client.config.debugging
|
41
|
+
@api_client.config.logger.debug 'Calling API: TokenOperationsApi.get_token_api_key ...'
|
42
|
+
end
|
43
|
+
# verify the required parameter 'grant_type' is set
|
44
|
+
if @api_client.config.client_side_validation && grant_type.nil?
|
45
|
+
fail ArgumentError, "Missing the required parameter 'grant_type' when calling TokenOperationsApi.get_token_api_key"
|
46
|
+
end
|
47
|
+
# verify the required parameter 'apikey' is set
|
48
|
+
if @api_client.config.client_side_validation && apikey.nil?
|
49
|
+
fail ArgumentError, "Missing the required parameter 'apikey' when calling TokenOperationsApi.get_token_api_key"
|
50
|
+
end
|
51
|
+
# resource path
|
52
|
+
local_var_path = '/identity/token#apikey'
|
53
|
+
|
54
|
+
# query parameters
|
55
|
+
query_params = opts[:query_params] || {}
|
56
|
+
|
57
|
+
# header parameters
|
58
|
+
header_params = opts[:header_params] || {}
|
59
|
+
# HTTP header 'Accept' (if needed)
|
60
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
61
|
+
# HTTP header 'Content-Type'
|
62
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
|
63
|
+
|
64
|
+
# form parameters
|
65
|
+
form_params = opts[:form_params] || {}
|
66
|
+
form_params['grant_type'] = grant_type
|
67
|
+
form_params['apikey'] = apikey
|
68
|
+
|
69
|
+
# http body (model)
|
70
|
+
post_body = opts[:body]
|
71
|
+
|
72
|
+
# return_type
|
73
|
+
return_type = opts[:return_type] || 'TokenResponse'
|
74
|
+
|
75
|
+
# auth_names
|
76
|
+
auth_names = opts[:auth_names] || []
|
77
|
+
|
78
|
+
new_options = opts.merge(
|
79
|
+
:header_params => header_params,
|
80
|
+
:query_params => query_params,
|
81
|
+
:form_params => form_params,
|
82
|
+
:body => post_body,
|
83
|
+
:auth_names => auth_names,
|
84
|
+
:return_type => return_type
|
85
|
+
)
|
86
|
+
|
87
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
88
|
+
if @api_client.config.debugging
|
89
|
+
@api_client.config.logger.debug "API called: TokenOperationsApi#get_token_api_key\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
90
|
+
end
|
91
|
+
return data, status_code, headers
|
92
|
+
end
|
93
|
+
|
94
|
+
# Create an IAM access token and delegated refresh token for a user or service ID
|
95
|
+
# Creates a non-opaque access token and a delegated refresh token for an API key.
|
96
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:apikey`.
|
97
|
+
# @param apikey [String] The value of the API key.
|
98
|
+
# @param response_type [String] Either 'delegated_refresh_token' to receive a delegated refresh token only, or 'cloud_iam delegated_refresh_token' to receive both an IAM access token and a delegated refresh token in one API call.
|
99
|
+
# @param receiver_client_ids [String] A comma separated list of one or more client IDs that will be able to consume the delegated refresh token. The service that accepts a delegated refresh token as API parameter must expose its client ID to allow this API call. The receiver of the delegated refresh token will be able to use the refresh token until it expires.
|
100
|
+
# @param [Hash] opts the optional parameters
|
101
|
+
# @option opts [Integer] :delegated_refresh_token_expiry Expiration in seconds until the delegated refresh token must be consumed by the receiver client IDs. After the expiration, no client ID can consume the delegated refresh token, even if the life time of the refresh token inside is still not expired. The default, if not specified, is 518,400 seconds which corresponds to 6 days.
|
102
|
+
# @return [TokenResponse]
|
103
|
+
def get_token_api_key_delegated_refresh_token(grant_type, apikey, response_type, receiver_client_ids, opts = {})
|
104
|
+
data, _status_code, _headers = get_token_api_key_delegated_refresh_token_with_http_info(grant_type, apikey, response_type, receiver_client_ids, opts)
|
105
|
+
data
|
106
|
+
end
|
107
|
+
|
108
|
+
# Create an IAM access token and delegated refresh token for a user or service ID
|
109
|
+
# Creates a non-opaque access token and a delegated refresh token for an API key.
|
110
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:apikey`.
|
111
|
+
# @param apikey [String] The value of the API key.
|
112
|
+
# @param response_type [String] Either 'delegated_refresh_token' to receive a delegated refresh token only, or 'cloud_iam delegated_refresh_token' to receive both an IAM access token and a delegated refresh token in one API call.
|
113
|
+
# @param receiver_client_ids [String] A comma separated list of one or more client IDs that will be able to consume the delegated refresh token. The service that accepts a delegated refresh token as API parameter must expose its client ID to allow this API call. The receiver of the delegated refresh token will be able to use the refresh token until it expires.
|
114
|
+
# @param [Hash] opts the optional parameters
|
115
|
+
# @option opts [Integer] :delegated_refresh_token_expiry Expiration in seconds until the delegated refresh token must be consumed by the receiver client IDs. After the expiration, no client ID can consume the delegated refresh token, even if the life time of the refresh token inside is still not expired. The default, if not specified, is 518,400 seconds which corresponds to 6 days.
|
116
|
+
# @return [Array<(TokenResponse, Integer, Hash)>] TokenResponse data, response status code and response headers
|
117
|
+
def get_token_api_key_delegated_refresh_token_with_http_info(grant_type, apikey, response_type, receiver_client_ids, opts = {})
|
118
|
+
if @api_client.config.debugging
|
119
|
+
@api_client.config.logger.debug 'Calling API: TokenOperationsApi.get_token_api_key_delegated_refresh_token ...'
|
120
|
+
end
|
121
|
+
# verify the required parameter 'grant_type' is set
|
122
|
+
if @api_client.config.client_side_validation && grant_type.nil?
|
123
|
+
fail ArgumentError, "Missing the required parameter 'grant_type' when calling TokenOperationsApi.get_token_api_key_delegated_refresh_token"
|
124
|
+
end
|
125
|
+
# verify the required parameter 'apikey' is set
|
126
|
+
if @api_client.config.client_side_validation && apikey.nil?
|
127
|
+
fail ArgumentError, "Missing the required parameter 'apikey' when calling TokenOperationsApi.get_token_api_key_delegated_refresh_token"
|
128
|
+
end
|
129
|
+
# verify the required parameter 'response_type' is set
|
130
|
+
if @api_client.config.client_side_validation && response_type.nil?
|
131
|
+
fail ArgumentError, "Missing the required parameter 'response_type' when calling TokenOperationsApi.get_token_api_key_delegated_refresh_token"
|
132
|
+
end
|
133
|
+
# verify the required parameter 'receiver_client_ids' is set
|
134
|
+
if @api_client.config.client_side_validation && receiver_client_ids.nil?
|
135
|
+
fail ArgumentError, "Missing the required parameter 'receiver_client_ids' when calling TokenOperationsApi.get_token_api_key_delegated_refresh_token"
|
136
|
+
end
|
137
|
+
# resource path
|
138
|
+
local_var_path = '/identity/token#apikey-delegated-refresh-token'
|
139
|
+
|
140
|
+
# query parameters
|
141
|
+
query_params = opts[:query_params] || {}
|
142
|
+
|
143
|
+
# header parameters
|
144
|
+
header_params = opts[:header_params] || {}
|
145
|
+
# HTTP header 'Accept' (if needed)
|
146
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
147
|
+
# HTTP header 'Content-Type'
|
148
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
|
149
|
+
|
150
|
+
# form parameters
|
151
|
+
form_params = opts[:form_params] || {}
|
152
|
+
form_params['grant_type'] = grant_type
|
153
|
+
form_params['apikey'] = apikey
|
154
|
+
form_params['response_type'] = response_type
|
155
|
+
form_params['receiver_client_ids'] = receiver_client_ids
|
156
|
+
form_params['delegated_refresh_token_expiry'] = opts[:'delegated_refresh_token_expiry'] if !opts[:'delegated_refresh_token_expiry'].nil?
|
157
|
+
|
158
|
+
# http body (model)
|
159
|
+
post_body = opts[:body]
|
160
|
+
|
161
|
+
# return_type
|
162
|
+
return_type = opts[:return_type] || 'TokenResponse'
|
163
|
+
|
164
|
+
# auth_names
|
165
|
+
auth_names = opts[:auth_names] || []
|
166
|
+
|
167
|
+
new_options = opts.merge(
|
168
|
+
:header_params => header_params,
|
169
|
+
:query_params => query_params,
|
170
|
+
:form_params => form_params,
|
171
|
+
:body => post_body,
|
172
|
+
:auth_names => auth_names,
|
173
|
+
:return_type => return_type
|
174
|
+
)
|
175
|
+
|
176
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
177
|
+
if @api_client.config.debugging
|
178
|
+
@api_client.config.logger.debug "API called: TokenOperationsApi#get_token_api_key_delegated_refresh_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
179
|
+
end
|
180
|
+
return data, status_code, headers
|
181
|
+
end
|
182
|
+
|
183
|
+
# Create an IAM access token based on an authorization policy
|
184
|
+
# Creates a non-opaque access token, if an appropriate authorization policy is in place. This kind of IAM access token is typically used for access between services.
|
185
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:iam-authz`.
|
186
|
+
# @param access_token [String] The IAM access token of the identity that has the appropriate authorization to create an IAM access token for a given resource.
|
187
|
+
# @param desired_iam_id [String] The IAM ID of the IAM access token identity that should be created. The desired_iam_id identifies a resource identity. The IAM ID consists of the prefix crn- and the CRN of the target identity, e.g. crn-crn:v1:bluemix:public:cloud-object-storage:global:a/59bcbfa6ea2f006b4ed7094c1a08dcdd:1a0ec336-f391-4091-a6fb-5e084a4c56f4::.
|
188
|
+
# @param [Hash] opts the optional parameters
|
189
|
+
# @return [TokenResponse]
|
190
|
+
def get_token_iam_authz(grant_type, access_token, desired_iam_id, opts = {})
|
191
|
+
data, _status_code, _headers = get_token_iam_authz_with_http_info(grant_type, access_token, desired_iam_id, opts)
|
192
|
+
data
|
193
|
+
end
|
194
|
+
|
195
|
+
# Create an IAM access token based on an authorization policy
|
196
|
+
# Creates a non-opaque access token, if an appropriate authorization policy is in place. This kind of IAM access token is typically used for access between services.
|
197
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `urn:ibm:params:oauth:grant-type:iam-authz`.
|
198
|
+
# @param access_token [String] The IAM access token of the identity that has the appropriate authorization to create an IAM access token for a given resource.
|
199
|
+
# @param desired_iam_id [String] The IAM ID of the IAM access token identity that should be created. The desired_iam_id identifies a resource identity. The IAM ID consists of the prefix crn- and the CRN of the target identity, e.g. crn-crn:v1:bluemix:public:cloud-object-storage:global:a/59bcbfa6ea2f006b4ed7094c1a08dcdd:1a0ec336-f391-4091-a6fb-5e084a4c56f4::.
|
200
|
+
# @param [Hash] opts the optional parameters
|
201
|
+
# @return [Array<(TokenResponse, Integer, Hash)>] TokenResponse data, response status code and response headers
|
202
|
+
def get_token_iam_authz_with_http_info(grant_type, access_token, desired_iam_id, opts = {})
|
203
|
+
if @api_client.config.debugging
|
204
|
+
@api_client.config.logger.debug 'Calling API: TokenOperationsApi.get_token_iam_authz ...'
|
205
|
+
end
|
206
|
+
# verify the required parameter 'grant_type' is set
|
207
|
+
if @api_client.config.client_side_validation && grant_type.nil?
|
208
|
+
fail ArgumentError, "Missing the required parameter 'grant_type' when calling TokenOperationsApi.get_token_iam_authz"
|
209
|
+
end
|
210
|
+
# verify the required parameter 'access_token' is set
|
211
|
+
if @api_client.config.client_side_validation && access_token.nil?
|
212
|
+
fail ArgumentError, "Missing the required parameter 'access_token' when calling TokenOperationsApi.get_token_iam_authz"
|
213
|
+
end
|
214
|
+
# verify the required parameter 'desired_iam_id' is set
|
215
|
+
if @api_client.config.client_side_validation && desired_iam_id.nil?
|
216
|
+
fail ArgumentError, "Missing the required parameter 'desired_iam_id' when calling TokenOperationsApi.get_token_iam_authz"
|
217
|
+
end
|
218
|
+
# resource path
|
219
|
+
local_var_path = '/identity/token#iam-authz'
|
220
|
+
|
221
|
+
# query parameters
|
222
|
+
query_params = opts[:query_params] || {}
|
223
|
+
|
224
|
+
# header parameters
|
225
|
+
header_params = opts[:header_params] || {}
|
226
|
+
# HTTP header 'Accept' (if needed)
|
227
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
228
|
+
# HTTP header 'Content-Type'
|
229
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
|
230
|
+
|
231
|
+
# form parameters
|
232
|
+
form_params = opts[:form_params] || {}
|
233
|
+
form_params['grant_type'] = grant_type
|
234
|
+
form_params['access_token'] = access_token
|
235
|
+
form_params['desired_iam_id'] = desired_iam_id
|
236
|
+
|
237
|
+
# http body (model)
|
238
|
+
post_body = opts[:body]
|
239
|
+
|
240
|
+
# return_type
|
241
|
+
return_type = opts[:return_type] || 'TokenResponse'
|
242
|
+
|
243
|
+
# auth_names
|
244
|
+
auth_names = opts[:auth_names] || []
|
245
|
+
|
246
|
+
new_options = opts.merge(
|
247
|
+
:header_params => header_params,
|
248
|
+
:query_params => query_params,
|
249
|
+
:form_params => form_params,
|
250
|
+
:body => post_body,
|
251
|
+
:auth_names => auth_names,
|
252
|
+
:return_type => return_type
|
253
|
+
)
|
254
|
+
|
255
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
256
|
+
if @api_client.config.debugging
|
257
|
+
@api_client.config.logger.debug "API called: TokenOperationsApi#get_token_iam_authz\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
258
|
+
end
|
259
|
+
return data, status_code, headers
|
260
|
+
end
|
261
|
+
|
262
|
+
# Create an IAM access token for a user using username / password credentials and an optional account identifier
|
263
|
+
# Creates a non-opaque access token for a username and password. To be able to call IBM Cloud APIs, the token must be made account-specific. For this purpose, also pass the 32 character long identifier for your account in the API call. This API call is possible only for non-federated IBMid users.
|
264
|
+
# @param authorization [String] Basic Authorization Header containing a valid client ID and secret. If this header is omitted the request fails with BXNIM0308E: 'No authorization header found'. You can use the client ID and secret that is used by the IBM Cloud CLI: `bx / bx`
|
265
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `password`.
|
266
|
+
# @param username [String] The value of the username
|
267
|
+
# @param password [String] The value of the password
|
268
|
+
# @param [Hash] opts the optional parameters
|
269
|
+
# @option opts [String] :account The 32 character identifier of the account. Specify this parameter to get an account-specific IAM token. IBM Cloud APIs require that IAM tokens are account-specific.
|
270
|
+
# @return [TokenResponse]
|
271
|
+
def get_token_password(authorization, grant_type, username, password, opts = {})
|
272
|
+
data, _status_code, _headers = get_token_password_with_http_info(authorization, grant_type, username, password, opts)
|
273
|
+
data
|
274
|
+
end
|
275
|
+
|
276
|
+
# Create an IAM access token for a user using username / password credentials and an optional account identifier
|
277
|
+
# Creates a non-opaque access token for a username and password. To be able to call IBM Cloud APIs, the token must be made account-specific. For this purpose, also pass the 32 character long identifier for your account in the API call. This API call is possible only for non-federated IBMid users.
|
278
|
+
# @param authorization [String] Basic Authorization Header containing a valid client ID and secret. If this header is omitted the request fails with BXNIM0308E: 'No authorization header found'. You can use the client ID and secret that is used by the IBM Cloud CLI: `bx / bx`
|
279
|
+
# @param grant_type [String] Grant type for this API call. You must set the grant type to `password`.
|
280
|
+
# @param username [String] The value of the username
|
281
|
+
# @param password [String] The value of the password
|
282
|
+
# @param [Hash] opts the optional parameters
|
283
|
+
# @option opts [String] :account The 32 character identifier of the account. Specify this parameter to get an account-specific IAM token. IBM Cloud APIs require that IAM tokens are account-specific.
|
284
|
+
# @return [Array<(TokenResponse, Integer, Hash)>] TokenResponse data, response status code and response headers
|
285
|
+
def get_token_password_with_http_info(authorization, grant_type, username, password, opts = {})
|
286
|
+
if @api_client.config.debugging
|
287
|
+
@api_client.config.logger.debug 'Calling API: TokenOperationsApi.get_token_password ...'
|
288
|
+
end
|
289
|
+
# verify the required parameter 'authorization' is set
|
290
|
+
if @api_client.config.client_side_validation && authorization.nil?
|
291
|
+
fail ArgumentError, "Missing the required parameter 'authorization' when calling TokenOperationsApi.get_token_password"
|
292
|
+
end
|
293
|
+
# verify the required parameter 'grant_type' is set
|
294
|
+
if @api_client.config.client_side_validation && grant_type.nil?
|
295
|
+
fail ArgumentError, "Missing the required parameter 'grant_type' when calling TokenOperationsApi.get_token_password"
|
296
|
+
end
|
297
|
+
# verify the required parameter 'username' is set
|
298
|
+
if @api_client.config.client_side_validation && username.nil?
|
299
|
+
fail ArgumentError, "Missing the required parameter 'username' when calling TokenOperationsApi.get_token_password"
|
300
|
+
end
|
301
|
+
# verify the required parameter 'password' is set
|
302
|
+
if @api_client.config.client_side_validation && password.nil?
|
303
|
+
fail ArgumentError, "Missing the required parameter 'password' when calling TokenOperationsApi.get_token_password"
|
304
|
+
end
|
305
|
+
# resource path
|
306
|
+
local_var_path = '/identity/token#password'
|
307
|
+
|
308
|
+
# query parameters
|
309
|
+
query_params = opts[:query_params] || {}
|
310
|
+
|
311
|
+
# header parameters
|
312
|
+
header_params = opts[:header_params] || {}
|
313
|
+
# HTTP header 'Accept' (if needed)
|
314
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
315
|
+
# HTTP header 'Content-Type'
|
316
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded'])
|
317
|
+
header_params[:'Authorization'] = authorization
|
318
|
+
|
319
|
+
# form parameters
|
320
|
+
form_params = opts[:form_params] || {}
|
321
|
+
form_params['grant_type'] = grant_type
|
322
|
+
form_params['username'] = username
|
323
|
+
form_params['password'] = password
|
324
|
+
form_params['account'] = opts[:'account'] if !opts[:'account'].nil?
|
325
|
+
|
326
|
+
# http body (model)
|
327
|
+
post_body = opts[:body]
|
328
|
+
|
329
|
+
# return_type
|
330
|
+
return_type = opts[:return_type] || 'TokenResponse'
|
331
|
+
|
332
|
+
# auth_names
|
333
|
+
auth_names = opts[:auth_names] || []
|
334
|
+
|
335
|
+
new_options = opts.merge(
|
336
|
+
:header_params => header_params,
|
337
|
+
:query_params => query_params,
|
338
|
+
:form_params => form_params,
|
339
|
+
:body => post_body,
|
340
|
+
:auth_names => auth_names,
|
341
|
+
:return_type => return_type
|
342
|
+
)
|
343
|
+
|
344
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
345
|
+
if @api_client.config.debugging
|
346
|
+
@api_client.config.logger.debug "API called: TokenOperationsApi#get_token_password\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
347
|
+
end
|
348
|
+
return data, status_code, headers
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
@@ -0,0 +1,387 @@
|
|
1
|
+
=begin
|
2
|
+
#IAM Identity Services API
|
3
|
+
|
4
|
+
#The IAM Identity Service API allows for the management of Identities (Service IDs, ApiKeys).
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.0.0-beta2
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'typhoeus'
|
18
|
+
|
19
|
+
module IbmCloudIam
|
20
|
+
class ApiClient
|
21
|
+
# The Configuration object holding settings to be used in the API client.
|
22
|
+
attr_accessor :config
|
23
|
+
|
24
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
25
|
+
#
|
26
|
+
# @return [Hash]
|
27
|
+
attr_accessor :default_headers
|
28
|
+
|
29
|
+
# Initializes the ApiClient
|
30
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
31
|
+
def initialize(config = Configuration.default)
|
32
|
+
@config = config
|
33
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
34
|
+
@default_headers = {
|
35
|
+
'Content-Type' => 'application/json',
|
36
|
+
'User-Agent' => @user_agent
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default
|
41
|
+
@@default ||= ApiClient.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# Call an API with given options.
|
45
|
+
#
|
46
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
47
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
48
|
+
def call_api(http_method, path, opts = {})
|
49
|
+
request = build_request(http_method, path, opts)
|
50
|
+
response = request.run
|
51
|
+
|
52
|
+
if @config.debugging
|
53
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
unless response.success?
|
57
|
+
if response.timed_out?
|
58
|
+
fail ApiError.new('Connection timed out')
|
59
|
+
elsif response.code == 0
|
60
|
+
# Errors from libcurl will be made visible here
|
61
|
+
fail ApiError.new(:code => 0,
|
62
|
+
:message => response.return_message)
|
63
|
+
else
|
64
|
+
fail ApiError.new(:code => response.code,
|
65
|
+
:response_headers => response.headers,
|
66
|
+
:response_body => response.body),
|
67
|
+
response.status_message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if opts[:return_type]
|
72
|
+
data = deserialize(response, opts[:return_type])
|
73
|
+
else
|
74
|
+
data = nil
|
75
|
+
end
|
76
|
+
return data, response.code, response.headers
|
77
|
+
end
|
78
|
+
|
79
|
+
# Builds the HTTP request
|
80
|
+
#
|
81
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
82
|
+
# @param [String] path URL path (e.g. /account/new)
|
83
|
+
# @option opts [Hash] :header_params Header parameters
|
84
|
+
# @option opts [Hash] :query_params Query parameters
|
85
|
+
# @option opts [Hash] :form_params Query parameters
|
86
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
87
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
88
|
+
def build_request(http_method, path, opts = {})
|
89
|
+
url = build_request_url(path)
|
90
|
+
http_method = http_method.to_sym.downcase
|
91
|
+
|
92
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
93
|
+
query_params = opts[:query_params] || {}
|
94
|
+
form_params = opts[:form_params] || {}
|
95
|
+
|
96
|
+
|
97
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
98
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
99
|
+
|
100
|
+
req_opts = {
|
101
|
+
:method => http_method,
|
102
|
+
:headers => header_params,
|
103
|
+
:params => query_params,
|
104
|
+
:params_encoding => @config.params_encoding,
|
105
|
+
:timeout => @config.timeout,
|
106
|
+
:ssl_verifypeer => @config.verify_ssl,
|
107
|
+
:ssl_verifyhost => _verify_ssl_host,
|
108
|
+
:sslcert => @config.cert_file,
|
109
|
+
:sslkey => @config.key_file,
|
110
|
+
:verbose => @config.debugging
|
111
|
+
}
|
112
|
+
|
113
|
+
# set custom cert, if provided
|
114
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
115
|
+
|
116
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
117
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
118
|
+
req_opts.update :body => req_body
|
119
|
+
if @config.debugging
|
120
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
request = Typhoeus::Request.new(url, req_opts)
|
125
|
+
download_file(request) if opts[:return_type] == 'File'
|
126
|
+
request
|
127
|
+
end
|
128
|
+
|
129
|
+
# Builds the HTTP request body
|
130
|
+
#
|
131
|
+
# @param [Hash] header_params Header parameters
|
132
|
+
# @param [Hash] form_params Query parameters
|
133
|
+
# @param [Object] body HTTP body (JSON/XML)
|
134
|
+
# @return [String] HTTP body data in the form of string
|
135
|
+
def build_request_body(header_params, form_params, body)
|
136
|
+
# http form
|
137
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
138
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
139
|
+
data = {}
|
140
|
+
form_params.each do |key, value|
|
141
|
+
case value
|
142
|
+
when ::File, ::Array, nil
|
143
|
+
# let typhoeus handle File, Array and nil parameters
|
144
|
+
data[key] = value
|
145
|
+
else
|
146
|
+
data[key] = value.to_s
|
147
|
+
end
|
148
|
+
end
|
149
|
+
elsif body
|
150
|
+
data = body.is_a?(String) ? body : body.to_json
|
151
|
+
else
|
152
|
+
data = nil
|
153
|
+
end
|
154
|
+
data
|
155
|
+
end
|
156
|
+
|
157
|
+
# Check if the given MIME is a JSON MIME.
|
158
|
+
# JSON MIME examples:
|
159
|
+
# application/json
|
160
|
+
# application/json; charset=UTF8
|
161
|
+
# APPLICATION/JSON
|
162
|
+
# */*
|
163
|
+
# @param [String] mime MIME
|
164
|
+
# @return [Boolean] True if the MIME is application/json
|
165
|
+
def json_mime?(mime)
|
166
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
167
|
+
end
|
168
|
+
|
169
|
+
# Deserialize the response to the given return type.
|
170
|
+
#
|
171
|
+
# @param [Response] response HTTP response
|
172
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
173
|
+
def deserialize(response, return_type)
|
174
|
+
body = response.body
|
175
|
+
|
176
|
+
# handle file downloading - return the File instance processed in request callbacks
|
177
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
178
|
+
return @tempfile if return_type == 'File'
|
179
|
+
|
180
|
+
return nil if body.nil? || body.empty?
|
181
|
+
|
182
|
+
# return response body directly for String return type
|
183
|
+
return body if return_type == 'String'
|
184
|
+
|
185
|
+
# ensuring a default content type
|
186
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
187
|
+
|
188
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
189
|
+
|
190
|
+
begin
|
191
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
192
|
+
rescue JSON::ParserError => e
|
193
|
+
if %w(String Date DateTime).include?(return_type)
|
194
|
+
data = body
|
195
|
+
else
|
196
|
+
raise e
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
convert_to_type data, return_type
|
201
|
+
end
|
202
|
+
|
203
|
+
# Convert data to the given return type.
|
204
|
+
# @param [Object] data Data to be converted
|
205
|
+
# @param [String] return_type Return type
|
206
|
+
# @return [Mixed] Data in a particular type
|
207
|
+
def convert_to_type(data, return_type)
|
208
|
+
return nil if data.nil?
|
209
|
+
case return_type
|
210
|
+
when 'String'
|
211
|
+
data.to_s
|
212
|
+
when 'Integer'
|
213
|
+
data.to_i
|
214
|
+
when 'Float'
|
215
|
+
data.to_f
|
216
|
+
when 'Boolean'
|
217
|
+
data == true
|
218
|
+
when 'DateTime'
|
219
|
+
# parse date time (expecting ISO 8601 format)
|
220
|
+
DateTime.parse data
|
221
|
+
when 'Date'
|
222
|
+
# parse date time (expecting ISO 8601 format)
|
223
|
+
Date.parse data
|
224
|
+
when 'Object'
|
225
|
+
# generic object (usually a Hash), return directly
|
226
|
+
data
|
227
|
+
when /\AArray<(.+)>\z/
|
228
|
+
# e.g. Array<Pet>
|
229
|
+
sub_type = $1
|
230
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
231
|
+
when /\AHash\<String, (.+)\>\z/
|
232
|
+
# e.g. Hash<String, Integer>
|
233
|
+
sub_type = $1
|
234
|
+
{}.tap do |hash|
|
235
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
236
|
+
end
|
237
|
+
else
|
238
|
+
# models, e.g. Pet
|
239
|
+
IbmCloudIam.const_get(return_type).build_from_hash(data)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
244
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
245
|
+
# The response body is written to the file in chunks in order to handle files which
|
246
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
247
|
+
# process can use.
|
248
|
+
#
|
249
|
+
# @see Configuration#temp_folder_path
|
250
|
+
def download_file(request)
|
251
|
+
tempfile = nil
|
252
|
+
encoding = nil
|
253
|
+
request.on_headers do |response|
|
254
|
+
content_disposition = response.headers['Content-Disposition']
|
255
|
+
if content_disposition && content_disposition =~ /filename=/i
|
256
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
257
|
+
prefix = sanitize_filename(filename)
|
258
|
+
else
|
259
|
+
prefix = 'download-'
|
260
|
+
end
|
261
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
262
|
+
encoding = response.body.encoding
|
263
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
264
|
+
@tempfile = tempfile
|
265
|
+
end
|
266
|
+
request.on_body do |chunk|
|
267
|
+
chunk.force_encoding(encoding)
|
268
|
+
tempfile.write(chunk)
|
269
|
+
end
|
270
|
+
request.on_complete do |response|
|
271
|
+
if tempfile
|
272
|
+
tempfile.close
|
273
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
274
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
275
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
276
|
+
"explicitly with `tempfile.delete`"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
# Sanitize filename by removing path.
|
282
|
+
# e.g. ../../sun.gif becomes sun.gif
|
283
|
+
#
|
284
|
+
# @param [String] filename the filename to be sanitized
|
285
|
+
# @return [String] the sanitized filename
|
286
|
+
def sanitize_filename(filename)
|
287
|
+
filename.gsub(/.*[\/\\]/, '')
|
288
|
+
end
|
289
|
+
|
290
|
+
def build_request_url(path)
|
291
|
+
# Add leading and trailing slashes to path
|
292
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
293
|
+
@config.base_url + path
|
294
|
+
end
|
295
|
+
|
296
|
+
# Update hearder and query params based on authentication settings.
|
297
|
+
#
|
298
|
+
# @param [Hash] header_params Header parameters
|
299
|
+
# @param [Hash] query_params Query parameters
|
300
|
+
# @param [String] auth_names Authentication scheme name
|
301
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
302
|
+
Array(auth_names).each do |auth_name|
|
303
|
+
auth_setting = @config.auth_settings[auth_name]
|
304
|
+
next unless auth_setting
|
305
|
+
case auth_setting[:in]
|
306
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
307
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
308
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
# Sets user agent in HTTP header
|
314
|
+
#
|
315
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
316
|
+
def user_agent=(user_agent)
|
317
|
+
@user_agent = user_agent
|
318
|
+
@default_headers['User-Agent'] = @user_agent
|
319
|
+
end
|
320
|
+
|
321
|
+
# Return Accept header based on an array of accepts provided.
|
322
|
+
# @param [Array] accepts array for Accept
|
323
|
+
# @return [String] the Accept header (e.g. application/json)
|
324
|
+
def select_header_accept(accepts)
|
325
|
+
return nil if accepts.nil? || accepts.empty?
|
326
|
+
# use JSON when present, otherwise use all of the provided
|
327
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
328
|
+
json_accept || accepts.join(',')
|
329
|
+
end
|
330
|
+
|
331
|
+
# Return Content-Type header based on an array of content types provided.
|
332
|
+
# @param [Array] content_types array for Content-Type
|
333
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
334
|
+
def select_header_content_type(content_types)
|
335
|
+
# use application/json by default
|
336
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
337
|
+
# use JSON when present, otherwise use the first one
|
338
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
339
|
+
json_content_type || content_types.first
|
340
|
+
end
|
341
|
+
|
342
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
343
|
+
# @param [Object] model object to be converted into JSON string
|
344
|
+
# @return [String] JSON string representation of the object
|
345
|
+
def object_to_http_body(model)
|
346
|
+
return model if model.nil? || model.is_a?(String)
|
347
|
+
local_body = nil
|
348
|
+
if model.is_a?(Array)
|
349
|
+
local_body = model.map { |m| object_to_hash(m) }
|
350
|
+
else
|
351
|
+
local_body = object_to_hash(model)
|
352
|
+
end
|
353
|
+
local_body.to_json
|
354
|
+
end
|
355
|
+
|
356
|
+
# Convert object(non-array) to hash.
|
357
|
+
# @param [Object] obj object to be converted into JSON string
|
358
|
+
# @return [String] JSON string representation of the object
|
359
|
+
def object_to_hash(obj)
|
360
|
+
if obj.respond_to?(:to_hash)
|
361
|
+
obj.to_hash
|
362
|
+
else
|
363
|
+
obj
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
# Build parameter value according to the given collection format.
|
368
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
369
|
+
def build_collection_param(param, collection_format)
|
370
|
+
case collection_format
|
371
|
+
when :csv
|
372
|
+
param.join(',')
|
373
|
+
when :ssv
|
374
|
+
param.join(' ')
|
375
|
+
when :tsv
|
376
|
+
param.join("\t")
|
377
|
+
when :pipes
|
378
|
+
param.join('|')
|
379
|
+
when :multi
|
380
|
+
# return the array directly as typhoeus will handle it as expected
|
381
|
+
param
|
382
|
+
else
|
383
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|