diff options
| author | John Keiser <jkeiser@opscode.com> | 2014-07-15 12:17:04 -0700 |
|---|---|---|
| committer | John Keiser <jkeiser@opscode.com> | 2014-07-15 12:17:04 -0700 |
| commit | d767320ff0819e355f093f548db9b7d578587c57 (patch) | |
| tree | 3267cb613dd1855f3c453cec8b5b20d870610a26 /lib/chef_zero | |
| parent | 3e248ab68c65fd18b9ff5985e4271c3877fc21e5 (diff) | |
| download | chef-zero-d767320ff0819e355f093f548db9b7d578587c57.tar.gz | |
Add /groups and /group/NAME endpoints
Diffstat (limited to 'lib/chef_zero')
| -rw-r--r-- | lib/chef_zero/data_normalizer.rb | 33 | ||||
| -rw-r--r-- | lib/chef_zero/data_store/memory_store_v2.rb | 2 | ||||
| -rw-r--r-- | lib/chef_zero/endpoints/group_endpoint.rb | 20 | ||||
| -rw-r--r-- | lib/chef_zero/endpoints/groups_endpoint.rb | 13 | ||||
| -rw-r--r-- | lib/chef_zero/server.rb | 8 |
5 files changed, 62 insertions, 14 deletions
diff --git a/lib/chef_zero/data_normalizer.rb b/lib/chef_zero/data_normalizer.rb index a452e8d..1892dee 100644 --- a/lib/chef_zero/data_normalizer.rb +++ b/lib/chef_zero/data_normalizer.rb @@ -50,17 +50,6 @@ module ChefZero data_bag_item end - def self.normalize_environment(environment, name) - environment['name'] ||= name - environment['description'] ||= '' - environment['cookbook_versions'] ||= {} - environment['json_class'] ||= "Chef::Environment" - environment['chef_type'] ||= "environment" - environment['default_attributes'] ||= {} - environment['override_attributes'] ||= {} - environment - end - def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method) # TODO I feel dirty if method != 'PUT' @@ -100,6 +89,28 @@ module ChefZero cookbook end + def self.normalize_environment(environment, name) + environment['name'] ||= name + environment['description'] ||= '' + environment['cookbook_versions'] ||= {} + environment['json_class'] ||= "Chef::Environment" + environment['chef_type'] ||= "environment" + environment['default_attributes'] ||= {} + environment['override_attributes'] ||= {} + environment + end + + def self.normalize_group(group, name, orgname) + group['actors'] ||= [] + group['users'] ||= [] + group['clients'] ||= [] + group['groups'] ||= [] + group['orgname'] ||= orgname if orgname + group['name'] ||= name + group['groupname'] ||= name + group + end + def self.normalize_node(node, name) node['name'] ||= name node['json_class'] ||= 'Chef::Node' diff --git a/lib/chef_zero/data_store/memory_store_v2.rb b/lib/chef_zero/data_store/memory_store_v2.rb index 2314ae8..4515de4 100644 --- a/lib/chef_zero/data_store/memory_store_v2.rb +++ b/lib/chef_zero/data_store/memory_store_v2.rb @@ -49,6 +49,8 @@ module ChefZero 'file_store' => { 'checksums' => {} }, + 'org' => '{}', + 'groups' => {}, 'nodes' => {}, 'roles' => {}, 'sandboxes' => {}, diff --git a/lib/chef_zero/endpoints/group_endpoint.rb b/lib/chef_zero/endpoints/group_endpoint.rb new file mode 100644 index 0000000..fbd9e08 --- /dev/null +++ b/lib/chef_zero/endpoints/group_endpoint.rb @@ -0,0 +1,20 @@ +require 'json' +require 'chef_zero/endpoints/rest_object_endpoint' +require 'chef_zero/data_normalizer' + +module ChefZero + module Endpoints + # /organizations/ORG/groups/NAME + class GroupEndpoint < RestObjectEndpoint + def initialize(server) + super(server, 'groupname') + end + + def populate_defaults(request, response_json) + group = JSON.parse(response_json, :create_additions => false) + group = DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1]) + JSON.pretty_generate(group) + end + end + end +end diff --git a/lib/chef_zero/endpoints/groups_endpoint.rb b/lib/chef_zero/endpoints/groups_endpoint.rb new file mode 100644 index 0000000..b35701f --- /dev/null +++ b/lib/chef_zero/endpoints/groups_endpoint.rb @@ -0,0 +1,13 @@ +require 'json' +require 'chef_zero/endpoints/rest_list_endpoint' + +module ChefZero + module Endpoints + # /organizations/ORG/groups/NAME + class GroupsEndpoint < RestListEndpoint + def initialize(server) + super(server, 'groupname') + end + end + end +end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index 663cb89..8d9aa95 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -32,6 +32,7 @@ require 'chef_zero/data_store/memory_store_v2' require 'chef_zero/data_store/v1_to_v2_adapter' require 'chef_zero/version' +require 'chef_zero/endpoints/rest_list_endpoint' require 'chef_zero/endpoints/authenticate_user_endpoint' require 'chef_zero/endpoints/actors_endpoint' require 'chef_zero/endpoints/actor_endpoint' @@ -41,7 +42,8 @@ require 'chef_zero/endpoints/cookbook_version_endpoint' require 'chef_zero/endpoints/data_bags_endpoint' require 'chef_zero/endpoints/data_bag_endpoint' require 'chef_zero/endpoints/data_bag_item_endpoint' -require 'chef_zero/endpoints/rest_list_endpoint' +require 'chef_zero/endpoints/groups_endpoint' +require 'chef_zero/endpoints/group_endpoint' require 'chef_zero/endpoints/environment_endpoint' require 'chef_zero/endpoints/environment_cookbooks_endpoint' require 'chef_zero/endpoints/environment_cookbook_endpoint' @@ -410,8 +412,8 @@ module ChefZero # [ "/organizations/*/association_requests/*", AssociationRequestEndpoint.new(self) ], # [ "/organizations/*/containers", RestListEndpoint.new(self) ], # [ "/organizations/*/containers/*", RestObjectEndpoint.new(self) ], - # [ "/organizations/*/groups", RestListEndpoint.new(self) ], - # [ "/organizations/*/groups/*", RestObjectEndpoint.new(self) ], + [ "/organizations/*/groups", GroupsEndpoint.new(self) ], + [ "/organizations/*/groups/*", GroupEndpoint.new(self) ], # [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ], # [ "/users/*/association_requests", UserAssocationRequestsEndpoint.new(self) ], # [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ], |
