Sha256: ce06aaebdd6fa3645fac243b875ef8edd208f6f466069f8548cc80478fc43953
Contents?: true
Size: 924 Bytes
Versions: 36
Compression:
Stored size: 924 Bytes
Contents
# frozen_string_literal: true module SdrClient # The stored credentials class Credentials class NoCredentialsError < StandardError; end # @param [String] a json string that contains a field 'token' def self.write(body) json = JSON.parse(body) FileUtils.mkdir_p(credentials_path, mode: 0o700) File.atomic_write(credentials_file) do |file| file.write(json.fetch('token')) end File.chmod(0o600, credentials_file) end def self.read raise NoCredentialsError unless ::File.exist?(credentials_file) creds = File.readlines(credentials_file, chomp: true).first if ::File.exist?(credentials_file) raise NoCredentialsError if creds.nil? creds end def self.credentials_path @credentials_path ||= File.join(Dir.home, '.sdr') end def self.credentials_file File.join(credentials_path, 'credentials') end end end
Version data entries
36 entries across 36 versions & 1 rubygems