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



28
29
30
31
32
# File 'lib/icfs/users_s3.rb', line 28

def initialize(s3, bucket, prefix=nil)
  @s3 = s3
  @bck = bucket
  @pre = prefix || ''.freeze
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



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

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



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

def read(urg)
  Items.validate(urg, 'User/Role/Group name'.freeze, 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



65
66
67
68
69
# File 'lib/icfs/users_s3.rb', line 65

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