Sha256: 3757d77a7f7bc0d6fafb867d5ce2365aa5c543845ef0ebbead5e5122e03653ed

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

class Terraspace::Cloud::Api
  class Cani
    class Cannot < Terraspace::Error; end
    include Terraspace::Util::Logging

    def initialize(result)
      @result = result
    end

    # Example http responses:
    # {"data":{"attributes":{"detail":"You 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"}]}
    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
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.16 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.15 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.14 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.13 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.12 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.11 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.10 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.9 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.8 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.7 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.6 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.5 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.4 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.3 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.2 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.1 lib/terraspace/cloud/api/cani.rb
terraspace-2.2.0 lib/terraspace/cloud/api/cani.rb
terraspace-2.1.7 lib/terraspace/cloud/api/cani.rb
terraspace-2.1.6 lib/terraspace/cloud/api/cani.rb