1
+ module Spice
2
+ class Environment < Spice ::Chef
3
+ # Get a list of all data bags in the following syntax
4
+ # Spice::Environment.all
5
+ #
6
+ # @param [Hash] options the options hash. Currently does nothing
7
+ def self . all ( options = { } )
8
+ connection . get ( "/environments" )
9
+ end
10
+
11
+ # An alternative format for showing the contents of a data bag
12
+ # @example Retrieve the id and uri of items in a data bag called "users"
13
+ # Spice::Environment["users"] # => {"adam":"http://localhost:4000/data/users/adam"}
14
+ def self . []( name )
15
+ connection . get ( "/environments/#{ name } " )
16
+ end
17
+
18
+ # Show the contents of a data bag
19
+ # @example Retrieve the id and uri of items in a data bag called "users"
20
+ # Spice::Environment.show(:name => "users") # => {"adam":"http://localhost:4000/data/users/adam"}
21
+ #
22
+ # @param [Hash] options The options hash
23
+ # @option options [String] :name The name of your data bag
24
+ def self . show ( options = { } )
25
+ raise ArgumentError , "Option :name must be present" unless options [ :name ]
26
+ name = options . delete ( :name )
27
+ connection . get ( "/environments/#{ name } " )
28
+ end
29
+
30
+ # Create a a new data bag
31
+ #
32
+ # @example
33
+ # Spice::Environment.create(:name => "users")
34
+ #
35
+ # @param [Hash] options the options hash from which to create a data bag
36
+ # @option options [String] :name The name of your data bag
37
+
38
+ def self . create ( options = { } )
39
+ options [ :chef_type ] ||= "environment"
40
+ options [ :json_class ] ||= "Chef::Environment"
41
+ options [ :attributes ] ||= { }
42
+ options [ :description ] ||= ""
43
+ options [ :cookbook_versions ] ||= { }
44
+ connection . post ( "/environments" , options )
45
+ end
46
+
47
+ # Delete a data bag
48
+ #
49
+ # @example
50
+ # Spice::Environment.delete(:name => "users")
51
+ #
52
+ # @param [Hash] options the options hash from which to delete a data bag
53
+ # @option options [String] :name The name of your data bag
54
+
55
+ def self . delete ( options = { } )
56
+ raise ArgumentError , "Option :name must be present" unless options [ :name ]
57
+ name = options . delete ( :name )
58
+ connection . delete ( "/environments/#{ name } " , options )
59
+ end
60
+
61
+ # Shows a data bag item
62
+ #
63
+ # @example
64
+ # Spice::Environment.show_item(:name => "users", :id => "adam")
65
+ #
66
+ # @param [Hash] options the options hash from which to create a data bag
67
+ # @option options [String] :name The name of your data bag
68
+ # @option options [String] :id The id of the data bag item
69
+
70
+ def self . show_cookbook ( options = { } )
71
+ raise ArgumentError , "Option :name must be present" unless options [ :name ]
72
+ raise ArgumentError , "Option :cookbook must be present" unless options [ :cookbook ]
73
+ name = options . delete ( :name )
74
+ cookbook = options . delete ( :cookbook )
75
+ connection . get ( "/environments/#{ name } /cookbooks/#{ cookbook } " , options )
76
+ end
77
+
78
+ def self . list_cookbooks ( options = { } )
79
+ raise ArgumentError , "Option :name must be present" unless options [ :name ]
80
+ name = options . delete ( :name )
81
+ connection . get ( "/environments/#{ name } /cookbooks" , options )
82
+ end
83
+
84
+ end
85
+ end
0 commit comments