Class: Sem::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sem/configuration.rb

Constant Summary collapse

CREDENTIALS_PATH =
File.expand_path("~/.sem/credentials").freeze
API_URL_PATH =
File.expand_path("~/.sem/api_url").freeze
DEFAULT_API_URL =
"https://api.semaphoreci.com".freeze

Class Method Summary collapse

Class Method Details

.api_urlObject



35
36
37
38
39
# File 'lib/sem/configuration.rb', line 35

def api_url
  return DEFAULT_API_URL unless File.file?(API_URL_PATH)

  File.read(API_URL_PATH).strip
end

.auth_tokenObject



29
30
31
32
33
# File 'lib/sem/configuration.rb', line 29

def auth_token
  raise Sem::Errors::Auth::NoCredentials unless File.file?(CREDENTIALS_PATH)

  File.read(CREDENTIALS_PATH).strip
end

.delete_auth_tokenObject



25
26
27
# File 'lib/sem/configuration.rb', line 25

def delete_auth_token
  FileUtils.rm_f(CREDENTIALS_PATH)
end

.export_auth_token(auth_token) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/sem/configuration.rb', line 17

def export_auth_token(auth_token)
  dirname = File.dirname(CREDENTIALS_PATH)
  FileUtils.mkdir_p(dirname)

  File.write(CREDENTIALS_PATH, auth_token)
  File.chmod(0o0600, CREDENTIALS_PATH)
end

.valid_auth_token?(auth_token) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/sem/configuration.rb', line 9

def valid_auth_token?(auth_token)
  Sem::API::Base.create_new_api_client(api_url, auth_token).orgs.list!

  true
rescue SemaphoreClient::Exceptions::Base
  false
end