Class: ChefFixie::AuthzApi

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_fixie_shahid/authz_objects.rb

Instance Method Summary collapse

Constructor Details

#initialize(user = nil) ⇒ AuthzApi

Returns a new instance of AuthzApi.



29
30
31
32
33
# File 'lib/chef_fixie_shahid/authz_objects.rb', line 29

def initialize(user = nil)
  @requestor_authz = user ? user : ChefFixie.configure { |x| x.superuser_id }
  @auth_uri ||= ChefFixie.configure { |x| x.authz_uri }
  @rest = Chef::HTTP.new(@auth_uri)
end

Instance Method Details

#delete(resource) ⇒ Object



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

def delete(resource)
  result = @rest.delete(resource,
                        "Content-Type" => "application/json",
                        "Accept" => "application/json",
                        "X-Ops-Requesting-Actor-Id" => @requestor_authz)
  FFI_Yajl::Parser.parse(result)
end

#get(resource) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/chef_fixie_shahid/authz_objects.rb', line 43

def get(resource)
  result = @rest.get(resource,
                     "Content-Type" => "application/json",
                     "Accept" => "application/json",
                     "X-Ops-Requesting-Actor-Id" => @requestor_authz)
  FFI_Yajl::Parser.parse(result)
end

#json_helper(s) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/chef_fixie_shahid/authz_objects.rb', line 35

def json_helper(s)
  if s.kind_of?(Hash)
    FFI_Yajl::Encoder.encode(s)
  else
    s
  end
end

#post(resource, data) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/chef_fixie_shahid/authz_objects.rb', line 59

def post(resource, data)
  result = @rest.post(resource, json_helper(data),
                      "Content-Type" => "application/json",
                      "Accept" => "application/json",
                      "X-Ops-Requesting-Actor-Id" => @requestor_authz)
  FFI_Yajl::Parser.parse(result)
end

#put(resource, data) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/chef_fixie_shahid/authz_objects.rb', line 51

def put(resource, data)
  result = @rest.put(resource, json_helper(data),
                     "Content-Type" => "application/json",
                     "Accept" => "application/json",
                     "X-Ops-Requesting-Actor-Id" => @requestor_authz)
  FFI_Yajl::Parser.parse(result)
end