Class: RubyNative::CLI::Credentials
- Inherits:
-
Object
- Object
- RubyNative::CLI::Credentials
- Defined in:
- lib/ruby_native/cli/credentials.rb
Class Attribute Summary collapse
-
.path ⇒ Object
Lazy: Dir.home raises in HOME-less containers, and that must not kill commands that only use RUBY_NATIVE_TOKEN.
Class Method Summary collapse
- .clear ⇒ Object
-
.env_token ⇒ Object
A misspelled CI secret interpolates to "", which must not shadow the credentials file or
ruby_native logincan never fix auth. - .file_token ⇒ Object
- .save(token) ⇒ Object
- .token ⇒ Object
Class Attribute Details
.path ⇒ Object
Lazy: Dir.home raises in HOME-less containers, and that must not kill commands that only use RUBY_NATIVE_TOKEN.
13 14 15 |
# File 'lib/ruby_native/cli/credentials.rb', line 13 def self.path @path ||= File.join(Dir.home, ".ruby_native", "credentials") end |
Class Method Details
.clear ⇒ Object
41 42 43 |
# File 'lib/ruby_native/cli/credentials.rb', line 41 def self.clear File.delete(path) if File.exist?(path) end |
.env_token ⇒ Object
A misspelled CI secret interpolates to "", which must not shadow the
credentials file or ruby_native login can never fix auth.
23 24 25 26 |
# File 'lib/ruby_native/cli/credentials.rb', line 23 def self.env_token value = ENV["RUBY_NATIVE_TOKEN"].to_s.strip value unless value.empty? end |
.file_token ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ruby_native/cli/credentials.rb', line 28 def self.file_token return unless File.exist?(path) JSON.parse(File.read(path))["token"] rescue JSON::ParserError, ArgumentError nil end |
.save(token) ⇒ Object
35 36 37 38 39 |
# File 'lib/ruby_native/cli/credentials.rb', line 35 def self.save(token) FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.generate(token: token)) File.chmod(0600, path) end |
.token ⇒ Object
17 18 19 |
# File 'lib/ruby_native/cli/credentials.rb', line 17 def self.token env_token || file_token end |