From fff51f6e1119c2e4b3018d75b4622cfb2028cff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phanie=20Jaumotte?= Date: Tue, 30 Jul 2024 10:11:14 +0200 Subject: [PATCH] modify key --- .../provider/elasticsearch_license/ruby.rb | 24 +++++++++++-------- manifests/license.pp | 2 +- .../classes/006_elasticsearch_license_spec.rb | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/puppet/provider/elasticsearch_license/ruby.rb b/lib/puppet/provider/elasticsearch_license/ruby.rb index 7053faf8b..698084475 100644 --- a/lib/puppet/provider/elasticsearch_license/ruby.rb +++ b/lib/puppet/provider/elasticsearch_license/ruby.rb @@ -1,32 +1,36 @@ # frozen_string_literal: true +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) + require 'puppet/provider/elastic_rest' +require 'puppet_x/elastic/deep_to_i' +require 'puppet_x/elastic/deep_to_s' + Puppet::Type.type(:elasticsearch_license).provide( :ruby, parent: Puppet::Provider::ElasticREST, + api_uri: '_license?acknowledge=true', metadata: :content, metadata_pipeline: [ ->(data) { Puppet_X::Elastic.deep_to_s data }, ->(data) { Puppet_X::Elastic.deep_to_i data } - ], - api_uri: '_license', - query_string: { - 'acknowledge' => 'true' - } + ] ) do 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| + Puppet.debug('Got to license.process_body') + + JSON.parse(body).map do |object_name, api_object| { - :name => name.to_s, - :ensure => :present, + name: object_name, + ensure: :present, metadata => { 'license' => process_metadata(api_object) }, - :provider => name - } + provider: name + }.compact end end 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' => {