Module: PuppetX::IntechWIFI::S3

Defined in:
lib/puppet_x/intechwifi/s3.rb

Class Method Summary collapse

Class Method Details

.get_owner_for_bucket(bucket, &aws_command) ⇒ Object



102
103
104
# File 'lib/puppet_x/intechwifi/s3.rb', line 102

def S3.get_owner_for_bucket(bucket, &aws_command)
  owner_to_property(JSON.parse(aws_command.call('s3api', 'get-bucket-acl', '--bucket', bucket))["Owner"])
end

.grant_json_to_property(source) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/puppet_x/intechwifi/s3.rb', line 47

def S3.grant_json_to_property(source)
  case source['Grantee']['Type']
    when 'CanonicalUser'
      "acc|#{source['Grantee']['DisplayName']}|#{source['Grantee']['ID']}|#{source['Permission']}"
    when 'Group'
      "grp|#{uri_to_user_group(source['Grantee']['URI'])}|#{source['Permission']}"
  end
end

.grant_property_to_hash(source) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet_x/intechwifi/s3.rb', line 60

def S3.grant_property_to_hash(source)
  s = source.split('|')
  {
      :Grantee => case s[0]
                    when 'acc'
                      {
                          :Type => "CanonicalUser",
                          :DisplayName => s[1],
                          :ID => s[2]
                      }
                    when 'grp'
                      {
                          :Type => "Group",
                          :URI => user_group_to_uri(s[1])
                      }
                  end,
      :Permission => s[-1]
  }
end

.name_to_bucket_key_pair(name) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/puppet_x/intechwifi/s3.rb', line 92

def S3.name_to_bucket_key_pair(name)
  # we need to check if we have a path on the end...
  append = name[-1] == '/'? "/" : ""
  arr = name.split('/')
  {
      :bucket => arr[2],
      :key => arr[3..arr.length].join("/") + append
  }
end

.owner_as_grant_property(owner) ⇒ Object



56
57
58
# File 'lib/puppet_x/intechwifi/s3.rb', line 56

def S3.owner_as_grant_property(owner)
  "acc|#{owner['DisplayName']}|#{owner['ID']}|FULL_CONTROL"
end

.owner_to_hash(source) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/puppet_x/intechwifi/s3.rb', line 80

def S3.owner_to_hash(source)
  s = source.split('|')
  {
      :DisplayName => s[1],
      :ID => s[2]
  }
end

.owner_to_property(source) ⇒ Object



88
89
90
# File 'lib/puppet_x/intechwifi/s3.rb', line 88

def S3.owner_to_property(source)
  "acc|#{source['DisplayName']}|#{source['ID']}"
end

.set_s3_grants_policy(owner, grants) ⇒ Object



106
107
108
109
110
111
# File 'lib/puppet_x/intechwifi/s3.rb', line 106

def S3.set_s3_grants_policy(owner, grants)
  {
      :Grants => grants.map{|x| PuppetX::IntechWIFI::S3.grant_property_to_hash(x)},
      :Owner => PuppetX::IntechWIFI::S3.owner_to_hash(owner)
  }.to_json
end

.uri_to_user_group(uri) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet_x/intechwifi/s3.rb', line 34

def S3.uri_to_user_group(uri)
  case uri
    when 'http://acs.amazonaws.com/groups/global/AuthenticatedUsers'
      'authenticated'
    when 'http://acs.amazonaws.com/groups/global/AllUsers'
      'public'
    when 'http://acs.amazonaws.com/groups/s3/LogDelivery'
      'log_delivery'
    else
      raise PuppetX::IntechWIFI::Exceptions::NotFoundError uri
  end
end

.user_group_to_uri(ug) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet_x/intechwifi/s3.rb', line 21

def S3.user_group_to_uri(ug)
  case ug
    when 'authenticated'
      'http://acs.amazonaws.com/groups/global/AuthenticatedUsers'
    when 'public'
      'http://acs.amazonaws.com/groups/global/AllUsers'
    when 'log_delivery'
      'http://acs.amazonaws.com/groups/s3/LogDelivery'
    else
      raise PuppetX::IntechWIFI::Exceptions::NotFoundError ug.to_s
  end
end