Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
If you want authentication turned on then you need to authenticate du…
Browse files Browse the repository at this point in the history
…ring the creation of all the things

references #8
  • Loading branch information
pvandervelde committed Jan 16, 2020
1 parent c087ddb commit c269831
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/cookbooks/resource_metrics_storage/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
default['influxdb']['port']['graphite'] = 2003
default['influxdb']['port']['http'] = 8086

# Note: the admin user needs to be set so that future users can
# further configure Influx. This
# password should be changed when the machine is provisioned!!!!!!
default['influxdb']['users']['admin']['username'] = 'admin'
default['influxdb']['users']['admin']['password'] = 'admin-password'

default['influxdb']['users']['interal_metrics']['username'] = 'user.internal.read'
default['influxdb']['users']['interal_metrics']['password'] = SecureRandom.uuid

Expand Down
55 changes: 50 additions & 5 deletions src/cookbooks/resource_metrics_storage/recipes/influxdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,32 @@
# INSTALL INFLUXDB
#

include_recipe 'influxdb::default'
chef_gem 'toml' do
compile_time false if respond_to?(:compile_time)
end

chef_gem 'influxdb' do
version '0.6.1'
compile_time false if respond_to?(:compile_time)
end

influxdb_install 'influxdb' do
action [:install]
include_repository node['influxdb']['include_repository']
install_type node['influxdb']['install_type']
install_version node['influxdb']['version']
end

# should really wait for influx to become available
service 'influxdb' do
action :nothing
supports status: true
end

influxdb_config node['influxdb']['config_file_path'] do
config node['influxdb']['config']
notifies :restart, 'service[influxdb]', :immediate
end

#
# SET PERMISSIONS ON DATA PATH
Expand Down Expand Up @@ -410,34 +435,52 @@
owner node['influxdb']['service_user']
end

#
# CREATE THE ADMIN USER
#

# Do that here so that chef can interact with Influx
influxdb_admin node['influxdb']['users']['admin']['username'] do
action :create
password node['influxdb']['users']['admin']['password']
end

#
# CREATE THE DATABASES
#

influxdb_database 'system' do
action :create
auth_username node['influxdb']['users']['admin']['username']
auth_password node['influxdb']['users']['admin']['password']
end

influxdb_retention_policy 'retention.system' do
policy_name 'retention.system'
action :create
auth_username node['influxdb']['users']['admin']['username']
auth_password node['influxdb']['users']['admin']['password']
database 'system'
default true
duration '2w'
policy_name 'retention.system'
replication 1
action :create
end

influxdb_database 'services' do
action :create
auth_username node['influxdb']['users']['admin']['username']
auth_password node['influxdb']['users']['admin']['password']
end

influxdb_retention_policy 'retention.services' do
policy_name 'retention.services'
action :create
auth_username node['influxdb']['users']['admin']['username']
auth_password node['influxdb']['users']['admin']['password']
database 'services'
default true
duration '26w'
policy_name 'retention.services'
replication 1
action :create
end

#
Expand All @@ -446,6 +489,8 @@

influxdb_user node['influxdb']['users']['interal_metrics']['username'] do
action :create
auth_username node['influxdb']['users']['admin']['username']
auth_password node['influxdb']['users']['admin']['password']
databases ['_internal']
password node['influxdb']['users']['interal_metrics']['password']
permissions ['READ']
Expand Down
22 changes: 17 additions & 5 deletions src/cookbooks/resource_metrics_storage/spec/influxdb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
require 'spec_helper'

describe 'resource_metrics_storage::influxdb' do
context 'installs InfluxDB' do
context 'configures directories' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'creates and mounts the data file system at /srv/influxdb' do
expect(chef_run).to create_directory('/srv/influxdb')
end

it 'installs the InfluxDB service' do
expect(chef_run).to include_recipe('influxdb::default')
end

it 'creates and mounts the data file system at /srv/influxdb/data' do
expect(chef_run).to create_directory('/srv/influxdb/data').with(
group: 'influxdb',
Expand Down Expand Up @@ -347,6 +343,22 @@
end
end

context 'installs influxdb' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'installs the service' do
expect(chef_run).to install_influxdb_install('influxdb')
end

it 'starts the service' do
expect(chef_run).to nothing_service('influxdb')
end

it 'configures influxdb' do
expect(chef_run).to create_influxdb_config('/etc/influxdb/influxdb.conf')
end
end

context 'creates the databases and sets retention policies' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

Expand Down

0 comments on commit c269831

Please sign in to comment.