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
33
34
35
36
37
# 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
  @license_server_urls = if ChefLicensing::Config.license_server_url.is_a?(String)
                           ChefLicensing::Config.license_server_url.split(",")
                         else
                           ChefLicensing::Config.license_server_url
                         end
end

Instance Method Details

#client(params = {}) ⇒ Object



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

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

#describe(params = {}) ⇒ Object



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

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



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

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

#entitlement_by_name(payload) ⇒ Object



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

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

#feature_by_id(payload) ⇒ Object



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

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

#feature_by_name(payload) ⇒ Object



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

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

#list_licenses(params = {}) ⇒ Object



67
68
69
# File 'lib/chef-licensing/restful_client/base.rb', line 67

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

#validate(license) ⇒ Object



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

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