Class: Sem::Configuration
- Inherits:
-
Object
- Object
- Sem::Configuration
- Defined in:
- lib/sem/configuration.rb
Constant Summary collapse
- CREDENTIALS_PATH =
File.("~/.sem/credentials").freeze
- API_URL_PATH =
File.("~/.sem/api_url").freeze
- DEFAULT_API_URL =
"https://api.semaphoreci.com".freeze
Class Method Summary collapse
- .api_url ⇒ Object
- .auth_token ⇒ Object
- .delete_auth_token ⇒ Object
- .export_auth_token(auth_token) ⇒ Object
- .valid_auth_token?(auth_token) ⇒ Boolean
Class Method Details
.api_url ⇒ Object
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_token ⇒ Object
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_token ⇒ Object
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
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 |