Class: ChefLicensing::RestfulClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/restful_client/base.rb

Overview

Base class to handle all License Server endpoints

Direct Known Subclasses

V1

Constant Summary collapse

END_POINTS =
{
  FEATURE_BY_NAME: "license-service/featurebyname",
  FEATURE_BY_ID: "license-service/featurebyid",
  ENTITLEMENT_BY_NAME: "license-service/entitlementbyname",
  ENTITLEMENT_BY_ID: "license-service/entitlementbyid",
}.freeze
CURRENT_ENDPOINT_VERSION =
2
REQUEST_LIMIT =
5

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



28
29
30
31
32
# File 'lib/chef-licensing/restful_client/base.rb', line 28

def initialize
  raise MissingAPICredentialsError, "Missing credential in config: Set in block chef_license_server or use environment variable CHEF_LICENSE_SERVER or pass through argument --chef-license-server" if ChefLicensing::Config.license_server_url.nil?

  @logger = ChefLicensing::Config.logger
end

Instance Method Details

#client(params = {}) ⇒ Object



54
55
56
# File 'lib/chef-licensing/restful_client/base.rb', line 54

def client(params = {})
  invoke_get_api(self.class::END_POINTS[:CLIENT], { licenseId: params[:license_keys], entitlementId: params[:entitlement_id] })
end

#describe(params = {}) ⇒ Object



58
59
60
# File 'lib/chef-licensing/restful_client/base.rb', line 58

def describe(params = {})
  invoke_get_api(self.class::END_POINTS[:DESCRIBE], { licenseId: params[:license_keys], entitlementId: params[:entitlement_id] })
end

#entitlement_by_id(payload) ⇒ Object



50
51
52
# File 'lib/chef-licensing/restful_client/base.rb', line 50

def entitlement_by_id(payload)
  invoke_post_api(self.class::END_POINTS[:ENTITLEMENT_BY_ID], payload)
end

#entitlement_by_name(payload) ⇒ Object



46
47
48
# File 'lib/chef-licensing/restful_client/base.rb', line 46

def entitlement_by_name(payload)
  invoke_post_api(self.class::END_POINTS[:ENTITLEMENT_BY_NAME], payload)
end

#feature_by_id(payload) ⇒ Object



42
43
44
# File 'lib/chef-licensing/restful_client/base.rb', line 42

def feature_by_id(payload)
  invoke_post_api(self.class::END_POINTS[:FEATURE_BY_ID], payload)
end

#feature_by_name(payload) ⇒ Object



38
39
40
# File 'lib/chef-licensing/restful_client/base.rb', line 38

def feature_by_name(payload)
  invoke_post_api(self.class::END_POINTS[:FEATURE_BY_NAME], payload)
end

#list_licenses(params = {}) ⇒ Object



62
63
64
# File 'lib/chef-licensing/restful_client/base.rb', line 62

def list_licenses(params = {})
  invoke_get_api(self.class::END_POINTS[:LIST_LICENSES])
end

#validate(license) ⇒ Object



34
35
36
# File 'lib/chef-licensing/restful_client/base.rb', line 34

def validate(license)
  invoke_get_api(self.class::END_POINTS[:VALIDATE], { licenseId: license, version: CURRENT_ENDPOINT_VERSION })
end