Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify API license #1230

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/puppet/provider/elasticsearch_license/xpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifests/license.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
port => $api_port,
timeout => $api_timeout,
}
-> elasticsearch_license { 'xpack':
-> elasticsearch_license { 'license':
ensure => $ensure,
content => $_content,
protocol => $api_protocol,
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/006_elasticsearch_license_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' => {
Expand Down
77 changes: 77 additions & 0 deletions spec/unit/provider/elasticsearch_license/ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -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
63 changes: 0 additions & 63 deletions spec/unit/provider/elasticsearch_license/xpack_spec.rb

This file was deleted.

1 change: 1 addition & 0 deletions types/multipath.pp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Multipath type
type Elasticsearch::Multipath = Variant[Array[Stdlib::Absolutepath], Stdlib::Absolutepath]
1 change: 1 addition & 0 deletions types/status.pp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Status type
type Elasticsearch::Status = Enum['enabled', 'disabled', 'running', 'unmanaged']
Loading