Sha256: b946929f95ed71f6812474f8f8bdcca2d57c31e06156efc89b47a2b5b24865b2

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'uffizzi'
require 'uffizzi/response_helper'
require 'uffizzi/clients/api/api_client'

module Uffizzi
  class Cli::LoginByIdentityToken
    include ApiClient

    def initialize(options)
      @options = options
    end

    def run
      token = @options[:token]
      server = @options[:server]
      params = prepare_request_params(token)
      response = create_ci_session(server, params)

      if ResponseHelper.created?(response)
        handle_succeed_response(response, server)
      else
        ResponseHelper.handle_failed_response(response)
      end
    end

    private

    def prepare_request_params(token)
      {
        user: {
          token: token,
        },
      }
    end

    def handle_succeed_response(response, server)
      ConfigFile.write_option(:server, server)
      ConfigFile.write_option(:cookie, response[:headers])
      ConfigFile.write_option(:account_id, response[:body][:account_id])
      ConfigFile.write_option(:project, response[:body][:project_slug])

      Uffizzi.ui.say('Successful Login by Identity Token')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uffizzi-cli-1.0.5 lib/uffizzi/cli/login_by_identity_token.rb
uffizzi-cli-1.0.4 lib/uffizzi/cli/login_by_identity_token.rb
uffizzi-cli-1.0.3 lib/uffizzi/cli/login_by_identity_token.rb
uffizzi-cli-1.0.2 lib/uffizzi/cli/login_by_identity_token.rb
uffizzi-cli-1.0.1 lib/uffizzi/cli/login_by_identity_token.rb
uffizzi-cli-1.0.0 lib/uffizzi/cli/login_by_identity_token.rb