permit-sdk 0.0.1

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.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/lib/api/api.rb +25 -0
  3. data/lib/api/base.rb +26 -0
  4. data/lib/api/resources.rb +13 -0
  5. data/lib/api/tenants.rb +11 -0
  6. data/lib/api/users.rb +50 -0
  7. data/lib/api/utils.rb +9 -0
  8. data/lib/config.rb +23 -0
  9. data/lib/main.rb +49 -0
  10. data/lib/openapi_client/api/api_keys_api.rb +413 -0
  11. data/lib/openapi_client/api/audit_elements_data_api.rb +118 -0
  12. data/lib/openapi_client/api/audit_logs_api.rb +204 -0
  13. data/lib/openapi_client/api/authentication_api.rb +512 -0
  14. data/lib/openapi_client/api/condition_set_rules_api.rb +278 -0
  15. data/lib/openapi_client/api/condition_sets_api.rb +428 -0
  16. data/lib/openapi_client/api/decision_logs_api.rb +128 -0
  17. data/lib/openapi_client/api/decision_logs_ingress_api.rb +90 -0
  18. data/lib/openapi_client/api/default_api.rb +297 -0
  19. data/lib/openapi_client/api/elements_configs_api.rb +657 -0
  20. data/lib/openapi_client/api/environments_api.rb +462 -0
  21. data/lib/openapi_client/api/instructions_api.rb +91 -0
  22. data/lib/openapi_client/api/members_api.rb +354 -0
  23. data/lib/openapi_client/api/opal_data_api.rb +343 -0
  24. data/lib/openapi_client/api/organizations_api.rb +652 -0
  25. data/lib/openapi_client/api/policy_api.rb +138 -0
  26. data/lib/openapi_client/api/policy_decision_points_api.rb +382 -0
  27. data/lib/openapi_client/api/policy_git_repositories_api.rb +510 -0
  28. data/lib/openapi_client/api/projects_api.rb +365 -0
  29. data/lib/openapi_client/api/resource_actions_api.rb +455 -0
  30. data/lib/openapi_client/api/resource_attributes_api.rb +473 -0
  31. data/lib/openapi_client/api/resource_instances_api.rb +425 -0
  32. data/lib/openapi_client/api/resource_roles_api.rb +813 -0
  33. data/lib/openapi_client/api/resources_api.rb +514 -0
  34. data/lib/openapi_client/api/role_assignments_api.rb +278 -0
  35. data/lib/openapi_client/api/roles_api.rb +759 -0
  36. data/lib/openapi_client/api/tenants_api.rb +603 -0
  37. data/lib/openapi_client/api/user_attributes_api.rb +458 -0
  38. data/lib/openapi_client/api/users_api.rb +684 -0
  39. data/lib/openapi_client/api/users_elements_data_api.rb +638 -0
  40. data/lib/openapi_client/api_client.rb +392 -0
  41. data/lib/openapi_client/api_error.rb +57 -0
  42. data/lib/openapi_client/configuration.rb +280 -0
  43. data/lib/openapi_client/models/action_block_editable.rb +230 -0
  44. data/lib/openapi_client/models/action_block_read.rb +255 -0
  45. data/lib/openapi_client/models/action_object.rb +275 -0
  46. data/lib/openapi_client/models/actor.rb +57 -0
  47. data/lib/openapi_client/models/add_role_permissions.rb +227 -0
  48. data/lib/openapi_client/models/api_key_create.rb +269 -0
  49. data/lib/openapi_client/models/api_key_owner_type.rb +41 -0
  50. data/lib/openapi_client/models/api_key_read.rb +329 -0
  51. data/lib/openapi_client/models/api_key_scope_read.rb +245 -0
  52. data/lib/openapi_client/models/attribute_block_editable.rb +235 -0
  53. data/lib/openapi_client/models/attribute_block_read.rb +260 -0
  54. data/lib/openapi_client/models/attribute_type.rb +44 -0
  55. data/lib/openapi_client/models/attributes.rb +231 -0
  56. data/lib/openapi_client/models/audit_log.rb +415 -0
  57. data/lib/openapi_client/models/audit_log_objects.rb +282 -0
  58. data/lib/openapi_client/models/authn_me_api_key_read.rb +329 -0
  59. data/lib/openapi_client/models/authn_me_member_read.rb +352 -0
  60. data/lib/openapi_client/models/authn_me_read.rb +224 -0
  61. data/lib/openapi_client/models/authn_me_user_read.rb +440 -0
  62. data/lib/openapi_client/models/condition_set_create.rb +340 -0
  63. data/lib/openapi_client/models/condition_set_read.rb +409 -0
  64. data/lib/openapi_client/models/condition_set_rule_create.rb +279 -0
  65. data/lib/openapi_client/models/condition_set_rule_read.rb +360 -0
  66. data/lib/openapi_client/models/condition_set_rule_remove.rb +279 -0
  67. data/lib/openapi_client/models/condition_set_type.rb +40 -0
  68. data/lib/openapi_client/models/condition_set_update.rb +255 -0
  69. data/lib/openapi_client/models/data_source_config.rb +228 -0
  70. data/lib/openapi_client/models/data_source_entry.rb +272 -0
  71. data/lib/openapi_client/models/detailed_audit_log.rb +443 -0
  72. data/lib/openapi_client/models/dev_login.rb +225 -0
  73. data/lib/openapi_client/models/dummy_engine_model.rb +229 -0
  74. data/lib/openapi_client/models/elements_config_create.rb +319 -0
  75. data/lib/openapi_client/models/elements_config_read.rb +402 -0
  76. data/lib/openapi_client/models/elements_config_runtime_read.rb +238 -0
  77. data/lib/openapi_client/models/elements_config_update.rb +268 -0
  78. data/lib/openapi_client/models/elements_env_type_read.rb +242 -0
  79. data/lib/openapi_client/models/elements_env_type_update.rb +222 -0
  80. data/lib/openapi_client/models/elements_permission_level.rb +44 -0
  81. data/lib/openapi_client/models/elements_role_read.rb +378 -0
  82. data/lib/openapi_client/models/elements_type.rb +41 -0
  83. data/lib/openapi_client/models/elements_user_create.rb +295 -0
  84. data/lib/openapi_client/models/elements_user_role_create.rb +225 -0
  85. data/lib/openapi_client/models/elements_user_role_remove.rb +225 -0
  86. data/lib/openapi_client/models/embedded_login_request_output.rb +265 -0
  87. data/lib/openapi_client/models/engine.rb +39 -0
  88. data/lib/openapi_client/models/environment_create.rb +281 -0
  89. data/lib/openapi_client/models/environment_object.rb +295 -0
  90. data/lib/openapi_client/models/environment_read.rb +335 -0
  91. data/lib/openapi_client/models/environment_stats.rb +365 -0
  92. data/lib/openapi_client/models/environment_update.rb +240 -0
  93. data/lib/openapi_client/models/failed_invite.rb +238 -0
  94. data/lib/openapi_client/models/full_data.rb +258 -0
  95. data/lib/openapi_client/models/http_validation_error.rb +221 -0
  96. data/lib/openapi_client/models/identity_read.rb +300 -0
  97. data/lib/openapi_client/models/invite_attempt_result.rb +232 -0
  98. data/lib/openapi_client/models/invite_create.rb +240 -0
  99. data/lib/openapi_client/models/invite_read.rb +325 -0
  100. data/lib/openapi_client/models/invite_status.rb +42 -0
  101. data/lib/openapi_client/models/labels.rb +238 -0
  102. data/lib/openapi_client/models/language_instructions.rb +252 -0
  103. data/lib/openapi_client/models/location_inner.rb +230 -0
  104. data/lib/openapi_client/models/login_result.rb +259 -0
  105. data/lib/openapi_client/models/member_access_level.rb +41 -0
  106. data/lib/openapi_client/models/member_access_obj.rb +41 -0
  107. data/lib/openapi_client/models/multi_invite_result.rb +238 -0
  108. data/lib/openapi_client/models/onboarding_step.rb +46 -0
  109. data/lib/openapi_client/models/opa_decision_log.rb +288 -0
  110. data/lib/openapi_client/models/opa_engine_decision_log.rb +345 -0
  111. data/lib/openapi_client/models/opa_labels.rb +238 -0
  112. data/lib/openapi_client/models/opa_metrics.rb +273 -0
  113. data/lib/openapi_client/models/opal_client.rb +305 -0
  114. data/lib/openapi_client/models/org_member_read.rb +420 -0
  115. data/lib/openapi_client/models/org_member_update.rb +230 -0
  116. data/lib/openapi_client/models/organization_create.rb +292 -0
  117. data/lib/openapi_client/models/organization_object.rb +295 -0
  118. data/lib/openapi_client/models/organization_read.rb +295 -0
  119. data/lib/openapi_client/models/organization_read_with_api_key.rb +313 -0
  120. data/lib/openapi_client/models/organization_update.rb +247 -0
  121. data/lib/openapi_client/models/paginated_result_api_key_read.rb +285 -0
  122. data/lib/openapi_client/models/paginated_result_audit_log.rb +285 -0
  123. data/lib/openapi_client/models/paginated_result_elements_config_read.rb +285 -0
  124. data/lib/openapi_client/models/paginated_result_opa_decision_log.rb +285 -0
  125. data/lib/openapi_client/models/paginated_result_user_read.rb +285 -0
  126. data/lib/openapi_client/models/pdp.rb +259 -0
  127. data/lib/openapi_client/models/pdp_config_object.rb +258 -0
  128. data/lib/openapi_client/models/pdp_config_read.rb +292 -0
  129. data/lib/openapi_client/models/pdp_context.rb +291 -0
  130. data/lib/openapi_client/models/pdp_state.rb +224 -0
  131. data/lib/openapi_client/models/pdp_state_update.rb +238 -0
  132. data/lib/openapi_client/models/pdp_values.rb +252 -0
  133. data/lib/openapi_client/models/permission_level_role_read.rb +254 -0
  134. data/lib/openapi_client/models/policy_repo_create.rb +318 -0
  135. data/lib/openapi_client/models/policy_repo_read.rb +347 -0
  136. data/lib/openapi_client/models/policy_repo_status.rb +41 -0
  137. data/lib/openapi_client/models/programming_language.rb +43 -0
  138. data/lib/openapi_client/models/project_create.rb +318 -0
  139. data/lib/openapi_client/models/project_object.rb +295 -0
  140. data/lib/openapi_client/models/project_read.rb +357 -0
  141. data/lib/openapi_client/models/project_update.rb +250 -0
  142. data/lib/openapi_client/models/raw_data.rb +329 -0
  143. data/lib/openapi_client/models/relationship_tuple_object.rb +252 -0
  144. data/lib/openapi_client/models/remote_config.rb +256 -0
  145. data/lib/openapi_client/models/remove_role_permissions.rb +227 -0
  146. data/lib/openapi_client/models/resource_action_create.rb +271 -0
  147. data/lib/openapi_client/models/resource_action_read.rb +370 -0
  148. data/lib/openapi_client/models/resource_action_update.rb +230 -0
  149. data/lib/openapi_client/models/resource_attribute_create.rb +271 -0
  150. data/lib/openapi_client/models/resource_attribute_read.rb +370 -0
  151. data/lib/openapi_client/models/resource_attribute_update.rb +230 -0
  152. data/lib/openapi_client/models/resource_attributes.rb +238 -0
  153. data/lib/openapi_client/models/resource_create.rb +310 -0
  154. data/lib/openapi_client/models/resource_id.rb +230 -0
  155. data/lib/openapi_client/models/resource_instance_create.rb +281 -0
  156. data/lib/openapi_client/models/resource_instance_read.rb +375 -0
  157. data/lib/openapi_client/models/resource_instance_update.rb +220 -0
  158. data/lib/openapi_client/models/resource_read.rb +374 -0
  159. data/lib/openapi_client/models/resource_replace.rb +274 -0
  160. data/lib/openapi_client/models/resource_role_create.rb +295 -0
  161. data/lib/openapi_client/models/resource_role_read.rb +379 -0
  162. data/lib/openapi_client/models/resource_role_update.rb +254 -0
  163. data/lib/openapi_client/models/resource_type_object.rb +286 -0
  164. data/lib/openapi_client/models/resource_update.rb +264 -0
  165. data/lib/openapi_client/models/role_assignment_create.rb +255 -0
  166. data/lib/openapi_client/models/role_assignment_read.rb +375 -0
  167. data/lib/openapi_client/models/role_assignment_remove.rb +255 -0
  168. data/lib/openapi_client/models/role_block.rb +244 -0
  169. data/lib/openapi_client/models/role_create.rb +295 -0
  170. data/lib/openapi_client/models/role_data.rb +221 -0
  171. data/lib/openapi_client/models/role_read.rb +364 -0
  172. data/lib/openapi_client/models/role_update.rb +254 -0
  173. data/lib/openapi_client/models/settings.rb +231 -0
  174. data/lib/openapi_client/models/ssh_auth_data.rb +295 -0
  175. data/lib/openapi_client/models/statistics.rb +389 -0
  176. data/lib/openapi_client/models/tenant_create.rb +281 -0
  177. data/lib/openapi_client/models/tenant_object.rb +284 -0
  178. data/lib/openapi_client/models/tenant_read.rb +365 -0
  179. data/lib/openapi_client/models/tenant_update.rb +240 -0
  180. data/lib/openapi_client/models/user_create.rb +286 -0
  181. data/lib/openapi_client/models/user_data.rb +232 -0
  182. data/lib/openapi_client/models/user_login_request_input.rb +240 -0
  183. data/lib/openapi_client/models/user_object.rb +313 -0
  184. data/lib/openapi_client/models/user_read.rb +336 -0
  185. data/lib/openapi_client/models/user_role.rb +240 -0
  186. data/lib/openapi_client/models/user_role_create.rb +240 -0
  187. data/lib/openapi_client/models/user_role_remove.rb +240 -0
  188. data/lib/openapi_client/models/user_update.rb +250 -0
  189. data/lib/openapi_client/models/validation_error.rb +254 -0
  190. data/lib/openapi_client/models/webhook_create.rb +235 -0
  191. data/lib/openapi_client/models/webhook_read.rb +315 -0
  192. data/lib/openapi_client/models/webhook_update.rb +230 -0
  193. data/lib/openapi_client/version.rb +15 -0
  194. data/lib/openapi_client.rb +220 -0
  195. data/lib/permit.rb +58 -0
  196. metadata +251 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2f70db526a9e0faffa1d423e5d6ebdc7561aecfffb2626e4f5350f351624153
