Permalink
Browse files

Merge tag '2.0.0' into stable

2.0.0
  • Loading branch information...
crayfishx committed Apr 27, 2017
2 parents f900941 + 76fdf65 commit e0eb19b7b9807c86e1a04ca1bd7dd7ef28933c89
Showing with 843 additions and 475 deletions.
  1. +1 −0 .gitignore
  2. +16 −9 .travis.yml
  3. +1 −1 Rakefile
  4. +0 −59 lib/hiera/backend/jerakia_backend.rb
  5. +4 −5 lib/jerakia.rb
  6. +33 −3 lib/jerakia/answer.rb
  7. +3 −1 lib/jerakia/cli.rb
  8. +3 −3 lib/jerakia/cli/lookup.rb
  9. +58 −0 lib/jerakia/cli/secret.rb
  10. +73 −32 lib/jerakia/datasource.rb
  11. +6 −10 lib/jerakia/datasource/dummy.rb
  12. +77 −63 lib/jerakia/datasource/file.rb
  13. +9 −11 lib/jerakia/datasource/file/json.rb
  14. +12 −14 lib/jerakia/datasource/file/yaml.rb
  15. +15 −17 lib/jerakia/dsl/lookup.rb
  16. +11 −8 lib/jerakia/dsl/policy.rb
  17. +60 −0 lib/jerakia/encryption.rb
  18. +168 −0 lib/jerakia/encryption/vault.rb
  19. +10 −0 lib/jerakia/error.rb
  20. +18 −6 lib/jerakia/launcher.rb
  21. +2 −18 lib/jerakia/log.rb
  22. +0 −24 lib/jerakia/lookup.rb
  23. +31 −58 lib/jerakia/policy.rb
  24. +2 −1 lib/jerakia/response/filter.rb
  25. +21 −38 lib/jerakia/response/filter/encryption.rb
  26. +3 −3 lib/jerakia/schema.rb
  27. +51 −0 lib/jerakia/util/http.rb
  28. +1 −1 lib/jerakia/version.rb
  29. +0 −33 lib/puppet/indirector/data_binding/jerakia.rb
  30. +0 −44 lib/puppet/indirector/data_binding/jerakia_rest.rb
  31. +12 −7 spec/features/dsl_spec.rb
  32. +126 −0 spec/features/encryption_vault_spec.rb
  33. +1 −1 spec/unit/jerakia_spec.rb
  34. +10 −1 test/fixtures/etc/jerakia/jerakia.yaml
  35. +1 −1 test/fixtures/etc/jerakia/policy.d/autorun.rb
  36. +1 −1 test/fixtures/etc/jerakia/policy.d/default.rb
  37. +1 −2 test/fixtures/etc/jerakia/policy.d/schema.rb
  38. +2 −0 test/fixtures/var/lib/jerakia/data/common/test.yaml
