Class: ICFS::ConfigS3

Inherits:
Config
  • Object
show all
Defined in:
lib/icfs/config_s3.rb

Overview

Configuration storage implemented in S3

Constant Summary

Constants inherited from Config

ICFS::Config::ValConfig

Instance Attribute Summary

Attributes inherited from Config

#data, #defaults

Instance Method Summary collapse

Methods inherited from Config

#get, #set

Constructor Details

#initialize(defaults, s3, bucket, prefix = nil) ⇒ ConfigS3

New instance

Parameters:

  • defaults (Hash)

    The default options

  • s3 (Aws::S3::Client)

    the configured S3 client

  • bucket (String)

    The bucket name

  • prefix (String) (defaults to: nil)

    Prefix to use for object keys



32
33
34
35
36
37
# File 'lib/icfs/config_s3.rb', line 32

def initialize(defaults, s3, bucket, prefix=nil)
  super(defaults)
  @s3 = s3
  @bck = bucket
  @pre = prefix || ''
end

Instance Method Details

#load(unam) ⇒ Boolean

Load a user configuration

Parameters:

  • unam (String)

    the user name to load

Returns:

  • (Boolean)

    if any config data was found for the user



43
44
45
46
47
48
49
50
51
52
# File 'lib/icfs/config_s3.rb', line 43

def load(unam)
  Items.validate(unam, 'User/Role/Group name', Items::FieldUsergrp)
  @unam = unam.dup
  json = @s3.get_object( bucket: @bck, key: _key(unam) ).body.read
  @data = Items.parse(json, 'Config values', Config::ValConfig)
  return true
rescue
  @data = {}
  return false
end

#saveObject

Save a user configuration

Raises:

  • (RuntimeError)


58
59
60
61
62
# File 'lib/icfs/config_s3.rb', line 58

def save()
  raise(RuntimeError, 'Save requires a user name') if !@unam
  json = Items.generate(@data, 'Config values', Config::ValConfig)
  @s3.put_object( bucket: @bck, key: _key(@unam), body: json )
end