diff --git a/lib/puppet/provider/elasticsearch_license/xpack.rb b/lib/puppet/provider/elasticsearch_license/xpack.rb index 4bae734c5..283f1893f 100644 --- a/lib/puppet/provider/elasticsearch_license/xpack.rb +++ b/lib/puppet/provider/elasticsearch_license/xpack.rb @@ -3,29 +3,28 @@ require 'puppet/provider/elastic_rest' Puppet::Type.type(:elasticsearch_license).provide( - :xpack, - api_resource_style: :bare, + :ruby, parent: Puppet::Provider::ElasticREST, metadata: :content, metadata_pipeline: [ ->(data) { Puppet_X::Elastic.deep_to_s data }, ->(data) { Puppet_X::Elastic.deep_to_i data } ], - api_uri: '_xpack/license', + api_uri: '_license', query_string: { 'acknowledge' => 'true' } ) do - desc 'A REST API based provider to manage Elasticsearch X-Pack licenses.' + desc 'A REST API based provider to manage Elasticsearch licenses.' mk_resource_methods def self.process_body(body) - JSON.parse(body).map do |_object_name, api_object| + JSON.parse(body).map do |object_name, api_object| { - :name => name.to_s, + :name => object_name, :ensure => :present, - metadata => { 'license' => process_metadata(api_object) }, + metadata => { 'licenses' => process_metadata(api_object) }, :provider => name } end diff --git a/manifests/license.pp b/manifests/license.pp index 866b85775..ea6025a11 100644 --- a/manifests/license.pp +++ b/manifests/license.pp @@ -72,7 +72,7 @@ port => $api_port, timeout => $api_timeout, } - -> elasticsearch_license { 'xpack': + -> elasticsearch_license { 'license': ensure => $ensure, content => $_content, protocol => $api_protocol, diff --git a/spec/classes/006_elasticsearch_license_spec.rb b/spec/classes/006_elasticsearch_license_spec.rb index 580bdadef..b8ce3d957 100644 --- a/spec/classes/006_elasticsearch_license_spec.rb +++ b/spec/classes/006_elasticsearch_license_spec.rb @@ -53,11 +53,11 @@ class { 'elasticsearch' : it do expect(subject).to contain_es_instance_conn_validator( 'license-conn-validator' - ).that_comes_before('elasticsearch_license[xpack]') + ).that_comes_before('elasticsearch_license[license]') end it do - expect(subject).to contain_elasticsearch_license('xpack').with( + expect(subject).to contain_elasticsearch_license('license').with( ensure: 'present', content: { 'license' => { diff --git a/spec/unit/provider/elasticsearch_license/ruby_spec.rb b/spec/unit/provider/elasticsearch_license/ruby_spec.rb new file mode 100644 index 000000000..d338207b5 --- /dev/null +++ b/spec/unit/provider/elasticsearch_license/ruby_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require_relative '../../../helpers/unit/provider/elasticsearch_rest_shared_examples' + +describe Puppet::Type.type(:elasticsearch_license).provider(:ruby) do # rubocop:disable RSpec/MultipleMemoizedHelpers + let(:example1) do + { + name: 'license', + ensure: :present, + provider: :ruby, + content: { + 'licenses' => [ { + #'status' => 'active', + #'uid' => 'cbff45e7-c553-41f7-ae4f-9205eabd80xx', + #'type' => 'trial', + #'issue_date' => '2018-02-22T23:12:05.550Z', + #'issue_date_in_millis' => 1_519_341_125_550, + #'expiry_date' => '2018-03-24T23:12:05.550Z', + #'expiry_date_in_millis' => 1_521_933_125_550, + #'max_nodes' => 1_000, + #'issued_to' => 'test', + #'issuer' => 'elasticsearch', + #'start_date_in_millis' => 1_513_814_400_000 + 'uid' => '893361dc-9749-4997-93cb-802e3d7fa4xx', + 'type' => 'trial', + 'issue_date_in_millis' => 1_411_948_800_000, + 'expiry_date_in_millis' => 1_914_278_399_999, + 'max_nodes' => 1, + 'issued_to' => 'test', + 'issuer' => 'elasticsearch' + } ] + } + } + end + + let(:json1) do + { + # 'license' => { + # 'status' => 'active', + # 'uid' => 'cbff45e7-c553-41f7-ae4f-9205eabd80xx', + # 'type' => 'trial', + # 'issue_date' => '2018-02-22T23:12:05.550Z', + # 'issue_date_in_millis' => '1519341125550', + # 'expiry_date' => '2018-03-24T23:12:05.550Z', + # 'expiry_date_in_millis' => '1521933125550', + # 'max_nodes' => '1000', + # 'issued_to' => 'test', + # 'issuer' => 'elasticsearch', + # 'start_date_in_millis' => '1513814400000' + # } + 'licenses' => [ { + "uid" => '893361dc-9749-4997-93cb-802e3d7fa4xx', + "type" => 'trial', + "issue_date_in_millis" => '1411948800000', + "expiry_date_in_millis" => '1914278399999', + "max_nodes" => '1', + "issued_to" => 'test', + "issuer" => 'elasticsearch', + } ] + } + end + + let(:resource) { Puppet::Type::Elasticsearch_index.new props } + let(:provider) { described_class.new resource } + let(:props) do + { + name: name, + settings: { + 'index' => { + 'number_of_replicas' => 0 + } + } + } + end + + include_examples 'REST API', '_license' +end diff --git a/spec/unit/provider/elasticsearch_license/xpack_spec.rb b/spec/unit/provider/elasticsearch_license/xpack_spec.rb deleted file mode 100644 index 00691acab..000000000 --- a/spec/unit/provider/elasticsearch_license/xpack_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../helpers/unit/provider/elasticsearch_rest_shared_examples' - -describe Puppet::Type.type(:elasticsearch_license).provider(:xpack) do # rubocop:disable RSpec/MultipleMemoizedHelpers - let(:name) { 'xpack' } - - let(:example1) do - { - name: 'xpack', - ensure: :present, - provider: :xpack, - content: { - 'license' => { - 'status' => 'active', - 'uid' => 'cbff45e7-c553-41f7-ae4f-9205eabd80xx', - 'type' => 'trial', - 'issue_date' => '2018-02-22T23:12:05.550Z', - 'issue_date_in_millis' => 1_519_341_125_550, - 'expiry_date' => '2018-03-24T23:12:05.550Z', - 'expiry_date_in_millis' => 1_521_933_125_550, - 'max_nodes' => 1_000, - 'issued_to' => 'test', - 'issuer' => 'elasticsearch', - 'start_date_in_millis' => 1_513_814_400_000 - } - } - } - end - - let(:json1) do - { - 'license' => { - 'status' => 'active', - 'uid' => 'cbff45e7-c553-41f7-ae4f-9205eabd80xx', - 'type' => 'trial', - 'issue_date' => '2018-02-22T23:12:05.550Z', - 'issue_date_in_millis' => '1519341125550', - 'expiry_date' => '2018-03-24T23:12:05.550Z', - 'expiry_date_in_millis' => '1521933125550', - 'max_nodes' => '1000', - 'issued_to' => 'test', - 'issuer' => 'elasticsearch', - 'start_date_in_millis' => '1513814400000' - } - } - end - - let(:resource) { Puppet::Type::Elasticsearch_index.new props } - let(:provider) { described_class.new resource } - let(:props) do - { - name: name, - settings: { - 'index' => { - 'number_of_replicas' => 0 - } - } - } - end - - include_examples 'REST API', 'xpack/license', nil, true -end diff --git a/types/multipath.pp b/types/multipath.pp index 63dea224d..94126dc82 100644 --- a/types/multipath.pp +++ b/types/multipath.pp @@ -1 +1,2 @@ +# Multipath type type Elasticsearch::Multipath = Variant[Array[Stdlib::Absolutepath], Stdlib::Absolutepath] diff --git a/types/status.pp b/types/status.pp index e31498bdb..296557c75 100644 --- a/types/status.pp +++ b/types/status.pp @@ -1 +1,2 @@ +# Status type type Elasticsearch::Status = Enum['enabled', 'disabled', 'running', 'unmanaged']