obscure_yaml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d03aa807687824a25fbe84157baa752f6707d1c
4
+ data.tar.gz: 6bde24370f2d14c8c35b392b2c360e99dce8fab6
5
+ SHA512:
6
+ metadata.gz: fe9ab40fbe9efdbc54b66912f50e818f5b3ea753a4a7d7d84bf43b74d64c8915acd65cf074089b434ba23d98809e960973489228e9d316eba2ae248440d7d5ac
7
+ data.tar.gz: 454cd7bfb0d48b316da75dd89f08371b663632ec670314a91ca85cca0e448a68d2661d3aa5c3b0766762ac0647fd4ccdd87bae5bb92cf6e3aa72a5f46346f74b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 bglusman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # obscure-yaml
2
+
3
+ This gem contains helper classes for working with Base64 encoded
4
+ Yaml files, in case the values you need to serialize are not valid YAML values without escaping etc, it will either read the value from a specified fle or use yaml value directly, and write the resulting data all to a single yaml file with 100% base64 encoded values for consistency.
data/bin/obscure ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/obscure_yaml/cli'
3
+
4
+ ObscureYaml::Cli.parse(ARGV)
5
+
@@ -0,0 +1,18 @@
1
+ require_relative '../obscure_yaml'
2
+ module ObscureYaml
3
+ module Cli
4
+ DECODE = 'decode'
5
+ ENCODE = 'encode'
6
+ module_function
7
+
8
+ def parse(arguments)
9
+ case arguments.shift
10
+ when DECODE
11
+ ObscureYaml.decode(*arguments)
12
+ when ENCODE
13
+ ObscureYaml.encode(arguments.pop, *arguments)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ObscureYaml
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,54 @@
1
+ # require 'obscure_yaml/base64'
2
+ require 'yaml'
3
+ require 'base64'
4
+ module ObscureYaml
5
+ DEFAULT_DATA_KEY = 'data'
6
+ MAGIC_DELIMITER = '@'
7
+ module_function
8
+
9
+ def decode(file_path, output=$stdout)
10
+ output << construct_yaml(file_path, :output)
11
+ end
12
+
13
+ def encode(output_path, file_path)
14
+ File.open(output_path, 'w+') do |f|
15
+ f.write(construct_yaml(file_path, :input))
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ module_function
22
+
23
+ def construct_yaml(file_path, direction)
24
+ YAML::load_file(file_path).tap { |hsh|
25
+ data = hsh[obscured_data_key]
26
+ hsh[obscured_data_key] = data.map { |key, value|
27
+ [key, handle_coding(direction, value)]
28
+ }.to_h
29
+ }.to_yaml
30
+ end
31
+
32
+ def handle_coding(direction, value)
33
+ direction == :output ? Base64.decode64(value) : Base64.encode64(value_or_file_contents(value))
34
+ end
35
+
36
+ def value_or_file_contents(value)
37
+ return value unless detect_file(value)
38
+ require 'open-uri'
39
+ value_contents = open(value.gsub(magic_delimiter, '')) { |f| f.read }
40
+ end
41
+
42
+ def detect_file(value)
43
+ value.match /\A#{magic_delimiter}(.+)#{magic_delimiter}\z/
44
+ end
45
+
46
+ def magic_delimiter
47
+ ENV['MAGIC_FILE'] || MAGIC_DELIMITER
48
+ end
49
+
50
+ def obscured_data_key
51
+ ENV['DATA_KEY'] || DEFAULT_DATA_KEY
52
+ end
53
+
54
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+ require 'obscure_yaml/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'obscure_yaml'
8
+ s.version = ObscureYaml::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Brian Glusman']
11
+ s.email = ['brian@stellaservice.com']
12
+ s.homepage = 'https://github.com/stellaservice/obscure_yaml'
13
+ s.license = 'MIT'
14
+ s.summary = 'Obscure YAML produces and consumes obscure yaml via base64 encoding/decoding and referenced files'
15
+ s.rubyforge_project = 'obscure_yaml'
16
+
17
+ s.description = <<-DESC
18
+ There was no call for this really, except we needed it.
19
+ DESC
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
24
+ s.require_paths = ['lib']
25
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obscure_yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Glusman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " There was no call for this really, except we needed it.\n"
14
+ email:
15
+ - brian@stellaservice.com
16
+ executables:
17
+ - obscure
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - bin/obscure
26
+ - lib/obscure_yaml.rb
27
+ - lib/obscure_yaml/cli.rb
28
+ - lib/obscure_yaml/version.rb
29
+ - obscure_yaml.gemspec
30
+ homepage: https://github.com/stellaservice/obscure_yaml
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project: obscure_yaml
50
+ rubygems_version: 2.5.1
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Obscure YAML produces and consumes obscure yaml via base64 encoding/decoding
54
+ and referenced files
55
+ test_files: []