Skip to content

Commit

Permalink
Switch to cookstyle and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Skopenko committed Nov 8, 2017
1 parent 4437b04 commit 3cc1eda
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 95 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ script:
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/rubocop --version
- /opt/chefdk/embedded/bin/foodcritic --version
- /opt/chefdk/embedded/bin/rspec
- /opt/chefdk/embedded/bin/rake
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright:: 2017 Andrei Skopenko

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
36 changes: 33 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
require 'emeril/rake_tasks'
#!/usr/bin/env rake

Emeril::RakeTasks.new do |t|
t.config[:category] = 'Monitoring & Trending'
require 'foodcritic'
require 'cookstyle'
require 'kitchen'
require 'rubocop/rake_task'

# Style tests. Cookstyle (rubocop) and Foodcritic
namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)

desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
progress: true,
}
end
end

desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']

# Integration tests. Kitchen.ci
namespace :integration do
desc 'Run Test Kitchen with Vagrant'
task :vagrant do
Kitchen.logger = Kitchen.default_file_logger
Kitchen::Config.new.instances.each(&:test)
end
end

# Default
task default: %w(style)
10 changes: 5 additions & 5 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
default['grafana']['ini']['database']['type'] = {
comment: "Either mysl, postgres, sqlite3, it's your choice",
disable: false,
value: 'sqlite3'
value: 'sqlite3',
}
default['grafana']['ini']['database']['host'] = '127.0.0.1:3306'
default['grafana']['ini']['database']['name'] = 'grafana'
Expand All @@ -76,22 +76,22 @@
default['grafana']['ini']['database']['ssl_mode'] = {
comment: 'For "postgres" only, either "disable", "require" or "verify-full"',
disable: true,
value: 'disable'
value: 'disable',
}
default['grafana']['ini']['database']['path'] = {
comment: 'For sqlite3 only, path relative to data_path setting',
disable: false,
value: 'grafana.db'
value: 'grafana.db',
}

default['grafana']['ini']['auth.ldap']['enabled'] = {
comment: '',
disable: true,
value: false
value: false,
}
default['grafana']['ini']['auth.ldap']['config_file'] = {
disable: true,
value: '/etc/grafana/ldap.toml'
value: '/etc/grafana/ldap.toml',
}

# server
Expand Down
40 changes: 20 additions & 20 deletions attributes/ldap_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,87 @@
default['grafana']['ldap']['[servers]']['host'] = {
comment: 'Ldap server host',
disable: false,
value: '"127.0.0.1"'
value: '"127.0.0.1"',
}
default['grafana']['ldap']['[servers]']['port'] = {
comment: 'Default port is 389 or 636 if use_ssl = true',
disable: false,
value: 389
value: 389,
}
default['grafana']['ldap']['[servers]']['use_ssl'] = {
comment: 'Set to true if ldap server supports TLS',
disable: false,
value: false
value: false,
}
default['grafana']['ldap']['[servers]']['ssl_skip_verify'] = {
comment: 'set to true if you want to skip ssl cert validation',
disable: false,
value: false
value: false,
}
default['grafana']['ldap']['[servers]']['bind_dn'] = {
comment: 'Search user bind dn',
disable: false,
value: '"cn=admin,dc=grafana,dc=org"'
value: '"cn=admin,dc=grafana,dc=org"',
}
default['grafana']['ldap']['[servers]']['bind_password'] = {
comment: 'Search user bind password',
disable: false,
value: 'grafana'
value: 'grafana',
}
default['grafana']['ldap']['[servers]']['search_filter'] = {
comment: 'Search filter, for example "(cn=%s)" or "(sAMAccountName=%s)"',
disable: false,
value: '"(cn=%s)"'
value: '"(cn=%s)"',
}
default['grafana']['ldap']['[servers]']['search_base_dns'] = {
comment: 'An array of base dns to search through',
disable: false,
value: ['dc=grafana,dc=org']
value: ['dc=grafana,dc=org'],
}
default['grafana']['ldap']['servers.attributes'] = {
name: { value: '"givenName"' },
surname: { value: '"sn"' },
username: { value: '"cn"' },
member_of: { value: '"memberOf"' },
email: { value: '"email"' }
email: { value: '"email"' },
}
default['grafana']['ldap']['[servers.group_mappings]'] = [
{
group_dn: {
comment: 'Map ldap groups to grafana org roles',
disable: false,
value: '"cn=admins,dc=grafana,dc=org"'
value: '"cn=admins,dc=grafana,dc=org"',
},
org_role: {
disable: false,
value: '"Admin"'
value: '"Admin"',
},
org_id: {
comment: 'The Grafana organization database id, optional, ' \
'if left out the default org (id 1) will be used',
disable: true,
value: 1
}
value: 1,
},
},
{
group_dn: {
disable: false,
value: '"cn=users,dc=grafana,dc=org"'
value: '"cn=users,dc=grafana,dc=org"',
},
org_role: {
disable: false,
value: '"Editor"'
}
value: '"Editor"',
},
},
{
group_dn: {
comment: 'If you want to match all (or no ldap groups) then you can use wildcard',
disable: false,
value: '"*"'
value: '"*"',
},
org_role: {
disable: false,
value: '"Viewer"'
}
}
value: '"Viewer"',
},
},
]
4 changes: 2 additions & 2 deletions libraries/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def with_limited_retry(opts)
# Generic method to build, perform and handle response of any API requests
# Params:
# +grafana_options+:: A hash of the host, port, user, and password as well as request parameters
def do_request(grafana_options, payload=nil)
def do_request(grafana_options, payload = nil)
session_id = login(grafana_options[:host], grafana_options[:port], grafana_options[:user], grafana_options[:password])
http = Net::HTTP.new(grafana_options[:host], grafana_options[:port])
request = case grafana_options[:method]
Expand Down Expand Up @@ -151,7 +151,7 @@ def handle_response_conn_refused

