Class: ICFS::UsersS3

Inherits:
Users
  • Object
show all
Defined in:
lib/icfs/users_s3.rb

Overview

Implements Users from AWS S3

Constant Summary

Constants inherited from Users

ICFS::Users::ValUser

Instance Method Summary collapse

Constructor Details

#initialize(s3, bucket, prefix = nil) ⇒ UsersS3

New instance

Parameters:

  • s3 (Aws::S3::Client)

    the configured S3 client

  • bucket (String)

    The bucket name

  • prefix (String) (defaults to: nil)

    Prefix to use for object keys



30
31
32
33
34
# File 'lib/icfs/users_s3.rb', line 30

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

Instance Method Details

#flush(urg) ⇒ Boolean

Flush a user/role/group from a cache, if any

Parameters:

  • urg (String)

    User/Role/Group name

Returns:

  • (Boolean)

    if cached



49
# File 'lib/icfs/users_s3.rb', line 49

def flush(urg); false; end

#read(urg) ⇒ Hash

Read a user/role/group

Parameters:

  • urg (String)

    User/Role/Group name

Returns:

  • (Hash)

    Will include :type and, if a user :roles, :groups, :perms



55
56
57
58
59
60
61
# File 'lib/icfs/users_s3.rb', line 55

def read(urg)
  Items.validate(urg, 'User/Role/Group name', Items::FieldUsergrp)
  json = @s3.get_object( bucket: @bck, key: _path(urg) ).body.read
  return JSON.parse(json)
rescue
  return nil
end

#write(obj) ⇒ Object

Write a user/role/group

Parameters:

  • obj (Hash)

    Will include :name, :type, and if a user :roles, :groups, :perms



67
68
69
70
71
# File 'lib/icfs/users_s3.rb', line 67

def write(obj)
  Items.validate(obj, 'User/Role/Group', Users::ValUser)
  json = JSON.pretty_generate(obj)
  @s3.put_object( bucket: @bck, key: _path(obj['name']), body: json )
end