diff options
author | John Keiser <jkeiser@opscode.com> | 2014-08-21 21:40:34 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-08-22 09:20:51 -0700 |
commit | e26df5899a068c06d80e2860cc4aa7671eae423a (patch) | |
tree | 18a5a9a29a85bdbcc5d9ecb978e4eb11b45610ea | |
parent | e21113a0aabde91dbbfd7e61a7095c84589642f3 (diff) | |
download | chef-zero-e26df5899a068c06d80e2860cc4aa7671eae423a.tar.gz |
Add license endpoint
-rw-r--r-- | lib/chef_zero/endpoints/license_endpoint.rb | 25 | ||||
-rw-r--r-- | lib/chef_zero/server.rb | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/license_endpoint.rb b/lib/chef_zero/endpoints/license_endpoint.rb new file mode 100644 index 0000000..06bbce8 --- /dev/null +++ b/lib/chef_zero/endpoints/license_endpoint.rb @@ -0,0 +1,25 @@ +require 'json' +require 'chef_zero/rest_base' + +module ChefZero + module Endpoints + # /license + class LicenseEndpoint < RestBase + MAX_NODE_COUNT = 25 + + def get(request) + node_count = 0 + list_data(request, [ 'organizations' ]).each do |orgname| + node_count += list_data(request, [ 'organizations', orgname, 'nodes' ]).size + end + + json_response(200, { + "limit_exceeded" => (node_count > MAX_NODE_COUNT) ? true : false, + "node_license" => MAX_NODE_COUNT, + "node_count" => node_count, + "upgrade_url" => 'http://blah.com' + }) + end + end + end +end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index a78757f..dc8fe7f 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -57,6 +57,7 @@ require 'chef_zero/endpoints/environment_cookbook_versions_endpoint' require 'chef_zero/endpoints/environment_nodes_endpoint' require 'chef_zero/endpoints/environment_recipes_endpoint' require 'chef_zero/endpoints/environment_role_endpoint' +require 'chef_zero/endpoints/license_endpoint' require 'chef_zero/endpoints/node_endpoint' require 'chef_zero/endpoints/organizations_endpoint' require 'chef_zero/endpoints/organization_endpoint' @@ -432,6 +433,7 @@ module ChefZero [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ], [ "/authenticate_user", AuthenticateUserEndpoint.new(self) ], [ "/system_recovery", SystemRecoveryEndpoint.new(self) ], + [ "/license", LicenseEndpoint.new(self) ], [ "/organizations", OrganizationsEndpoint.new(self) ], [ "/organizations/*", OrganizationEndpoint.new(self) ], |