def handle_response_unknown(request, code, message)
if message
Chef::Log.error(message % { code: code })
Chef::Log.error(format(message, code: code))
else
Chef::Log.error "Response code '#{code}' not handled when sending #{request_message request}"
end
Expand Down
6 changes: 3 additions & 3 deletions libraries/dashboard_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create_update_dashboard(dashboard, grafana_options)
dashboard_source_file = find_dashboard_source_file dashboard
dashboard_options = {
'dashboard' => JSON.parse(File.read(dashboard_source_file)),
'overwrite' => dashboard[:overwrite]
'overwrite' => dashboard[:overwrite],
}

grafana_options[:method] = 'Post'
Expand Down Expand Up @@ -46,13 +46,13 @@ def dashboard_sanity(dashboard_options)
else
"#{dashboard_options[:source]} resource name or source"
end
fail "dashboard_sanity failure: #{err_msg_prt} was specified, but no dashboard found (checked: #{checked_paths})"
raise "dashboard_sanity failure: #{err_msg_prt} was specified, but no dashboard found (checked: #{checked_paths})"
end
dash_json = JSON.parse(File.read(dashboard_source_file))

dash_json_title = dash_json['title'].tr('.', '-').tr(' ', '-').downcase
if dash_json_title != dashboard_options[:name]
fail "dashboard_sanity failure: the resource name (#{dashboard_options[:name]}) "\
raise "dashboard_sanity failure: the resource name (#{dashboard_options[:name]}) "\
"did not match the \"title\" in the json (#{dash_json_title}) or is not a valid Grafana slug. "\
'See http://docs.grafana.org/reference/http_api/#get-dashboard for more details.'
end
Expand Down
1 change: 0 additions & 1 deletion libraries/organization_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,5 @@ def select_org(organization, grafana_options)
rescue BackendError
nil
end

end
end
12 changes: 8 additions & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name 'grafana'
maintainer 'Jonathan Tron'
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Installs/Configures grafana'
maintainer 'Andrei Skopenko'
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Installs/Configures Grafana Server'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.1.3'
source_url 'https://github.com/sous-chefs/chef-grafana'
issues_url 'https://github.com/sous-chefs/chef-grafana/issues'

chef_version '>= 11.0'

supports 'ubuntu', '>= 12.04'
supports 'debian', '>= 7.0'
Expand Down
6 changes: 3 additions & 3 deletions providers/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If dashboard's name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -54,7 +54,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If dashboard's name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -92,7 +92,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If dashboard's name is not provided as variable,
# Let's use resource name for it
Expand Down
17 changes: 8 additions & 9 deletions providers/datasource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If datasource name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -45,7 +45,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If datasource name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -84,7 +84,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If datasource name is not provided as variable,
# Let's use resource name for it
Expand All @@ -100,12 +100,11 @@ def whyrun_supported?
# Find wether datasource already exists
# If found, delete it
datasources.each do |src|
if src['name'] == new_resource.datasource[:name]
exists = true
new_resource.datasource[:id] = src['id']
converge_by("Deleting data source #{new_resource.name}") do
delete_datasource(new_resource.datasource, grafana_options)
end
next unless src['name'] == new_resource.datasource[:name]
exists = true
new_resource.datasource[:id] = src['id']
converge_by("Deleting data source #{new_resource.name}") do
delete_datasource(new_resource.datasource, grafana_options)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions providers/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -41,7 +41,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If name is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -76,7 +76,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If name is not provided as variable,
# Let's use resource name for it
Expand Down
6 changes: 3 additions & 3 deletions providers/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If login is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -59,7 +59,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If login is not provided as variable,
# Let's use resource name for it
Expand Down Expand Up @@ -109,7 +109,7 @@ def whyrun_supported?
host: new_resource.host,
port: new_resource.port,
user: new_resource.admin_user,
password: new_resource.admin_password
password: new_resource.admin_password,
}
# If login is not provided as variable,
# Let's use resource name for it
Expand Down
Loading

0 comments on commit 3cc1eda

Please sign in to comment.