Skip to content

Commit

Permalink
add generators for random IDs and secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Nov 19, 2015
1 parent 4e3ff8c commit f1abcb3
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exe/formatron
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require 'formatron/cli'
require 'formatron/cli/generators/credentials'
require 'formatron/cli/generators/bootstrap'
require 'formatron/cli/generators/instance'
require 'formatron/cli/generators/guid'
require 'formatron/cli/generators/databag_secret'
require 'formatron/cli/deploy'
require 'formatron/cli/destroy'
require 'formatron/cli/provision'
Expand All @@ -12,6 +14,8 @@ require 'formatron/cli/completion'
Formatron::CLI.include Formatron::CLI::Generators::Credentials
Formatron::CLI.include Formatron::CLI::Generators::Bootstrap
Formatron::CLI.include Formatron::CLI::Generators::Instance
Formatron::CLI.include Formatron::CLI::Generators::GUID
Formatron::CLI.include Formatron::CLI::Generators::DatabagSecret
Formatron::CLI.include Formatron::CLI::Deploy
Formatron::CLI.include Formatron::CLI::Destroy
Formatron::CLI.include Formatron::CLI::Provision
Expand Down
25 changes: 25 additions & 0 deletions lib/formatron/cli/generators/databag_secret.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'formatron/generators/util'

class Formatron
class CLI
module Generators
# CLI command for databag secret generator
module DatabagSecret
def databag_secret_action(c)
c.action do |_args, _options|
puts Formatron::Generators::Util.databag_secret
end
end

def databag_secret_formatron_command
command :'generate data bag secret' do |c|
c.syntax = 'formatron generate data bag secret [options]'
c.summary = 'Generate a random data bag secret'
c.description = 'Generate a random data bag secret'
databag_secret_action c
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/formatron/cli/generators/guid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'formatron/generators/util'

class Formatron
class CLI
module Generators
# CLI command for GUID generator
module GUID
def guid_action(c)
c.action do |_args, _options|
puts Formatron::Generators::Util.guid
end
end

def guid_formatron_command
command :'generate guid' do |c|
c.syntax = 'formatron generate guid [options]'
c.summary = 'Generate a random GUID'
c.description = 'Generate a random GUID'
guid_action c
end
end
end
end
end
end
35 changes: 35 additions & 0 deletions spec/formatron/cli/generators/databag_secret_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

require 'formatron/cli'
require 'formatron/cli/generators/databag_secret'

describe Formatron::CLI::Generators::DatabagSecret do
include FakeFS::SpecHelpers

# Test harness
class Test < Formatron::CLI
include Formatron::CLI::Generators::DatabagSecret
end

before(:each) do
allow(Commander::Runner).to receive(:instance) do
@singleton ||=
Commander::Runner.new [
'generate',
'data',
'bag',
'secret',
'-t'
]
end
end

it 'should print a data bag secret' do
expect(
Formatron::Generators::Util
).to receive(:databag_secret).once.with(
no_args
)
Test.new.run
end
end
33 changes: 33 additions & 0 deletions spec/formatron/cli/generators/guid_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

require 'formatron/cli'
require 'formatron/cli/generators/guid'

describe Formatron::CLI::Generators::GUID do
include FakeFS::SpecHelpers

# Test harness
class Test < Formatron::CLI
include Formatron::CLI::Generators::GUID
end

before(:each) do
allow(Commander::Runner).to receive(:instance) do
@singleton ||=
Commander::Runner.new [
'generate',
'guid',
'-t'
]
end
end

it 'should print a GUID' do
expect(
Formatron::Generators::Util
).to receive(:guid).once.with(
no_args
)
Test.new.run
end
end

0 comments on commit f1abcb3

Please sign in to comment.