Sha256: 30463a190958900667fc4886d2d4662722b91ad2748184764960550ab2134f18

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Uffizzi
  module AuthHelper
    class << self
      def signed_in?
        config_data_exists? && authorized?
      end

      def sign_out
        return unless Uffizzi::ConfigFile.exists?

        Uffizzi::ConfigFile.unset_option(:cookie)
        Uffizzi::ConfigFile.unset_option(:account)
        Uffizzi::ConfigFile.unset_option(:project)
        Uffizzi::Token.delete if Uffizzi::Token.exists?
      end

      def check_login(project_option = nil)
        raise Uffizzi::Error.new('You are not logged in. Run `uffizzi login`.') unless signed_in?
        raise Uffizzi::Error.new('This command needs project to be set in config file') unless project_set?(project_option)
      end

      private

      def config_data_exists?
        ConfigFile.exists? &&
          ConfigFile.option_has_value?(:server) &&
          ConfigFile.option_has_value?(:account)
      end

      def authorized?
        ConfigFile.option_has_value?(:cookie) || Uffizzi::Token.exists?
      end

      def project_set?(project_option)
        !project_option.nil? || (Uffizzi::ConfigFile.exists? && Uffizzi::ConfigFile.option_has_value?(:project))
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
uffizzi-cli-2.4.11 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.10 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.9 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.8 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.7 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.6 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.5 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.4 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.3 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.2 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.1 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.4.0 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.3.4 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.3.3 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.3.2 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.3.1 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.3.0 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.2.2 lib/uffizzi/auth_helper.rb
uffizzi-cli-2.2.1 lib/uffizzi/auth_helper.rb