Class: E3DB::Config

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/e3db/config.rb

Overview

Configuration and credentials for E3DB.

Typically a configuration is loaded from a JSON file generated during registration via the E3DB administration console or command-line tool. To load a configuration from a JSON file, use Config.load.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#api_base_urlString

Returns the base URL for the E3DB API service.

Returns:

  • (String)

    the base URL for the E3DB API service



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#api_key_idString

Returns the client's non-secret API key component.

Returns:

  • (String)

    the client's non-secret API key component



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#api_secretString

Returns the client's confidential API key component.

Returns:

  • (String)

    the client's confidential API key component



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#auth_base_urlString

Returns the base URL for the E3DB authentication service.

Returns:

  • (String)

    the base URL for the E3DB authentication service



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#client_idString

Returns the client's unique client identifier.

Returns:

  • (String)

    the client's unique client identifier



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#loggingBoolean

Warning: Log output will contain confidential authentication tokens---do not enable in production if log output isn't confidential!

Returns:

  • (Boolean)

    a flag to enable HTTP logging when true



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#private_keyString

Returns the client's Base64URL encoded Curve25519 private key.

Returns:

  • (String)

    the client's Base64URL encoded Curve25519 private key



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#public_keyString

Returns the client's Base64URL encoded Curve25519 public key.

Returns:

  • (String)

    the client's Base64URL encoded Curve25519 public key



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

#versionInt

Returns the version number of the configuration format (currently 1).

Returns:

  • (Int)

    the version number of the configuration format (currently 1)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/e3db/config.rb', line 39

class Config < Dry::Struct
  attribute :version, Types::Int
  attribute :client_id, Types::String
  attribute :api_key_id, Types::String
  attribute :api_secret, Types::String
  attribute :public_key, Types::String
  attribute :private_key, Types::String
  attribute :api_url, Types::String.default(DEFAULT_API_URL)
  attribute :logging, Types::Bool

  # Load configuration from a JSON file created during registration
  # or with {E3DB::Config.save}.
  #
  # The configuration file should contain a single JSON object
  # with the following structure:
  #
  #   {
  #     "version": 1,
  #     "client_id": "UUID",
  #     "api_key_id": "API_KEY",
  #     "api_secret": "API_SECRET",
  #     "public_key": "PUBLIC_KEY",
  #     "private_key": "PRIVATE_KEY",
  #     "api_url": "URL",
  #  }
  #
  # @param filename [String] pathname of JSON configuration to load
  # @return [Config] the configuration object loaded from the file
  def self.load(filename)
    json = JSON.parse(File.read(filename), symbolize_names: true)
    if json[:version] != 1
      raise StandardError, "Unsupported config version: #{json[:version]}"
    end
    Config.new(json.merge(:logging => false))
  end

  def self.default
    return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
  end

  def self.load_profile(profile)
    return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
  end

  def logging=(value)
    @logging = value
  end
end

Class Method Details

.defaultObject



75
76
77
# File 'lib/e3db/config.rb', line 75

def self.default
  return self.load(File.join(Dir.home, '.tozny', 'e3db.json'))
end

.load(filename) ⇒ Config

Load configuration from a JSON file created during registration or with save.

The configuration file should contain a single JSON object with the following structure:

{ "version": 1, "client_id": "UUID", "api_key_id": "API_KEY", "api_secret": "API_SECRET", "public_key": "PUBLIC_KEY", "private_key": "PRIVATE_KEY", "api_url": "URL", }

Parameters:

  • filename (String)

    pathname of JSON configuration to load

Returns:

  • (Config)

    the configuration object loaded from the file



67
68
69
70
71
72
73
# File 'lib/e3db/config.rb', line 67

def self.load(filename)
  json = JSON.parse(File.read(filename), symbolize_names: true)
  if json[:version] != 1
    raise StandardError, "Unsupported config version: #{json[:version]}"
  end
  Config.new(json.merge(:logging => false))
end

.load_profile(profile) ⇒ Object



79
80
81
# File 'lib/e3db/config.rb', line 79

def self.load_profile(profile)
  return self.load(File.join(Dir.home, '.tozny', profile, 'e3db.json'))
end