turnkey_client 0.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 +7 -0
- data/Rakefile +8 -0
- data/git_push.sh +55 -0
- data/lib/turnkey_client/api/activities_api.rb +136 -0
- data/lib/turnkey_client/api/api_keys_api.rb +252 -0
- data/lib/turnkey_client/api/authenticators_api.rb +252 -0
- data/lib/turnkey_client/api/consensus_api.rb +136 -0
- data/lib/turnkey_client/api/features_api.rb +136 -0
- data/lib/turnkey_client/api/invitations_api.rb +136 -0
- data/lib/turnkey_client/api/organizations_api.rb +194 -0
- data/lib/turnkey_client/api/policies_api.rb +310 -0
- data/lib/turnkey_client/api/private_key_tags_api.rb +194 -0
- data/lib/turnkey_client/api/private_keys_api.rb +252 -0
- data/lib/turnkey_client/api/public_api_service_api.rb +66 -0
- data/lib/turnkey_client/api/sessions_api.rb +78 -0
- data/lib/turnkey_client/api/signing_api.rb +136 -0
- data/lib/turnkey_client/api/user_auth_api.rb +78 -0
- data/lib/turnkey_client/api/user_recovery_api.rb +136 -0
- data/lib/turnkey_client/api/user_tags_api.rb +194 -0
- data/lib/turnkey_client/api/users_api.rb +310 -0
- data/lib/turnkey_client/api/wallets_api.rb +426 -0
- data/lib/turnkey_client/api_client.rb +446 -0
- data/lib/turnkey_client/api_error.rb +57 -0
- data/lib/turnkey_client/configuration.rb +216 -0
- data/lib/turnkey_client/models/datav1_tag.rb +269 -0
- data/lib/turnkey_client/models/externaldatav1_address.rb +215 -0
- data/lib/turnkey_client/models/externaldatav1_credential.rb +226 -0
- data/lib/turnkey_client/models/externaldatav1_quorum.rb +229 -0
- data/lib/turnkey_client/models/externaldatav1_timestamp.rb +225 -0
- data/lib/turnkey_client/models/immutableactivityv1_address.rb +215 -0
- data/lib/turnkey_client/models/protobuf_any.rb +201 -0
- data/lib/turnkey_client/models/rpc_status.rb +226 -0
- data/lib/turnkey_client/models/v1_accept_invitation_intent.rb +241 -0
- data/lib/turnkey_client/models/v1_accept_invitation_intent_v2.rb +241 -0
- data/lib/turnkey_client/models/v1_accept_invitation_result.rb +227 -0
- data/lib/turnkey_client/models/v1_access_type.rb +29 -0
- data/lib/turnkey_client/models/v1_activate_billing_tier_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_activate_billing_tier_result.rb +212 -0
- data/lib/turnkey_client/models/v1_activity.rb +371 -0
- data/lib/turnkey_client/models/v1_activity_response.rb +211 -0
- data/lib/turnkey_client/models/v1_activity_status.rb +32 -0
- data/lib/turnkey_client/models/v1_activity_type.rb +83 -0
- data/lib/turnkey_client/models/v1_address_format.rb +31 -0
- data/lib/turnkey_client/models/v1_api_key.rb +279 -0
- data/lib/turnkey_client/models/v1_api_key_params.rb +237 -0
- data/lib/turnkey_client/models/v1_api_only_user_params.rb +256 -0
- data/lib/turnkey_client/models/v1_approve_activity_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_approve_activity_request.rb +289 -0
- data/lib/turnkey_client/models/v1_attestation.rb +259 -0
- data/lib/turnkey_client/models/v1_authenticator.rb +345 -0
- data/lib/turnkey_client/models/v1_authenticator_attestation_response.rb +280 -0
- data/lib/turnkey_client/models/v1_authenticator_params.rb +256 -0
- data/lib/turnkey_client/models/v1_authenticator_params_v2.rb +241 -0
- data/lib/turnkey_client/models/v1_authenticator_transport.rb +31 -0
- data/lib/turnkey_client/models/v1_create_api_keys_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_create_api_keys_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_api_keys_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_api_only_users_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_create_api_only_users_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_api_only_users_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_authenticators_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_create_authenticators_intent_v2.rb +229 -0
- data/lib/turnkey_client/models/v1_create_authenticators_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_authenticators_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_invitations_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_create_invitations_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_invitations_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_organization_intent.rb +251 -0
- data/lib/turnkey_client/models/v1_create_organization_intent_v2.rb +251 -0
- data/lib/turnkey_client/models/v1_create_organization_result.rb +212 -0
- data/lib/turnkey_client/models/v1_create_policy_intent.rb +252 -0
- data/lib/turnkey_client/models/v1_create_policy_intent_v2.rb +252 -0
- data/lib/turnkey_client/models/v1_create_policy_intent_v3.rb +255 -0
- data/lib/turnkey_client/models/v1_create_policy_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_policy_result.rb +212 -0
- data/lib/turnkey_client/models/v1_create_private_key_tag_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_create_private_key_tag_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_private_key_tag_result.rb +229 -0
- data/lib/turnkey_client/models/v1_create_private_keys_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_create_private_keys_intent_v2.rb +214 -0
- data/lib/turnkey_client/models/v1_create_private_keys_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_private_keys_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_private_keys_result_v2.rb +214 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_intent.rb +226 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_intent_v2.rb +244 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_intent_v3.rb +261 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_intent_v4.rb +273 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_result.rb +211 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_result_v3.rb +228 -0
- data/lib/turnkey_client/models/v1_create_sub_organization_result_v4.rb +220 -0
- data/lib/turnkey_client/models/v1_create_user_tag_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_create_user_tag_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_user_tag_result.rb +229 -0
- data/lib/turnkey_client/models/v1_create_users_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_create_users_intent_v2.rb +214 -0
- data/lib/turnkey_client/models/v1_create_users_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_users_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_wallet_accounts_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_create_wallet_accounts_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_wallet_accounts_result.rb +214 -0
- data/lib/turnkey_client/models/v1_create_wallet_intent.rb +239 -0
- data/lib/turnkey_client/models/v1_create_wallet_request.rb +289 -0
- data/lib/turnkey_client/models/v1_create_wallet_result.rb +229 -0
- data/lib/turnkey_client/models/v1_cred_props_authentication_extensions_client_outputs.rb +211 -0
- data/lib/turnkey_client/models/v1_credential_type.rb +29 -0
- data/lib/turnkey_client/models/v1_curve.rb +28 -0
- data/lib/turnkey_client/models/v1_delete_api_keys_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_delete_api_keys_request.rb +289 -0
- data/lib/turnkey_client/models/v1_delete_api_keys_result.rb +214 -0
- data/lib/turnkey_client/models/v1_delete_authenticators_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_delete_authenticators_request.rb +289 -0
- data/lib/turnkey_client/models/v1_delete_authenticators_result.rb +214 -0
- data/lib/turnkey_client/models/v1_delete_invitation_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_invitation_request.rb +289 -0
- data/lib/turnkey_client/models/v1_delete_invitation_result.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_organization_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_organization_result.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_payment_method_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_payment_method_result.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_policy_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_policy_request.rb +289 -0
- data/lib/turnkey_client/models/v1_delete_policy_result.rb +212 -0
- data/lib/turnkey_client/models/v1_delete_private_key_tags_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_delete_private_key_tags_result.rb +231 -0
- data/lib/turnkey_client/models/v1_delete_user_tags_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_delete_user_tags_result.rb +231 -0
- data/lib/turnkey_client/models/v1_delete_users_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_delete_users_result.rb +214 -0
- data/lib/turnkey_client/models/v1_disable_private_key_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_disable_private_key_result.rb +212 -0
- data/lib/turnkey_client/models/v1_effect.rb +28 -0
- data/lib/turnkey_client/models/v1_email_auth_intent.rb +256 -0
- data/lib/turnkey_client/models/v1_email_auth_request.rb +289 -0
- data/lib/turnkey_client/models/v1_email_auth_result.rb +227 -0
- data/lib/turnkey_client/models/v1_email_customization.rb +233 -0
- data/lib/turnkey_client/models/v1_export_private_key_intent.rb +227 -0
- data/lib/turnkey_client/models/v1_export_private_key_request.rb +289 -0
- data/lib/turnkey_client/models/v1_export_private_key_result.rb +227 -0
- data/lib/turnkey_client/models/v1_export_wallet_account_intent.rb +227 -0
- data/lib/turnkey_client/models/v1_export_wallet_account_request.rb +289 -0
- data/lib/turnkey_client/models/v1_export_wallet_account_result.rb +227 -0
- data/lib/turnkey_client/models/v1_export_wallet_intent.rb +236 -0
- data/lib/turnkey_client/models/v1_export_wallet_request.rb +289 -0
- data/lib/turnkey_client/models/v1_export_wallet_result.rb +227 -0
- data/lib/turnkey_client/models/v1_feature.rb +215 -0
- data/lib/turnkey_client/models/v1_feature_name.rb +30 -0
- data/lib/turnkey_client/models/v1_get_activities_request.rb +245 -0
- data/lib/turnkey_client/models/v1_get_activities_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_activity_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_api_key_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_api_key_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_api_keys_request.rb +222 -0
- data/lib/turnkey_client/models/v1_get_api_keys_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_authenticator_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_authenticator_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_authenticators_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_authenticators_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_organization_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_organization_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_policies_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_policies_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_policy_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_policy_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_private_key_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_private_key_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_private_keys_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_private_keys_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_user_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_user_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_users_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_users_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_wallet_accounts_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_wallet_accounts_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_wallet_request.rb +227 -0
- data/lib/turnkey_client/models/v1_get_wallet_response.rb +211 -0
- data/lib/turnkey_client/models/v1_get_wallets_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_wallets_response.rb +214 -0
- data/lib/turnkey_client/models/v1_get_whoami_request.rb +212 -0
- data/lib/turnkey_client/models/v1_get_whoami_response.rb +257 -0
- data/lib/turnkey_client/models/v1_hash_function.rb +30 -0
- data/lib/turnkey_client/models/v1_init_user_email_recovery_intent.rb +237 -0
- data/lib/turnkey_client/models/v1_init_user_email_recovery_request.rb +289 -0
- data/lib/turnkey_client/models/v1_init_user_email_recovery_result.rb +212 -0
- data/lib/turnkey_client/models/v1_intent.rb +715 -0
- data/lib/turnkey_client/models/v1_invitation.rb +330 -0
- data/lib/turnkey_client/models/v1_invitation_params.rb +273 -0
- data/lib/turnkey_client/models/v1_invitation_status.rb +29 -0
- data/lib/turnkey_client/models/v1_list_private_key_tags_request.rb +212 -0
- data/lib/turnkey_client/models/v1_list_private_key_tags_response.rb +214 -0
- data/lib/turnkey_client/models/v1_list_user_tags_request.rb +212 -0
- data/lib/turnkey_client/models/v1_list_user_tags_response.rb +214 -0
- data/lib/turnkey_client/models/v1_mnemonic_language.rb +35 -0
- data/lib/turnkey_client/models/v1_noop_codegen_anchor_response.rb +211 -0
- data/lib/turnkey_client/models/v1_operator.rb +37 -0
- data/lib/turnkey_client/models/v1_organization_data.rb +301 -0
- data/lib/turnkey_client/models/v1_pagination.rb +227 -0
- data/lib/turnkey_client/models/v1_path_format.rb +27 -0
- data/lib/turnkey_client/models/v1_payload_encoding.rb +28 -0
- data/lib/turnkey_client/models/v1_policy.rb +314 -0
- data/lib/turnkey_client/models/v1_private_key.rb +333 -0
- data/lib/turnkey_client/models/v1_private_key_params.rb +260 -0
- data/lib/turnkey_client/models/v1_private_key_result.rb +217 -0
- data/lib/turnkey_client/models/v1_public_key_credential_with_attestation.rb +323 -0
- data/lib/turnkey_client/models/v1_recover_user_intent.rb +226 -0
- data/lib/turnkey_client/models/v1_recover_user_request.rb +289 -0
- data/lib/turnkey_client/models/v1_recover_user_result.rb +214 -0
- data/lib/turnkey_client/models/v1_reject_activity_intent.rb +212 -0
- data/lib/turnkey_client/models/v1_reject_activity_request.rb +289 -0
- data/lib/turnkey_client/models/v1_remove_organization_feature_intent.rb +211 -0
- data/lib/turnkey_client/models/v1_remove_organization_feature_request.rb +289 -0
- data/lib/turnkey_client/models/v1_remove_organization_feature_result.rb +214 -0
- data/lib/turnkey_client/models/v1_result.rb +602 -0
- data/lib/turnkey_client/models/v1_root_user_params.rb +256 -0
- data/lib/turnkey_client/models/v1_selector.rb +224 -0
- data/lib/turnkey_client/models/v1_selector_v2.rb +226 -0
- data/lib/turnkey_client/models/v1_set_organization_feature_intent.rb +226 -0
- data/lib/turnkey_client/models/v1_set_organization_feature_request.rb +289 -0
- data/lib/turnkey_client/models/v1_set_organization_feature_result.rb +214 -0
- data/lib/turnkey_client/models/v1_set_payment_method_intent.rb +287 -0
- data/lib/turnkey_client/models/v1_set_payment_method_intent_v2.rb +242 -0
- data/lib/turnkey_client/models/v1_set_payment_method_result.rb +242 -0
- data/lib/turnkey_client/models/v1_sign_raw_payload_intent.rb +255 -0
- data/lib/turnkey_client/models/v1_sign_raw_payload_intent_v2.rb +255 -0
- data/lib/turnkey_client/models/v1_sign_raw_payload_request.rb +289 -0
- data/lib/turnkey_client/models/v1_sign_raw_payload_result.rb +242 -0
- data/lib/turnkey_client/models/v1_sign_transaction_intent.rb +241 -0
- data/lib/turnkey_client/models/v1_sign_transaction_intent_v2.rb +241 -0
- data/lib/turnkey_client/models/v1_sign_transaction_request.rb +289 -0
- data/lib/turnkey_client/models/v1_sign_transaction_result.rb +211 -0
- data/lib/turnkey_client/models/v1_simple_client_extension_results.rb +224 -0
- data/lib/turnkey_client/models/v1_tag_type.rb +28 -0
- data/lib/turnkey_client/models/v1_transaction_type.rb +27 -0
- data/lib/turnkey_client/models/v1_update_allowed_origins_intent.rb +214 -0
- data/lib/turnkey_client/models/v1_update_allowed_origins_result.rb +197 -0
- data/lib/turnkey_client/models/v1_update_policy_intent.rb +261 -0
- data/lib/turnkey_client/models/v1_update_policy_request.rb +289 -0
- data/lib/turnkey_client/models/v1_update_policy_result.rb +212 -0
- data/lib/turnkey_client/models/v1_update_private_key_tag_intent.rb +256 -0
- data/lib/turnkey_client/models/v1_update_private_key_tag_request.rb +289 -0
- data/lib/turnkey_client/models/v1_update_private_key_tag_result.rb +212 -0
- data/lib/turnkey_client/models/v1_update_root_quorum_intent.rb +229 -0
- data/lib/turnkey_client/models/v1_update_root_quorum_request.rb +289 -0
- data/lib/turnkey_client/models/v1_update_root_quorum_result.rb +197 -0
- data/lib/turnkey_client/models/v1_update_user_intent.rb +244 -0
- data/lib/turnkey_client/models/v1_update_user_request.rb +289 -0
- data/lib/turnkey_client/models/v1_update_user_result.rb +212 -0
- data/lib/turnkey_client/models/v1_update_user_tag_intent.rb +256 -0
- data/lib/turnkey_client/models/v1_update_user_tag_request.rb +289 -0
- data/lib/turnkey_client/models/v1_update_user_tag_result.rb +212 -0
- data/lib/turnkey_client/models/v1_user.rb +316 -0
- data/lib/turnkey_client/models/v1_user_params.rb +287 -0
- data/lib/turnkey_client/models/v1_user_params_v2.rb +273 -0
- data/lib/turnkey_client/models/v1_vote.rb +378 -0
- data/lib/turnkey_client/models/v1_wallet.rb +270 -0
- data/lib/turnkey_client/models/v1_wallet_account.rb +342 -0
- data/lib/turnkey_client/models/v1_wallet_account_params.rb +254 -0
- data/lib/turnkey_client/models/v1_wallet_params.rb +239 -0
- data/lib/turnkey_client/models/v1_wallet_result.rb +228 -0
- data/lib/turnkey_client/models/v1_web_authn_stamp.rb +257 -0
- data/lib/turnkey_client/version.rb +14 -0
- data/lib/turnkey_client.rb +289 -0
- data/turnkey_client.gemspec +38 -0
- metadata +387 -0
@@ -0,0 +1,446 @@
|
|
1
|
+
=begin
|
2
|
+
#API Reference
|
3
|
+
|
4
|
+
#Review our [API Introduction](../api-introduction) to get started.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 3.0.53
|
10
|
+
=end
|
11
|
+
|
12
|
+
require 'date'
|
13
|
+
require 'json'
|
14
|
+
require 'logger'
|
15
|
+
require 'tempfile'
|
16
|
+
require 'typhoeus'
|
17
|
+
require 'uri'
|
18
|
+
require 'openssl'
|
19
|
+
require 'json'
|
20
|
+
require 'base64'
|
21
|
+
|
22
|
+
ASN1_DER_P256_PRIVATE_KEY_PREFIX = "308141020100301306072a8648ce3d020106082a8648ce3d030107042730250201010420"
|
23
|
+
|
24
|
+
module TurnkeyClient
|
25
|
+
class ApiClient
|
26
|
+
# The Configuration object holding settings to be used in the API client.
|
27
|
+
attr_accessor :config
|
28
|
+
|
29
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
30
|
+
#
|
31
|
+
# @return [Hash]
|
32
|
+
attr_accessor :default_headers
|
33
|
+
|
34
|
+
# Initializes the ApiClient
|
35
|
+
# @option config [Configuration] Configuration for initializing the object
|
36
|
+
def initialize(config)
|
37
|
+
@config = config
|
38
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
39
|
+
@default_headers = {
|
40
|
+
'Content-Type' => 'application/json',
|
41
|
+
'User-Agent' => @user_agent
|
42
|
+
}
|
43
|
+
|
44
|
+
if config.api_public_key.nil?
|
45
|
+
raise "Unable to find :api_public_key in configuration. Please configure it with `TurnkeyClient.configure`"
|
46
|
+
end
|
47
|
+
|
48
|
+
if config.api_private_key.nil?
|
49
|
+
raise "Unable to find :api_private_key in configuration. Please configure it with `TurnkeyClient.configure`"
|
50
|
+
end
|
51
|
+
|
52
|
+
# This hex prefix represents the start of a private key object in ASN.1, encoded in DER
|
53
|
+
# This is necessary to load the private key in raw format with openssl.
|
54
|
+
pkcs8_hex = ASN1_DER_P256_PRIVATE_KEY_PREFIX + config.api_private_key
|
55
|
+
|
56
|
+
# See https://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/
|
57
|
+
pkcs8_bytes = pkcs8_hex.scan(/../).map { |x| x.hex }.pack('c*')
|
58
|
+
|
59
|
+
@turnkey_api_key = OpenSSL::PKey.read(pkcs8_bytes)
|
60
|
+
|
61
|
+
# Check that we loaded the right key by comparing the public key to the passed in public key
|
62
|
+
if self.turnkey_api_public_key != config.api_public_key.downcase
|
63
|
+
raise "Expected public key to be #{config.api_public_key} (value configured), but computed #{self.turnkey_api_public_key} from configured private key"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Return the hex-encoded public key in compressed form
|
68
|
+
def turnkey_api_public_key
|
69
|
+
# This gives the public point as a [OpenSSL::BN](https://ruby-doc.org/stdlib-2.4.1/libdoc/openssl/rdoc/OpenSSL/BN.html)
|
70
|
+
public_key_bn = @turnkey_api_key.public_key.to_bn :compressed
|
71
|
+
public_key_hex = public_key_bn.to_s 16
|
72
|
+
public_key_hex.downcase
|
73
|
+
end
|
74
|
+
|
75
|
+
# Given a string (often, a POST request body), returns a hash with the correct auth header
|
76
|
+
# to authenticate the request.
|
77
|
+
def turnkey_stamp(data)
|
78
|
+
hash = OpenSSL::Digest::SHA256.digest(data)
|
79
|
+
signature = @turnkey_api_key.dsa_sign_asn1(hash)
|
80
|
+
|
81
|
+
# See https://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/
|
82
|
+
signature_hex = signature.unpack('H*').first
|
83
|
+
|
84
|
+
stamp = {
|
85
|
+
publicKey: self.turnkey_api_public_key,
|
86
|
+
scheme: "SIGNATURE_SCHEME_TK_API_P256",
|
87
|
+
signature: signature_hex,
|
88
|
+
}
|
89
|
+
|
90
|
+
{ "x-stamp" => Base64.urlsafe_encode64(stamp.to_json, padding: false) }
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.default
|
94
|
+
@@default ||= ApiClient.new
|
95
|
+
end
|
96
|
+
|
97
|
+
# Call an API with given options.
|
98
|
+
#
|
99
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
100
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
101
|
+
def call_api(http_method, path, opts = {})
|
102
|
+
request = build_request(http_method, path, opts)
|
103
|
+
response = request.run
|
104
|
+
|
105
|
+
if @config.debugging
|
106
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
107
|
+
end
|
108
|
+
|
109
|
+
unless response.success?
|
110
|
+
if response.timed_out?
|
111
|
+
fail ApiError.new('Connection timed out')
|
112
|
+
elsif response.code == 0
|
113
|
+
# Errors from libcurl will be made visible here
|
114
|
+
fail ApiError.new(:code => 0,
|
115
|
+
:message => response.return_message)
|
116
|
+
else
|
117
|
+
fail ApiError.new(:code => response.code,
|
118
|
+
:response_headers => response.headers,
|
119
|
+
:response_body => response.body),
|
120
|
+
response.status_message
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if opts[:return_type]
|
125
|
+
data = deserialize(response, opts[:return_type])
|
126
|
+
else
|
127
|
+
data = nil
|
128
|
+
end
|
129
|
+
return data, response.code, response.headers
|
130
|
+
end
|
131
|
+
|
132
|
+
# Builds the HTTP request
|
133
|
+
#
|
134
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
135
|
+
# @param [String] path URL path (e.g. /account/new)
|
136
|
+
# @option opts [Hash] :header_params Header parameters
|
137
|
+
# @option opts [Hash] :query_params Query parameters
|
138
|
+
# @option opts [Hash] :form_params Query parameters
|
139
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
140
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
141
|
+
def build_request(http_method, path, opts = {})
|
142
|
+
url = build_request_url(path)
|
143
|
+
http_method = http_method.to_sym.downcase
|
144
|
+
|
145
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
146
|
+
query_params = opts[:query_params] || {}
|
147
|
+
form_params = opts[:form_params] || {}
|
148
|
+
|
149
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
150
|
+
|
151
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
152
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
153
|
+
|
154
|
+
req_opts = {
|
155
|
+
:method => http_method,
|
156
|
+
:headers => header_params,
|
157
|
+
:params => query_params,
|
158
|
+
:params_encoding => @config.params_encoding,
|
159
|
+
:timeout => @config.timeout,
|
160
|
+
:ssl_verifypeer => @config.verify_ssl,
|
161
|
+
:ssl_verifyhost => _verify_ssl_host,
|
162
|
+
:sslcert => @config.cert_file,
|
163
|
+
:sslkey => @config.key_file,
|
164
|
+
:verbose => @config.debugging
|
165
|
+
}
|
166
|
+
|
167
|
+
# set custom cert, if provided
|
168
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
169
|
+
|
170
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
171
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
172
|
+
req_opts.update :body => req_body
|
173
|
+
|
174
|
+
# Now, stamp the request body and add the header to the list of headers
|
175
|
+
turnkey_auth_headers = turnkey_stamp(req_body)
|
176
|
+
req_opts[:headers] = header_params.merge(turnkey_auth_headers)
|
177
|
+
|
178
|
+
if @config.debugging
|
179
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
request = Typhoeus::Request.new(url, req_opts)
|
184
|
+
download_file(request) if opts[:return_type] == 'File'
|
185
|
+
request
|
186
|
+
end
|
187
|
+
|
188
|
+
# Builds the HTTP request body
|
189
|
+
#
|
190
|
+
# @param [Hash] header_params Header parameters
|
191
|
+
# @param [Hash] form_params Query parameters
|
192
|
+
# @param [Object] body HTTP body (JSON/XML)
|
193
|
+
# @return [String] HTTP body data in the form of string
|
194
|
+
def build_request_body(header_params, form_params, body)
|
195
|
+
# http form
|
196
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
197
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
198
|
+
data = {}
|
199
|
+
form_params.each do |key, value|
|
200
|
+
case value
|
201
|
+
when ::File, ::Array, nil
|
202
|
+
# let typhoeus handle File, Array and nil parameters
|
203
|
+
data[key] = value
|
204
|
+
else
|
205
|
+
data[key] = value.to_s
|
206
|
+
end
|
207
|
+
end
|
208
|
+
elsif body
|
209
|
+
data = body.is_a?(String) ? body : body.to_json
|
210
|
+
else
|
211
|
+
data = nil
|
212
|
+
end
|
213
|
+
data
|
214
|
+
end
|
215
|
+
|
216
|
+
# Check if the given MIME is a JSON MIME.
|
217
|
+
# JSON MIME examples:
|
218
|
+
# application/json
|
219
|
+
# application/json; charset=UTF8
|
220
|
+
# APPLICATION/JSON
|
221
|
+
# */*
|
222
|
+
# @param [String] mime MIME
|
223
|
+
# @return [Boolean] True if the MIME is application/json
|
224
|
+
def json_mime?(mime)
|
225
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
226
|
+
end
|
227
|
+
|
228
|
+
# Deserialize the response to the given return type.
|
229
|
+
#
|
230
|
+
# @param [Response] response HTTP response
|
231
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
232
|
+
def deserialize(response, return_type)
|
233
|
+
body = response.body
|
234
|
+
|
235
|
+
# handle file downloading - return the File instance processed in request callbacks
|
236
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
237
|
+
return @tempfile if return_type == 'File'
|
238
|
+
|
239
|
+
return nil if body.nil? || body.empty?
|
240
|
+
|
241
|
+
# return response body directly for String return type
|
242
|
+
return body if return_type == 'String'
|
243
|
+
|
244
|
+
# ensuring a default content type
|
245
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
246
|
+
|
247
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
248
|
+
|
249
|
+
begin
|
250
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
251
|
+
rescue JSON::ParserError => e
|
252
|
+
if %w(String Date DateTime).include?(return_type)
|
253
|
+
data = body
|
254
|
+
else
|
255
|
+
raise e
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
convert_to_type data, return_type
|
260
|
+
end
|
261
|
+
|
262
|
+
# Convert data to the given return type.
|
263
|
+
# @param [Object] data Data to be converted
|
264
|
+
# @param [String] return_type Return type
|
265
|
+
# @return [Mixed] Data in a particular type
|
266
|
+
def convert_to_type(data, return_type)
|
267
|
+
return nil if data.nil?
|
268
|
+
case return_type
|
269
|
+
when 'String'
|
270
|
+
data.to_s
|
271
|
+
when 'Integer'
|
272
|
+
data.to_i
|
273
|
+
when 'Float'
|
274
|
+
data.to_f
|
275
|
+
when 'Boolean'
|
276
|
+
data == true
|
277
|
+
when 'DateTime'
|
278
|
+
# parse date time (expecting ISO 8601 format)
|
279
|
+
DateTime.parse data
|
280
|
+
when 'Date'
|
281
|
+
# parse date time (expecting ISO 8601 format)
|
282
|
+
Date.parse data
|
283
|
+
when 'Object'
|
284
|
+
# generic object (usually a Hash), return directly
|
285
|
+
data
|
286
|
+
when /\AArray<(.+)>\z/
|
287
|
+
# e.g. Array<Pet>
|
288
|
+
sub_type = $1
|
289
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
290
|
+
when /\AHash\<String, (.+)\>\z/
|
291
|
+
# e.g. Hash<String, Integer>
|
292
|
+
sub_type = $1
|
293
|
+
{}.tap do |hash|
|
294
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
295
|
+
end
|
296
|
+
else
|
297
|
+
# models, e.g. Pet
|
298
|
+
TurnkeyClient.const_get(return_type).build_from_hash(data)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
303
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
304
|
+
# The response body is written to the file in chunks in order to handle files which
|
305
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
306
|
+
# process can use.
|
307
|
+
#
|
308
|
+
# @see Configuration#temp_folder_path
|
309
|
+
def download_file(request)
|
310
|
+
tempfile = nil
|
311
|
+
encoding = nil
|
312
|
+
request.on_headers do |response|
|
313
|
+
content_disposition = response.headers['Content-Disposition']
|
314
|
+
if content_disposition && content_disposition =~ /filename=/i
|
315
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
316
|
+
prefix = sanitize_filename(filename)
|
317
|
+
else
|
318
|
+
prefix = 'download-'
|
319
|
+
end
|
320
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
321
|
+
encoding = response.body.encoding
|
322
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
323
|
+
@tempfile = tempfile
|
324
|
+
end
|
325
|
+
request.on_body do |chunk|
|
326
|
+
chunk.force_encoding(encoding)
|
327
|
+
tempfile.write(chunk)
|
328
|
+
end
|
329
|
+
request.on_complete do |response|
|
330
|
+
if tempfile
|
331
|
+
tempfile.close
|
332
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
333
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
334
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
335
|
+
"explicitly with `tempfile.delete`"
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
# Sanitize filename by removing path.
|
341
|
+
# e.g. ../../sun.gif becomes sun.gif
|
342
|
+
#
|
343
|
+
# @param [String] filename the filename to be sanitized
|
344
|
+
# @return [String] the sanitized filename
|
345
|
+
def sanitize_filename(filename)
|
346
|
+
filename.gsub(/.*[\/\\]/, '')
|
347
|
+
end
|
348
|
+
|
349
|
+
def build_request_url(path)
|
350
|
+
# Add leading and trailing slashes to path
|
351
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
352
|
+
@config.base_url + path
|
353
|
+
end
|
354
|
+
|
355
|
+
# Update hearder and query params based on authentication settings.
|
356
|
+
#
|
357
|
+
# @param [Hash] header_params Header parameters
|
358
|
+
# @param [Hash] query_params Query parameters
|
359
|
+
# @param [String] auth_names Authentication scheme name
|
360
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
361
|
+
Array(auth_names).each do |auth_name|
|
362
|
+
auth_setting = @config.auth_settings[auth_name]
|
363
|
+
next unless auth_setting
|
364
|
+
case auth_setting[:in]
|
365
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
366
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
367
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
# Sets user agent in HTTP header
|
373
|
+
#
|
374
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
375
|
+
def user_agent=(user_agent)
|
376
|
+
@user_agent = user_agent
|
377
|
+
@default_headers['User-Agent'] = @user_agent
|
378
|
+
end
|
379
|
+
|
380
|
+
# Return Accept header based on an array of accepts provided.
|
381
|
+
# @param [Array] accepts array for Accept
|
382
|
+
# @return [String] the Accept header (e.g. application/json)
|
383
|
+
def select_header_accept(accepts)
|
384
|
+
return nil if accepts.nil? || accepts.empty?
|
385
|
+
# use JSON when present, otherwise use all of the provided
|
386
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
387
|
+
json_accept || accepts.join(',')
|
388
|
+
end
|
389
|
+
|
390
|
+
# Return Content-Type header based on an array of content types provided.
|
391
|
+
# @param [Array] content_types array for Content-Type
|
392
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
393
|
+
def select_header_content_type(content_types)
|
394
|
+
# use application/json by default
|
395
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
396
|
+
# use JSON when present, otherwise use the first one
|
397
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
398
|
+
json_content_type || content_types.first
|
399
|
+
end
|
400
|
+
|
401
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
402
|
+
# @param [Object] model object to be converted into JSON string
|
403
|
+
# @return [String] JSON string representation of the object
|
404
|
+
def object_to_http_body(model)
|
405
|
+
return model if model.nil? || model.is_a?(String)
|
406
|
+
local_body = nil
|
407
|
+
if model.is_a?(Array)
|
408
|
+
local_body = model.map { |m| object_to_hash(m) }
|
409
|
+
else
|
410
|
+
local_body = object_to_hash(model)
|
411
|
+
end
|
412
|
+
local_body.to_json
|
413
|
+
end
|
414
|
+
|
415
|
+
# Convert object(non-array) to hash.
|
416
|
+
# @param [Object] obj object to be converted into JSON string
|
417
|
+
# @return [String] JSON string representation of the object
|
418
|
+
def object_to_hash(obj)
|
419
|
+
if obj.respond_to?(:to_hash)
|
420
|
+
obj.to_hash
|
421
|
+
else
|
422
|
+
obj
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
# Build parameter value according to the given collection format.
|
427
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
428
|
+
def build_collection_param(param, collection_format)
|
429
|
+
case collection_format
|
430
|
+
when :csv
|
431
|
+
param.join(',')
|
432
|
+
when :ssv
|
433
|
+
param.join(' ')
|
434
|
+
when :tsv
|
435
|
+
param.join("\t")
|
436
|
+
when :pipes
|
437
|
+
param.join('|')
|
438
|
+
when :multi
|
439
|
+
# return the array directly as typhoeus will handle it as expected
|
440
|
+
param
|
441
|
+
else
|
442
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
=begin
|
2
|
+
#API Reference
|
3
|
+
|
4
|
+
#Review our [API Introduction](../api-introduction) to get started.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 3.0.53
|
10
|
+
=end
|
11
|
+
|
12
|
+
module TurnkeyClient
|
13
|
+
class ApiError < StandardError
|
14
|
+
attr_reader :code, :response_headers, :response_body
|
15
|
+
|
16
|
+
# Usage examples:
|
17
|
+
# ApiError.new
|
18
|
+
# ApiError.new("message")
|
19
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
20
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
21
|
+
def initialize(arg = nil)
|
22
|
+
if arg.is_a? Hash
|
23
|
+
if arg.key?(:message) || arg.key?('message')
|
24
|
+
super(arg[:message] || arg['message'])
|
25
|
+
else
|
26
|
+
super arg
|
27
|
+
end
|
28
|
+
|
29
|
+
arg.each do |k, v|
|
30
|
+
instance_variable_set "@#{k}", v
|
31
|
+
end
|
32
|
+
else
|
33
|
+
super arg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Override to_s to display a friendly error message
|
38
|
+
def to_s
|
39
|
+
message
|
40
|
+
end
|
41
|
+
|
42
|
+
def message
|
43
|
+
if @message.nil?
|
44
|
+
msg = "Error message: the server returns an error"
|
45
|
+
else
|
46
|
+
msg = @message
|
47
|
+
end
|
48
|
+
|
49
|
+
msg += "\nHTTP status code: #{code}" if code
|
50
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
51
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
52
|
+
|
53
|
+
msg
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|