Module: Terjira::Client::AuthOptionBuilder

Included in:
Base
Defined in:
lib/terjira/client/auth_option_builder.rb

Constant Summary collapse

AUTH_CACHE_KEY =
'auth'.freeze

Instance Method Summary collapse

Instance Method Details

#auth_file_cacheObject



37
38
39
# File 'lib/terjira/client/auth_option_builder.rb', line 37

def auth_file_cache
  @auth_file_cache ||= Terjira::FileCache.new('profile')
end

#build_auth_options(cache_key = AUTH_CACHE_KEY) ⇒ Object



9
10
11
12
13
# File 'lib/terjira/client/auth_option_builder.rb', line 9

def build_auth_options(cache_key = AUTH_CACHE_KEY)
  auth_file_cache.fetch cache_key do
    build_auth_options_by_tty
  end
end

#build_auth_options_by_cached(cache_key = AUTH_CACHE_KEY) ⇒ Object



15
16
17
# File 'lib/terjira/client/auth_option_builder.rb', line 15

def build_auth_options_by_cached(cache_key = AUTH_CACHE_KEY)
  auth_file_cache.get(cache_key)
end

#build_auth_options_by_ttyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/terjira/client/auth_option_builder.rb', line 23

def build_auth_options_by_tty
  puts 'Login will be required...'
  prompt = TTY::Prompt.new

  result = prompt.collect do
    key(:site).ask('Site:', required: true)
    key(:context_path).ask('Context path:', default: '')
    key(:username).ask('Username:', required: true)
    key(:password).mask('Password:', required: true)
  end
  result[:auth_type] = :basic
  result
end

#expire_auth_options(cache_key = AUTH_CACHE_KEY) ⇒ Object



19
20
21
# File 'lib/terjira/client/auth_option_builder.rb', line 19

def expire_auth_options(cache_key = AUTH_CACHE_KEY)
  auth_file_cache.delete(cache_key)
end