Class: Terraspace::Cloud::Api::Cani
- Inherits:
-
Object
- Object
- Terraspace::Cloud::Api::Cani
- Includes:
- Util::Logging
- Defined in:
- lib/terraspace/cloud/api/cani.rb
Defined Under Namespace
Classes: Cannot
Instance Method Summary collapse
-
#handle(exit_on_error = true) ⇒ Object
Example http responses: are authorized to perform this action.”,“status”:200,“title”:“Authoriz… {”errors“:[{”detail“:”You are not authorized to perform this action. Double check your token or check with your admin that you have permissions.“,”status“:403,”title“:”Forbidden“]}.
-
#initialize(result) ⇒ Cani
constructor
A new instance of Cani.
Methods included from Util::Logging
Constructor Details
#initialize(result) ⇒ Cani
Returns a new instance of Cani.
6 7 8 |
# File 'lib/terraspace/cloud/api/cani.rb', line 6 def initialize(result) @result = result end |
Instance Method Details
#handle(exit_on_error = true) ⇒ Object
Example http responses: are authorized to perform this action.”,“status”:200,“title”:“Authoriz… {”errors“:[{”detail“:”You are not authorized to perform this action. Double check your token or check with your admin that you have permissions.“,”status“:403,”title“:”Forbidden“]}
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/terraspace/cloud/api/cani.rb', line 13 def handle(exit_on_error=true) yes = false # assume do not have permission detail = @result&.dig('data', 'attributes', 'detail') if detail&.include?('You are authorized to perform this action') yes = true # confirm have permission end return if yes if exit_on_error if @result.nil? # 400 Bad Request logger.info "ERROR: It doesn't look like TS_TOKEN is valid".color(:red) else errors = @result.dig('errors') detail = errors.first['detail'] # {"errors":[{"detail":"You are not authorized to perform this action. Double check your token or check with your admin that you have permissions.","status":403,"title":"Forbidden"}]} logger.info "ERROR: #{detail}".color(:red) end exit 1 else @result # original http response with error info end end |