Class: ChefLicensing::Api::Parser::Describe

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/api/parser/describe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Describe

Returns a new instance of Describe.



12
13
14
15
# File 'lib/chef-licensing/api/parser/describe.rb', line 12

def initialize(data)
  @data = data
  @license_data = data.license || OpenStruct.new({})
end

Instance Attribute Details

#dataObject (readonly)

Uses response from /describe API This parser formats the response which will enable creation of license data object.



10
11
12
# File 'lib/chef-licensing/api/parser/describe.rb', line 10

def data
  @data
end

#license_dataObject (readonly)

Uses response from /describe API This parser formats the response which will enable creation of license data object.



10
11
12
# File 'lib/chef-licensing/api/parser/describe.rb', line 10

def license_data
  @license_data
end

Instance Method Details

#parse_asset_entitlementsObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/chef-licensing/api/parser/describe.rb', line 97

def parse_asset_entitlements
  assets = []
  assets_data = data.assets || []
  assets_data.select do |asset|
    asset.from.each do |from_info|
      if from_info.license == parse_id
        asset_details = {
          "status" => from_info.status,
          "entitled" => asset.entitled,
          "id" => asset.id,
          "name" => asset.name,
        }
        assets << asset_details
      end
    end
  end
  assets
end

#parse_expiration_dateObject

Parse expiration details



31
32
33
# File 'lib/chef-licensing/api/parser/describe.rb', line 31

def parse_expiration_date
  license_data.end
end

#parse_feature_entitlementsObject

Parse entitlements



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef-licensing/api/parser/describe.rb', line 59

def parse_feature_entitlements
  features = []
  features_data = data.features || []
  features_data.each do |feature|
    feature.from.each do |from_info|
      if from_info.license == parse_id
        feature_details = {
          "status" => from_info.status,
          "entitled" => feature.entitled,
          "id" => feature.id,
          "name" => feature.name,
        }
        features << feature_details
      end
    end
  end
  features
end

#parse_idObject



17
18
19
# File 'lib/chef-licensing/api/parser/describe.rb', line 17

def parse_id
  license_data.licenseKey
end

#parse_license_expiration_statusObject



35
36
37
# File 'lib/chef-licensing/api/parser/describe.rb', line 35

def parse_license_expiration_status
  nil
end

#parse_license_typeObject



21
22
23
# File 'lib/chef-licensing/api/parser/describe.rb', line 21

def parse_license_type
  license_data.licenseType
end

#parse_limitsObject

Parse usage details



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef-licensing/api/parser/describe.rb', line 41

def parse_limits
  limits = []
  limits_data = license_data.limits || []
  limits_data.each do |limit|
    limit_details = {
      "usage_status" => limit.status,
      "usage_limit" => limit.amount,
      "usage_measure" => limit.measure,
      "used" => limit.used,
      "software" => limit.software,
    }
    limits << limit_details
  end
  limits
end

#parse_software_entitlementsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/chef-licensing/api/parser/describe.rb', line 78

def parse_software_entitlements
  softwares = []
  softwares_data = data.software || []
  softwares_data.select do |software|
    software.from.each do |from_info|
      if from_info.license == parse_id
        software_details = {
          "status" => from_info.status,
          "entitled" => software.entitled,
          "id" => software.id,
          "name" => software.name,
        }
        softwares << software_details
      end
    end
  end
  softwares
end

#parse_statusObject



25
26
27
# File 'lib/chef-licensing/api/parser/describe.rb', line 25

def parse_status
  license_data.status
end