4
+ data.tar.gz: 2414147d8ac281e8853405ca121d8cc32cddb9410a46f566cb0af5f2d60b62b9
5
+ SHA512:
6
+ metadata.gz: 504f160a6ecf37c0bc4755a2a58d871832e25f16a36ba1590717bec092e3a49dc63963aa3eb5527a2bf3611ff66d57e6b3d954883b7a6b98bddb23fe9438b2dd
7
+ data.tar.gz: 4ba505adc4f43973e0c05461bb9bcaa30cd39ceff2f44d648f083d47b92f5671854e2e9fb481f3cf905dd75985fc5d145de5054e020e336244e618e736e4e09a
data/lib/api/api.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'openapi_client'
2
+ require_relative 'users'
3
+ require_relative 'resources'
4
+ require_relative 'utils'
5
+ require_relative 'tenants'
6
+
7
+ class PermitApiClient
8
+ attr_accessor :config, :logger, :client, :tenants, :resources, :roles, :users, :elements
9
+
10
+ def initialize(config, logger)
11
+
12
+ OpenapiClient.configure do |openapi_config|
13
+ openapi_config.scheme = Utils.get_schema_from_url(config.api_url)
14
+ openapi_config.host = Utils.get_host_from_url(config.api_url)
15
+ openapi_config.access_token = config.token
16
+ end
17
+ @config = config
18
+ @logger = logger
19
+ @users = UsersApi.new(OpenapiClient::UsersApi.new, config, logger)
20
+ @tenants = TenantsApi.new(OpenapiClient::TenantsApi.new, config, logger)
21
+ @resources = ResourcesApi.new(OpenapiClient::ResourcesApi.new, config, logger)
22
+ # @roles = RolesApi.new(OpenapiClient::RolesApi.new, config, logger)
23
+ # @elements = ElementsApi.new(OpenapiClient::ElementsConfigsApi.new, config, logger)
24
+ end
25
+ end
data/lib/api/base.rb ADDED
@@ -0,0 +1,26 @@
1
+
2
+ class PermitBaseApi
3
+ attr_accessor :client, :config, :logger
4
+
5
+ def lazy_load_context
6
+ # If the instance config context is nil, we need to load it from the server
7
+ OpenapiClient.configure do |openapi_config|
8
+ openapi_config.scheme = Utils.get_schema_from_url(config.api_url)
9
+ openapi_config.host = Utils.get_host_from_url(config.api_url)
10
+ openapi_config.access_token = config.token
11
+ openapi_config.server_operation_index = {}
12
+ openapi_config.server_index = nil
13
+ end
14
+ client = OpenapiClient::APIKeysApi.new
15
+ if @config.context.nil?
16
+ @config.context = client.get_api_key_scope
17
+ end
18
+ end
19
+
20
+ def initialize(client, config, logger)
21
+ @logger = logger
22
+ @config = config
23
+ @client = client
24
+ end
25
+
26
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base'
2
+
3
+ class ResourcesApi < PermitBaseApi
4
+ def initialize(client, config, logger)
5
+ super
6
+ end
7
+
8
+ def get(resource_key)
9
+
10
+ data = @client.get_tenant(config.context.project, config.context.project, resource_key)
11
+ data
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'base'
2
+ class TenantsApi < PermitBaseApi
3
+ def initialize(client, config, logger)
4
+ super
5
+ end
6
+
7
+ def get(tenant_key)
8
+ data = @client.get_tenant(config.context.project, config.context.project, tenant_key)
9
+ data
10
+ end
11
+ end
data/lib/api/users.rb ADDED
@@ -0,0 +1,50 @@
1
+ require_relative 'base'
2
+
3
+ class UsersApi < PermitBaseApi
4
+ def initialize(client, config, logger)
5
+ super
6
+ end
7
+
8
+ def get(user_key)
9
+ lazy_load_context
10
+ data = @client.get_user(config.context.project_id, config.context.environment_id, user_key)
11
+ data
12
+ end
13
+
14
+
15
+ def sync_user(user)
16
+ lazy_load_context
17
+ raise KeyError.new("Required UserCreate or hash object") if user.is_a?(String)
18
+ user_key = user.is_a?(Hash) ? user.delete(:key) : user.key
19
+ raise KeyError.new("required 'key' in input dictionary") if user_key.nil?
20
+
21
+ # check if the user key already exists
22
+ logger.info("checking if user '#{user_key}' already exists")
23
+ begin
24
+ user_to_update = @client.get_user(config.context.project_id, config.context.environment_id, user_key)
25
+ rescue OpenapiClient::ApiError => e
26
+ if e.code == 404
27
+ # if the user does not exist, create it
28
+ logger.info("user does not exist, creating it...")
29
+ user_create = user.is_a?(Hash) ? OpenapiClient::UserCreate.new(user.merge("key" => user_key)) : user
30
+ created_user = @client.create_user(config.context.project_id, config.context.environment_id, user_create)
31
+ return created_user
32
+ else
33
+ raise e
34
+ end
35
+ end
36
+ if user_to_update
37
+ # if the user exists update it
38
+ logger.info("user exists, updating it...")
39
+ unless user.is_a?(Hash)
40
+ user = user.instance_variables.map { |var| [var.to_s.delete("@"), user.instance_variable_get(var)] }.to_h.except("key")
41
+ end
42
+ if user.empty?
43
+ raise "empty user object, nothing to update"
44
+ end
45
+ user_update = OpenapiClient::UserUpdate.new(user)
46
+ updated_user = @client.update_user(config.context.project_id, config.context.environment_id, user_key, user_update)
47
+ return updated_user
48
+ end
49
+ end
50
+ end
data/lib/api/utils.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Utils
2
+ def self.get_schema_from_url(url)
3
+ url.split(':')[0]
4
+ end
5
+
6
+ def self.get_host_from_url(url)
7
+ url.split(':')[1].split('/')[2]
8
+ end
9
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,23 @@
1
+ class PermitConfig
2
+ #
3
+ # This class is used to configure the Permit SDK. It is used to set the base url of the PDP and the api key.
4
+ #
5
+ # Example:
6
+ #
7
+ # ```ruby
8
+ # permit = Permit::Permit.new
9
+ # permit.config.base_url = 'https://pdp.permit.io'
10
+ # permit.config
11
+ # ```
12
+ attr_accessor :api_url, :token, :pdp_url, :context, :debug, :logger
13
+
14
+ def initialize( token, api_url = DEFAULT_API_URL, pdp_url = DEFAULT_PDP_URL,context = nil, debug = false, logger = nil)
15
+ @api_url = api_url
16
+ @pdp_url = pdp_url
17
+ @context = context
18
+ @token = token
19
+ @debug = debug
20
+ @logger = logger
21
+ end
22
+
23
+ end
data/lib/main.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'webrick'
2
+ require_relative 'permit'
3
+
4
+ permit = Permit.new( "TOKEN")
5
+
6
+ server = WEBrick::HTTPServer.new(Port: 3000)
7
+
8
+ server.mount_proc '/' do |_, res|
9
+ res['Content-Type'] = 'application/json'
10
+ user = { id: "daniel@permit.io", first_name: nil, last_name: nil, email: "daniel@permit.io" }
11
+
12
+ permitted = permit.check("daniel@permit.io", "create", "Blog_Post")
13
+ if permitted
14
+ res.status = 200
15
+ res.body = { result: "#{user[:first_name]} #{user[:last_name]} is PERMITTED to create Blog_Post!" }.to_json
16
+ next
17
+ end
18
+ res.status = 403
19
+ res.body = { result: "#{user[:first_name]} #{user[:last_name]} is NOT PERMITTED to create Blog_Post!" }.to_json
20
+ end
21
+
22
+ trap 'INT' do server.shutdown end
23
+
24
+ server.start
25
+
26
+
27
+ # require_relative 'permit'
28
+ # require_relative 'openapi_client/models/user_create'
29
+ # permit = Permit.new('token')
30
+ # a = permit.api.users.get("asdf12")
31
+ # # allow = permit.check('daniel@permit.io', 'create', 'Blog_Post:123')
32
+ # # if allow
33
+ # # puts "Allow"
34
+ # # else
35
+ # # puts "Deny"
36
+ # # end
37
+ # #
38
+ # # allow = permit.check({"key": "daniel@permit.io"}, 'create', {"type":"Blog_Post","tenant":"default", "key":"123"})
39
+ # # if allow
40
+ # # puts "Allow"
41
+ # # else
42
+ # # puts "Deny"
43
+ # # end
44
+ # user = OpenapiClient::UserCreate.new(key: "asdf1234", email: "raz@maiol.com", first_name: "Raz", last_name: "Ma")
45
+ # a = permit.sync_user(user)
46
+ # puts a
47
+ #
48
+ # a = permit.sync_user({ key: "asdf12345", email: "raz@maiol.com", first_name: "Raz", last_name: "Ma" })
49
+ # puts a
@@ -0,0 +1,413 @@
1
+ =begin
2
+ #Permit.io API
3
+
4
+ # Authorization as a service
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.2.1
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module OpenapiClient
16
+ class APIKeysApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Create Api Key
23
+ # Creates a new api_key under the active organization.
24
+ # @param api_key_create [APIKeyCreate]
25
+ # @param [Hash] opts the optional parameters
26
+ # @return [APIKeyRead]
27
+ def create_api_key(api_key_create, opts = {})
28
+ data, _status_code, _headers = create_api_key_with_http_info(api_key_create, opts)
29
+ data
30
+ end
31
+
32
+ # Create Api Key
33
+ # Creates a new api_key under the active organization.
34
+ # @param api_key_create [APIKeyCreate]
35
+ # @param [Hash] opts the optional parameters
36
+ # @return [Array<(APIKeyRead, Integer, Hash)>] APIKeyRead data, response status code and response headers
37
+ def create_api_key_with_http_info(api_key_create, opts = {})
38
+ if @api_client.config.debugging
39
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.create_api_key ...'
40
+ end
41
+ # verify the required parameter 'api_key_create' is set
42
+ if @api_client.config.client_side_validation && api_key_create.nil?
43
+ fail ArgumentError, "Missing the required parameter 'api_key_create' when calling APIKeysApi.create_api_key"
44
+ end
45
+ # resource path
46
+ local_var_path = '/v2/api-key'
47
+
48
+ # query parameters
49
+ query_params = opts[:query_params] || {}
50
+
51
+ # header parameters
52
+ header_params = opts[:header_params] || {}
53
+ # HTTP header 'Accept' (if needed)
54
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
55
+ # HTTP header 'Content-Type'
56
+ content_type = @api_client.select_header_content_type(['application/json'])
57
+ if !content_type.nil?
58
+ header_params['Content-Type'] = content_type
59
+ end
60
+
61
+ # form parameters
62
+ form_params = opts[:form_params] || {}
63
+
64
+ # http body (model)
65
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(api_key_create)
66
+
67
+ # return_type
68
+ return_type = opts[:debug_return_type] || 'APIKeyRead'
69
+
70
+ # auth_names
71
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
72
+
73
+ new_options = opts.merge(
74
+ :operation => :"APIKeysApi.create_api_key",
75
+ :header_params => header_params,
76
+ :query_params => query_params,
77
+ :form_params => form_params,
78
+ :body => post_body,
79
+ :auth_names => auth_names,
80
+ :return_type => return_type
81
+ )
82
+
83
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
84
+ if @api_client.config.debugging
85
+ @api_client.config.logger.debug "API called: APIKeysApi#create_api_key\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
86
+ end
87
+ return data, status_code, headers
88
+ end
89
+
90
+ # Delete Api Key
91
+ # Deletes the api_key and all its related data.
92
+ # @param api_key_id [String] The unique id of the API key
93
+ # @param [Hash] opts the optional parameters
94
+ # @return [nil]
95
+ def delete_api_key(api_key_id, opts = {})
96
+ delete_api_key_with_http_info(api_key_id, opts)
97
+ nil
98
+ end
99
+
100
+ # Delete Api Key
101
+ # Deletes the api_key and all its related data.
102
+ # @param api_key_id [String] The unique id of the API key
103
+ # @param [Hash] opts the optional parameters
104
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
105
+ def delete_api_key_with_http_info(api_key_id, opts = {})
106
+ if @api_client.config.debugging
107
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.delete_api_key ...'
108
+ end
109
+ # verify the required parameter 'api_key_id' is set
110
+ if @api_client.config.client_side_validation && api_key_id.nil?
111
+ fail ArgumentError, "Missing the required parameter 'api_key_id' when calling APIKeysApi.delete_api_key"
112
+ end
113
+ # resource path
114
+ local_var_path = '/v2/api-key/{api_key_id}'.sub('{' + 'api_key_id' + '}', CGI.escape(api_key_id.to_s))
115
+
116
+ # query parameters
117
+ query_params = opts[:query_params] || {}
118
+
119
+ # header parameters
120
+ header_params = opts[:header_params] || {}
121
+ # HTTP header 'Accept' (if needed)
122
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
123
+
124
+ # form parameters
125
+ form_params = opts[:form_params] || {}
126
+
127
+ # http body (model)
128
+ post_body = opts[:debug_body]
129
+
130
+ # return_type
131
+ return_type = opts[:debug_return_type]
132
+
133
+ # auth_names
134
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
135
+
136
+ new_options = opts.merge(
137
+ :operation => :"APIKeysApi.delete_api_key",
138
+ :header_params => header_params,
139
+ :query_params => query_params,
140
+ :form_params => form_params,
141
+ :body => post_body,
142
+ :auth_names => auth_names,
143
+ :return_type => return_type
144
+ )
145
+
146
+ data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
147
+ if @api_client.config.debugging
148
+ @api_client.config.logger.debug "API called: APIKeysApi#delete_api_key\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
149
+ end
150
+ return data, status_code, headers
151
+ end
152
+
153
+ # Get Api Key
154
+ # Gets a single api_key matching the given api_key_id, if such api_key exists.
155
+ # @param api_key_id [String] The unique id of the API key
156
+ # @param [Hash] opts the optional parameters
157
+ # @return [APIKeyRead]
158
+ def get_api_key(api_key_id, opts = {})
159
+ data, _status_code, _headers = get_api_key_with_http_info(api_key_id, opts)
160
+ data
161
+ end
162
+
163
+ # Get Api Key
164
+ # Gets a single api_key matching the given api_key_id, if such api_key exists.
165
+ # @param api_key_id [String] The unique id of the API key
166
+ # @param [Hash] opts the optional parameters
167
+ # @return [Array<(APIKeyRead, Integer, Hash)>] APIKeyRead data, response status code and response headers
168
+ def get_api_key_with_http_info(api_key_id, opts = {})
169
+ if @api_client.config.debugging
170
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.get_api_key ...'
171
+ end
172
+ # verify the required parameter 'api_key_id' is set
173
+ if @api_client.config.client_side_validation && api_key_id.nil?
174
+ fail ArgumentError, "Missing the required parameter 'api_key_id' when calling APIKeysApi.get_api_key"
175
+ end
176
+ # resource path
177
+ local_var_path = '/v2/api-key/{api_key_id}'.sub('{' + 'api_key_id' + '}', CGI.escape(api_key_id.to_s))
178
+
179
+ # query parameters
180
+ query_params = opts[:query_params] || {}
181
+
182
+ # header parameters
183
+ header_params = opts[:header_params] || {}
184
+ # HTTP header 'Accept' (if needed)
185
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
186
+
187
+ # form parameters
188
+ form_params = opts[:form_params] || {}
189
+
190
+ # http body (model)
191
+ post_body = opts[:debug_body]
192
+
193
+ # return_type
194
+ return_type = opts[:debug_return_type] || 'APIKeyRead'
195
+
196
+ # auth_names
197
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
198
+
199
+ new_options = opts.merge(
200
+ :operation => :"APIKeysApi.get_api_key",
201
+ :header_params => header_params,
202
+ :query_params => query_params,
203
+ :form_params => form_params,
204
+ :body => post_body,
205
+ :auth_names => auth_names,
206
+ :return_type => return_type
207
+ )
208
+
209
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
210
+ if @api_client.config.debugging
211
+ @api_client.config.logger.debug "API called: APIKeysApi#get_api_key\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
212
+ end
213
+ return data, status_code, headers
214
+ end
215
+
216
+ # Get Api Key Scope
217
+ # @param [Hash] opts the optional parameters
218
+ # @return [APIKeyScopeRead]
219
+ def get_api_key_scope(opts = {})
220
+ data, _status_code, _headers = get_api_key_scope_with_http_info(opts)
221
+ data
222
+ end
223
+
224
+ # Get Api Key Scope
225
+ # @param [Hash] opts the optional parameters
226
+ # @return [Array<(APIKeyScopeRead, Integer, Hash)>] APIKeyScopeRead data, response status code and response headers
227
+ def get_api_key_scope_with_http_info(opts = {})
228
+ if @api_client.config.debugging
229
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.get_api_key_scope ...'
230
+ end
231
+ # resource path
232
+ local_var_path = '/v2/api-key/scope'
233
+
234
+ # query parameters
235
+ query_params = opts[:query_params] || {}
236
+
237
+ # header parameters
238
+ header_params = opts[:header_params] || {}
239
+ # HTTP header 'Accept' (if needed)
240
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
241
+
242
+ # form parameters
243
+ form_params = opts[:form_params] || {}
244
+
245
+ # http body (model)
246
+ post_body = opts[:debug_body]
247
+
248
+ # return_type
249
+ return_type = opts[:debug_return_type] || 'APIKeyScopeRead'
250
+
251
+ # auth_names
252
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
253
+
254
+ new_options = opts.merge(
255
+ :operation => :"APIKeysApi.get_api_key_scope",
256
+ :header_params => header_params,
257
+ :query_params => query_params,
258
+ :form_params => form_params,
259
+ :body => post_body,
260
+ :auth_names => auth_names,
261
+ :return_type => return_type
262
+ )
263
+
264
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
265
+ if @api_client.config.debugging
266
+ @api_client.config.logger.debug "API called: APIKeysApi#get_api_key_scope\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
267
+ end
268
+ return data, status_code, headers
269
+ end
270
+
271
+ # Get Environment Api Key
272
+ # @param proj_id [String] Either the unique id of the project, or the URL-friendly key of the project (i.e: the \&quot;slug\&quot;).
273
+ # @param env_id [String] Either the unique id of the environment, or the URL-friendly key of the environment (i.e: the \&quot;slug\&quot;).
274
+ # @param [Hash] opts the optional parameters
275
+ # @return [APIKeyRead]
276
+ def get_environment_api_key(proj_id, env_id, opts = {})
277
+ data, _status_code, _headers = get_environment_api_key_with_http_info(proj_id, env_id, opts)
278
+ data
279
+ end
280
+
281
+ # Get Environment Api Key
282
+ # @param proj_id [String] Either the unique id of the project, or the URL-friendly key of the project (i.e: the \&quot;slug\&quot;).
283
+ # @param env_id [String] Either the unique id of the environment, or the URL-friendly key of the environment (i.e: the \&quot;slug\&quot;).
284
+ # @param [Hash] opts the optional parameters
285
+ # @return [Array<(APIKeyRead, Integer, Hash)>] APIKeyRead data, response status code and response headers
286
+ def get_environment_api_key_with_http_info(proj_id, env_id, opts = {})
287
+ if @api_client.config.debugging
288
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.get_environment_api_key ...'
289
+ end
290
+ # verify the required parameter 'proj_id' is set
291
+ if @api_client.config.client_side_validation && proj_id.nil?
292
+ fail ArgumentError, "Missing the required parameter 'proj_id' when calling APIKeysApi.get_environment_api_key"
293
+ end
294
+ # verify the required parameter 'env_id' is set
295
+ if @api_client.config.client_side_validation && env_id.nil?
296
+ fail ArgumentError, "Missing the required parameter 'env_id' when calling APIKeysApi.get_environment_api_key"
297
+ end
298
+ # resource path
299
+ local_var_path = '/v2/api-key/{proj_id}/{env_id}'.sub('{' + 'proj_id' + '}', CGI.escape(proj_id.to_s)).sub('{' + 'env_id' + '}', CGI.escape(env_id.to_s))
300
+
301
+ # query parameters
302
+ query_params = opts[:query_params] || {}
303
+
304
+ # header parameters
305
+ header_params = opts[:header_params] || {}
306
+ # HTTP header 'Accept' (if needed)
307
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
308
+
309
+ # form parameters
310
+ form_params = opts[:form_params] || {}
311
+
312
+ # http body (model)
313
+ post_body = opts[:debug_body]
314
+
315
+ # return_type
316
+ return_type = opts[:debug_return_type] || 'APIKeyRead'
317
+
318
+ # auth_names
319
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
320
+
321
+ new_options = opts.merge(
322
+ :operation => :"APIKeysApi.get_environment_api_key",
323
+ :header_params => header_params,
324
+ :query_params => query_params,
325
+ :form_params => form_params,
326
+ :body => post_body,
327
+ :auth_names => auth_names,
328
+ :return_type => return_type
329
+ )
330
+
331
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
332
+ if @api_client.config.debugging
333
+ @api_client.config.logger.debug "API called: APIKeysApi#get_environment_api_key\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
334
+ end
335
+ return data, status_code, headers
336
+ end
337
+
338
+ # List Api Keys
339
+ # Lists all the api_keys under the active organization.
340
+ # @param [Hash] opts the optional parameters
341
+ # @option opts [Integer] :page Page number of the results to fetch, starting at 1. (default to 1)
342
+ # @option opts [Integer] :per_page The number of results per page (max 100). (default to 30)
343
+ # @return [PaginatedResultAPIKeyRead]
344
+ def list_api_keys(opts = {})
345
+ data, _status_code, _headers = list_api_keys_with_http_info(opts)
346
+ data
347
+ end
348
+
349
+ # List Api Keys
350
+ # Lists all the api_keys under the active organization.
351
+ # @param [Hash] opts the optional parameters
352
+ # @option opts [Integer] :page Page number of the results to fetch, starting at 1. (default to 1)
353
+ # @option opts [Integer] :per_page The number of results per page (max 100). (default to 30)
354
+ # @return [Array<(PaginatedResultAPIKeyRead, Integer, Hash)>] PaginatedResultAPIKeyRead data, response status code and response headers
355
+ def list_api_keys_with_http_info(opts = {})
356
+ if @api_client.config.debugging
357
+ @api_client.config.logger.debug 'Calling API: APIKeysApi.list_api_keys ...'
358
+ end
359
+ if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'] < 1
360
+ fail ArgumentError, 'invalid value for "opts[:"page"]" when calling APIKeysApi.list_api_keys, must be greater than or equal to 1.'
361
+ end
362
+
363
+ if @api_client.config.client_side_validation && !opts[:'per_page'].nil? && opts[:'per_page'] > 100
364
+ fail ArgumentError, 'invalid value for "opts[:"per_page"]" when calling APIKeysApi.list_api_keys, must be smaller than or equal to 100.'
365
+ end
366
+
367
+ if @api_client.config.client_side_validation && !opts[:'per_page'].nil? && opts[:'per_page'] < 1
368
+ fail ArgumentError, 'invalid value for "opts[:"per_page"]" when calling APIKeysApi.list_api_keys, must be greater than or equal to 1.'
369
+ end
370
+
371
+ # resource path
372
+ local_var_path = '/v2/api-key'
373
+
374
+ # query parameters
375
+ query_params = opts[:query_params] || {}
376
+ query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
377
+ query_params[:'per_page'] = opts[:'per_page'] if !opts[:'per_page'].nil?
378
+
379
+ # header parameters
380
+ header_params = opts[:header_params] || {}
381
+ # HTTP header 'Accept' (if needed)
382
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
383
+
384
+ # form parameters
385
+ form_params = opts[:form_params] || {}
386
+
387
+ # http body (model)
388
+ post_body = opts[:debug_body]
389
+
390
+ # return_type
391
+ return_type = opts[:debug_return_type] || 'PaginatedResultAPIKeyRead'
392
+
393
+ # auth_names
394
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
395
+
396
+ new_options = opts.merge(
397
+ :operation => :"APIKeysApi.list_api_keys",
398
+ :header_params => header_params,
399
+ :query_params => query_params,
400
+ :form_params => form_params,
401
+ :body => post_body,
402
+ :auth_names => auth_names,
403
+ :return_type => return_type
404
+ )
405
+
406
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
407
+ if @api_client.config.debugging
408
+ @api_client.config.logger.debug "API called: APIKeysApi#list_api_keys\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
409
+ end
410
+ return data, status_code, headers
411
+ end
412
+ end
413
+ end