Sha256: 01ce03f6ba96c8eee90e305b55704f1df21901eb14cf92424bf07df53aead61e

Contents?: true

Size: 934 Bytes

Versions: 4

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module SdrClient
  class RedesignedClient
    class CLI < Thor
      # The stored credentials
      class Credentials
        # @param [String] a json string that contains a field 'token'
        def self.write(body)
          token = JSON.parse(body).fetch('token')
          FileUtils.mkdir_p(credentials_path, mode: 0o700)
          ::File.atomic_write(credentials_file) { |file| file.write(token) }
          ::File.chmod(0o600, credentials_file)
        end

        def self.read
          return unless ::File.exist?(credentials_file)

          creds = ::File.read(credentials_file, chomp: true)
          return 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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sdr-client-2.18.0 lib/sdr_client/redesigned_client/cli/credentials.rb
sdr-client-2.17.0 lib/sdr_client/redesigned_client/cli/credentials.rb
sdr-client-2.16.0 lib/sdr_client/redesigned_client/cli/credentials.rb
sdr-client-2.13.2 lib/sdr_client/redesigned_client/cli/credentials.rb