# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. # typed: true # frozen_string_literal: true require 'faraday' require 'faraday/multipart' require 'sorbet-runtime' module SpeakeasyClientSDK extend T::Sig class Auth extend T::Sig # REST APIs for managing Authentication sig { params(sdk_config: SDKConfiguration).void } def initialize(sdk_config) @sdk_configuration = sdk_config end sig { params(request: T.nilable(::SpeakeasyClientSDK::Operations::GetAccessTokenRequest)).returns(::SpeakeasyClientSDK::Operations::GetAccessTokenResponse) } def get_access_token(request) # get_access_token - Get or refresh an access token for the current workspace. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/v1/auth/access_token" headers = {} query_params = Utils.get_query_params(::SpeakeasyClientSDK::Operations::GetAccessTokenRequest, request, @sdk_configuration.globals) headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers req.params = query_params end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::SpeakeasyClientSDK::Operations::GetAccessTokenResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::AccessToken) res.access_token = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::Error) res.error = out end end res end sig { returns(::SpeakeasyClientSDK::Operations::GetUserResponse) } def get_user # get_user - Get information about the current user. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/v1/user" headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::SpeakeasyClientSDK::Operations::GetUserResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::User) res.user = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::Error) res.error = out end end res end sig { params(request: T.nilable(::SpeakeasyClientSDK::Operations::GetWorkspaceAccessRequest)).returns(::SpeakeasyClientSDK::Operations::GetWorkspaceAccessResponse) } def get_workspace_access(request) # get_workspace_access - Get access allowances for a particular workspace # Checks if generation is permitted for a particular run of the CLI url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/v1/workspace/access" headers = {} query_params = Utils.get_query_params(::SpeakeasyClientSDK::Operations::GetWorkspaceAccessRequest, request, @sdk_configuration.globals) headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers req.params = query_params Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::SpeakeasyClientSDK::Operations::GetWorkspaceAccessResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::AccessDetails) res.access_details = out end end res end sig { returns(::SpeakeasyClientSDK::Operations::ValidateApiKeyResponse) } def validate_api_key # validate_api_key - Validate the current api key. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/v1/auth/validate" headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::SpeakeasyClientSDK::Operations::ValidateApiKeyResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::ApiKeyDetails) res.api_key_details = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::SpeakeasyClientSDK::Shared::Error) res.error = out end end res end end end