Skip to content

Commit

Permalink
Merge pull request #5 from inspec/mj/chefstyle
Browse files Browse the repository at this point in the history
Apply Chefstyle to train-aws
  • Loading branch information
miah authored Jun 19, 2019
2 parents 53339ca + ee59e9e commit 399dfc6
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 229 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Gemfile.local
Gemfile.local.lock
Gemfile.lock
.bundle
26 changes: 9 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# encoding: utf-8
source 'https://rubygems.org'
source "https://rubygems.org"

# This is Gemfile, which is used by bundler
# to ensure a coherent set of gems is installed.
# This file lists dependencies needed when outside
# of a gem (the gemspec lists deps for gem deployment)

# Bundler should refer to the gemspec for any dependencies.
gemspec

# Remaining group is only used for development.
group :development do
gem 'pry'
gem 'bundler'
gem 'byebug'
gem 'minitest'
gem 'mocha'
gem 'm'
gem 'rake'
gem 'rubocop', '= 0.49.1' # Need to keep in sync with main InSpec project, so config files will work
gem "pry"
gem "bundler"
gem "byebug"
gem "minitest"
gem "mocha"
gem "m"
gem "rake"
gem "chefstyle"
end
29 changes: 11 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ task default: [:'test:unit', :'test:functional']
#------------------------------------------------------------------#
# Test Runner Tasks
#------------------------------------------------------------------#
require 'rake/testtask'
require "rake/testtask"

namespace :test do
{
unit: 'test/unit/*_test.rb',
functional: 'test/integration/*_test.rb',
integration: 'test/function/*_test.rb',
unit: "test/unit/*_test.rb",
functional: "test/integration/*_test.rb",
integration: "test/function/*_test.rb",
}.each do |task_name, glob|
Rake::TestTask.new(task_name) do |t|
t.libs.push 'lib'
t.libs.push 'test'
t.libs.push "lib"
t.libs.push "test"
t.test_files = FileList[glob]
t.verbose = true
t.warning = false
Expand All @@ -32,15 +32,8 @@ end
# #------------------------------------------------------------------#
# # Code Style Tasks
# #------------------------------------------------------------------#
# require 'rubocop/rake_task'

# RuboCop::RakeTask.new(:lint) do |t|
# # Choices of rubocop rules to enforce are deeply personal.
# # Here, we set things up so that your plugin will use the Bundler-installed
# # train gem's copy of the Train project's rubocop.yml file (which
# # is indeed packaged with the train gem).
# require 'train/globals'
# train_rubocop_yml = File.join(Train.src_root, '.rubocop.yml')

# t.options = ['--display-cop-names', '--config', train_rubocop_yml]
# end
require "chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:lint) do |task|
task.options << "--display-cop-names"
end
8 changes: 4 additions & 4 deletions lib/train-aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

# It's traditonal to keep your gem version in a separate file, so CI can find it easier.
require 'train-aws/version'
require "train-aws/version"

# A train plugin has three components: Transport, Connection, and Platform.
# Transport acts as the glue.
require 'train-aws/transport'
require 'train-aws/platform'
require 'train-aws/connection'
require "train-aws/transport"
require "train-aws/platform"
require "train-aws/connection"
44 changes: 22 additions & 22 deletions lib/train-aws/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@

# Push platform detection out to a mixin, as it tends
# to develop at a different cadence than the rest
require 'train-aws/platform'
require 'train'
require 'train/plugins'
require "train-aws/platform"
require "train"
require "train/plugins"

require 'aws-sdk-core'
require "aws-sdk-core"

require 'aws-sdk-cloudtrail'
require 'aws-sdk-cloudwatch'
require 'aws-sdk-cloudwatchlogs'
require 'aws-sdk-costandusagereportservice'
require 'aws-sdk-configservice'
require 'aws-sdk-ec2'
require 'aws-sdk-ecs'
require 'aws-sdk-eks'
require 'aws-sdk-elasticloadbalancing'
require 'aws-sdk-iam'
require 'aws-sdk-kms'
require 'aws-sdk-rds'
require 'aws-sdk-s3'
require 'aws-sdk-sqs'
require 'aws-sdk-sns'
require "aws-sdk-cloudtrail"
require "aws-sdk-cloudwatch"
require "aws-sdk-cloudwatchlogs"
require "aws-sdk-costandusagereportservice"
require "aws-sdk-configservice"
require "aws-sdk-ec2"
require "aws-sdk-ecs"
require "aws-sdk-eks"
require "aws-sdk-elasticloadbalancing"
require "aws-sdk-iam"
require "aws-sdk-kms"
require "aws-sdk-rds"
require "aws-sdk-s3"
require "aws-sdk-sqs"
require "aws-sdk-sns"

module TrainPlugins
module Aws
Expand All @@ -58,7 +58,7 @@ def initialize(options)
options[:region] = options[:host] || options[:region]
if options[:path]
# string the leading / from path
options[:profile] = options[:path].sub(%r{^/}, '')
options[:profile] = options[:path].sub(%r{^/}, "")
end

# Now let the BaseConnection have a chance to configure itself.
Expand All @@ -69,8 +69,8 @@ def initialize(options)