@@ -3,3 +3,4 @@
*.swp
test/fixtures/var/db/jerakia/*
/Gemfile.lock
jerakia-puppet
@@ -1,19 +1,26 @@
before_install:
- git clone https://github.com/crayfishx/jerakia-puppet.git ./jerakia-puppet


language: ruby
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2

env:
- PUPPET_GEM_VERSION="~> 3.6.2"
- PUPPET_GEM_VERSION="~> 3.7.0"
- PUPPET_GEM_VERSION="~> 3.8.0"
- PUPPET_GEM_VERSION="~> 3.8.6"
- PUPPET_GEM_VERSION="~> 4.1.0"
- PUPPET_GEM_VERSION="~> 4.2.0"
- PUPPET_GEM_VERSION="~> 4.3.0"
- PUPPET_GEM_VERSION="~> 4.4.0"
- PUPPET_GEM_VERSION="~> 4.5.0"
matrix:
- PUPPET_GEM_VERSION="~> 3.6.2"
- PUPPET_GEM_VERSION="~> 3.7.0"
- PUPPET_GEM_VERSION="~> 3.8.0"
- PUPPET_GEM_VERSION="~> 3.8.6"
- PUPPET_GEM_VERSION="~> 4.1.0"
- PUPPET_GEM_VERSION="~> 4.2.0"
- PUPPET_GEM_VERSION="~> 4.3.0"
- PUPPET_GEM_VERSION="~> 4.4.0"
- PUPPET_GEM_VERSION="~> 4.5.0"

matrix:
exclude:
- rvm: 2.2
@@ -3,7 +3,7 @@ require 'rake'
require 'rspec/core/rake_task'

@top_dir=Dir.pwd
ENV['RUBYLIB'] = "#{@top_dir}/lib"
ENV['RUBYLIB'] = "#{@top_dir}/lib:#{@top_dir}/jerakia-puppet/lib"
ENV['JERAKIA_CONFIG'] = "#{@top_dir}/test/fixtures/etc/jerakia/jerakia.yaml"

RSpec::Core::RakeTask.new(:spec)

This file was deleted.

Oops, something went wrong.
@@ -15,6 +15,7 @@ class Jerakia
require 'jerakia/error'

attr_reader :options
attr_reader :launcher

class << self
attr_reader :config
@@ -26,6 +27,7 @@ class << self

def initialize(options = {})
@options = options
@policies = {}

load_config
load_log_handler
@@ -36,14 +38,11 @@ def initialize(options = {})

log.debug('Jerakia initialized')
Jerakia.log.verbose("Jerakia started. Version #{Jerakia::VERSION}")
@launcher = Jerakia::Launcher.new
end

def lookup(request)
lookup_instance = Jerakia::Launcher.new(request)
lookup_instance.invoke_from_file
lookup_instance.answer
rescue Jerakia::Error => e
Jerakia.fatal(e.message, e)
launcher.policies[request.policy.to_sym].run(request)
end

def self.fatal(msg, e)
@@ -4,9 +4,12 @@ class Answer

attr_accessor :payload
attr_accessor :datatype
attr_reader :merge_strategy
attr_reader :lookup_type

def initialize(lookup_type = :first)
def initialize(lookup_type = :first, merge_strategy = :array)
@lookup_type = lookup_type
@merge_strategy = merge_strategy
case lookup_type
when :first
@payload = nil
@@ -16,17 +19,44 @@ def initialize(lookup_type = :first)
end
end

def process_response(response_entries)
response_entries.flatten.each do |res|
case lookup_type
when :first
@payload = res[:value]
@datatype = res[:datatype]
Jerakia.log.debug("Registered answer as #{payload}")
break
when :cascade
@payload << res[:value]
end
end
consolidate
end

def consolidate
if lookup_type == :cascade && payload.is_a?(Array)
case merge_strategy
when :array
flatten_payload!
when :hash, :deep_hash
merge_payload!
end
end
end


def flatten_payload!
@payload.flatten!
end

# TODO: consolidate this into less lines
#
def merge_payload!(method = :hash) # rubocop:disable Metrics/MethodLength
def merge_payload! # rubocop:disable Metrics/MethodLength
payload_hash = {}
@payload.each do |p|
next unless p.is_a?(Hash)
case method
case merge_strategy
when :hash
payload_hash = p.merge(payload_hash)
when :deep_hash
@@ -5,13 +5,15 @@
require 'jerakia/cli/server'
require 'jerakia/cli/token'
require 'jerakia/cli/lookup'

require 'jerakia/cli/secret'

class Jerakia
class CLI < Thor
include Jerakia::CLI::Server
include Jerakia::CLI::Lookup
include Jerakia::CLI::Token
include Jerakia::CLI::Secret


desc 'version', 'Version information'
def version
@@ -66,13 +66,13 @@ def self.included(thor)
efault: 'json',
desc: 'Output format, yaml or json'

def lookup(key)
def lookup(key=nil)
# Thor by default now returns a frozen options hash so we
# need to dup this here to prevent problems later with
# modifying the request object
#
options_copy = options.dup

key_copy = key.nil? ? key : key.dup
case true
when options[:verbose]
loglevel = 'verbose'
@@ -91,7 +91,7 @@ def lookup(key)
:loglevel => loglevel,
:trace => options[:trace])
req = Jerakia::Request.new(
:key => key.dup,
:key => key_copy,
:namespace => options_copy[:namespace].split(/::/),
:policy => options_copy[:policy].to_sym,
:lookup_type => options_copy[:type].to_sym,
@@ -0,0 +1,58 @@
require 'jerakia/encryption'
require 'jerakia'

class Jerakia
class CLI < Thor
module Secret
class Secret < Thor

Jerakia.new
@provider = Jerakia::Encryption.new

class << self
attr_reader :provider
end

no_commands do
def provider
self.class.provider
end
end

if @provider.features?(:decrypt)
desc 'decrypt <encrypted value>', 'Decrypt an encrypted value'
def decrypt(encrypted)
begin
plaintext = provider.decrypt(encrypted)
rescue Jerakia::EncryptionError => e
puts e.message
exit(1)
end
puts plaintext
end
end

if @provider.features?(:encrypt)
desc 'encrypt <string>', 'Encrypt a plain text string'
def encrypt(plaintext)
begin
encrypted = provider.encrypt(plaintext)
rescue Jerakia::EncryptionError => e
puts e.message
exit(1)
end
puts encrypted
end
end
end

def self.included(thor)
thor.class_eval do
info = Secret.provider.loaded? ? "" : "(No encryption provider configured!)"
desc 'secret [SUBCOMMAND] <options>', "Manage encrypted secrets #{info}"
subcommand 'secret', Secret
end
end
end
end
end
Oops, something went wrong.

0 comments on commit e0eb19b

Please sign in to comment.