# Why are we doing this?
# Why aren't we calling the AWS config system?
ENV['AWS_PROFILE'] = @options[:profile] if @options[:profile]
ENV['AWS_REGION'] = @options[:region] if @options[:region]
ENV["AWS_PROFILE"] = @options[:profile] if @options[:profile]
ENV["AWS_REGION"] = @options[:region] if @options[:region]
end

# We support caching on the aws_client call, but not the aws_resource call
Expand Down
6 changes: 3 additions & 3 deletions lib/train-aws/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def platform
# of the cloud family.

# This plugin defines a new platform.
Train::Platforms.name('aws').in_family('cloud')
Train::Platforms.name("aws").in_family("cloud")

# When you know you will only ever run on your dedicated platform
# force_platform! lets you bypass platform detection.
Expand All @@ -29,11 +29,11 @@ def platform
# Use release to report a version number. You might use the version
# of the plugin, or a version of an important underlying SDK, or a
# version of a remote API.
aws_version = Gem.loaded_specs['aws-sdk-core'].version
aws_version = Gem.loaded_specs["aws-sdk-core"].version
aws_version = "aws-sdk-core: v#{aws_version}"
plugin_version = "train-aws: v#{TrainPlugins::Aws::VERSION}"

force_platform!('aws', release: "#{plugin_version}, #{aws_version}")
force_platform!("aws", release: "#{plugin_version}, #{aws_version}")
end
end
end
20 changes: 10 additions & 10 deletions lib/train-aws/transport.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@

require 'train'
require 'train/plugins'
require 'aws-sdk-core'
require "train"
require "train/plugins"
require "aws-sdk-core"

# Train Plugins v1 are usually declared under the TrainPlugins namespace.
# Each plugin has three components: Transport, Connection, and Platform.
# We'll only define the Transport here, but we'll refer to the others.
require 'train-aws/connection'
require "train-aws/connection"

module TrainPlugins
module Aws
class Transport < Train.plugin(1)
name 'aws'
name "aws"

# Pass ENV vars in using a block to `option`. This causes `
# option to lazy-evaluate the block to provide a default value.`
# Otherwise, we would read the ENV var (and set the default)
# once at compile time, which would make testing difficult.
# TODO: convert to thor-style defaults
option(:region, required: true) { ENV['AWS_REGION'] }
option(:access_key_id) { ENV['AWS_ACCESS_KEY_ID'] }
option(:secret_access_key) { ENV['AWS_SECRET_ACCESS_KEY'] }
option(:session_token) { ENV['AWS_SESSION_TOKEN'] }
option(:region, required: true) { ENV["AWS_REGION"] }
option(:access_key_id) { ENV["AWS_ACCESS_KEY_ID"] }
option(:secret_access_key) { ENV["AWS_SECRET_ACCESS_KEY"] }
option(:session_token) { ENV["AWS_SESSION_TOKEN"] }

# This can provide the access key id and secret access key
option(:profile) { ENV['AWS_PROFILE'] }
option(:profile) { ENV["AWS_PROFILE"] }

# The only thing you MUST do in a transport is a define a
# connection() method that returns a instance that is a
Expand Down
24 changes: 12 additions & 12 deletions test/functional/train-aws_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@
# their app. Unlike unit tests, we don't assume any knowledge of how anything
# works; we just know what it is supposed to do.

require_relative '../helper'
require 'train'
require_relative "../helper"
require "train"

# Train should auto-load train-aws
# require 'train-aws'

describe 'train-aws' do
describe "train-aws" do
describe "creating a train instance with this transport" do
it "should not explode on create" do
# This checks for uncaught exceptions.
Train.create('aws', {})
Train.create("aws", {})

# This checks for warnings (or any other output) to stdout/stderr
proc { Train.create('aws') }.must_be_silent
proc { Train.create("aws") }.must_be_silent
end
end

describe 'creating a connection object using the transport' do
describe "creating a connection object using the transport" do
it "should not explode on connect" do
# This checks for uncaught exceptions.
Train.create('aws').connection
Train.create("aws").connection

# This checks for warnings (or any other output) to stdout/stderr
proc { Train.create('aws').connection }.must_be_silent
proc { Train.create("aws").connection }.must_be_silent
end
end

describe "reading a file" do
it "should throw an exception if you try to read a file" do
conn = Train.create('aws').connection
path = File.join('nonesuch' + rand.to_s)
conn = Train.create("aws").connection
path = File.join("nonesuch" + rand.to_s)
proc { conn.file(path).contents }.must_raise(NotImplementedError)
end
end

describe "running a command" do
it "should throw an exception if you try to run a command" do
conn = Train.create('aws').connection
proc { conn.run_command('date') }.must_raise(NotImplementedError)
conn = Train.create("aws").connection
proc { conn.run_command("date") }.must_raise(NotImplementedError)
end
end
end
12 changes: 6 additions & 6 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# any utilities to make testing a plugin easier.

# require 'train/plugin_test_helper'
require 'minitest/spec'
require 'minitest/mock'
require 'mocha/minitest'
require 'minitest/autorun'
require "minitest/spec"
require "minitest/mock"
require "mocha/minitest"
require "minitest/autorun"

class Module
include Minitest::Spec::DSL
end

# Common debugging tools
require 'pry'
require 'byebug'
require "pry"
require "byebug"
Loading

0 comments on commit 399dfc6

Please sign in to comment.