soar_environment 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cefa3bc5eaa71c5da03f09bd9d4dc5bfe1c51ec2
4
+ data.tar.gz: 2383ea89e73de67d0a573aeaea107fce11808321
5
+ SHA512:
6
+ metadata.gz: 40a3795e20c120d02df36b6d6ebd3440e950287009b260aabb99d6fe55b3956ca7f7fe56f874428b1b946680e68742dc91602b61c821a80ebd1db0796273b793
7
+ data.tar.gz: 052c104809d196139d8fae3f1438d7134ad0e0b9f436b72b47382527d8f8aa1d7a55f3e0a27e42aa78ca355b42d7a2b3f1eb537dd78d605add93992c71ea030f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ *.gem
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_environment
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_environment.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ernst Van Graan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # SoarEnvironment
2
+
3
+ This library provides environment discovery functionality for the SOAR architecture and includes obtaining variables from the environment, and supplementing with an environment YAML file. When RUBY_PLATFORM is 'java', system properties are used instead of ENV. Once loaded, the configuration can be supplemented with values for keys in SOAR_CONFIGURATION_KEYS supplied in a configuration provided.
4
+
5
+ Exceptions raised:
6
+ - ArgumentError when RACK_ENV is not set in the process environment nor environment file
7
+ - ArgumentError when a configuration is not provided or is not a Hash when supplementing environment with configuration
8
+ - SoarEnvironment::LoadError when an environment file does not exist when loading environment
9
+ - SoarEnvironment::LoadError when an environment file cannot be loaded when loading environment
10
+
11
+ Once an environment is loaded (taking process and environment file into account), supplementing from configuration can be performed. Supplementing only provides values if the keys are not already present in the environment, thus if present in an environment file, that entry would be preferred above presence in configuration.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'soar-environment'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install soar-environment
28
+
29
+ ## Usage
30
+
31
+ ```
32
+ @iut = SoarEnvironment::Environment.new
33
+ environment = @iut.load_environment
34
+
35
+ @iut = SoarEnvironment::Environment.new(@environment_file_path)
36
+ environment = @iut.load_environment
37
+ ```
38
+
39
+ Once loaded, the environment can be supplemented with a configuration:
40
+
41
+ ```
42
+ environment = @iut.supplement_with_configuration(config)
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Please send feedback and comments to the author at:
48
+
49
+ Ernst van Graan <ernst.van.graan@hetzner.co.za>
50
+
51
+ This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_environment"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module SoarEnvironment
2
+ VERSION = "0.1.11"
3
+ end
@@ -0,0 +1,60 @@
1
+ require "soar_environment/version"
2
+ require "psych"
3
+ require "yaml"
4
+
5
+ module SoarEnvironment
6
+ class LoadError < RuntimeError; end
7
+
8
+ class Environment
9
+ SOAR_CONFIGURATION_KEYS = ['IDENTIFIER', 'CAS_SERVER', 'SESSION_KEY', 'SESSION_SECRET'] if not defined? SOAR_CONFIGURATION_KEYS; SOAR_CONFIGURATION_KEYS.freeze
10
+
11
+ attr_reader :environment_file
12
+ attr_reader :environment
13
+
14
+ def initialize(environment_file = nil)
15
+ @environment_file = environment_file
16
+ end
17
+
18
+ def load_environment
19
+ @environment = merge(load_file(@environment_file), load_env)
20
+ raise ArgumentError.new("RACK_ENV not set in environment nor in properties or configuration") if (@environment['RACK_ENV'].nil?) or (@environment['RACK_ENV'].strip == "")
21
+ @environment
22
+ end
23
+
24
+ def supplement_with_configuration(configuration, keys = SOAR_CONFIGURATION_KEYS)
25
+ raise ArgumentError.new("configuration not provided") if (configuration.nil?)
26
+ raise ArgumentError.new("configuration not valid") if not (configuration.is_a?(Hash))
27
+ keys.each do |key|
28
+ @environment[key] ||= configuration[key]
29
+ end
30
+ @environment
31
+ end
32
+
33
+ private
34
+
35
+ # Produce a union of hashes, with duplicate keys overriden by the last specified hash to include them.
36
+ def merge(*hashes)
37
+ hashes.inject { |m, s| m.merge(s) }
38
+ end
39
+
40
+ def load_env
41
+ env = (RUBY_PLATFORM == "java" ? java.lang.System.properties.merge(ENV) : ENV)
42
+ env.to_h
43
+ end
44
+
45
+ def load_file(filename)
46
+ if filename
47
+ raise SoarEnvironment::LoadError.new("Failed to load file #{filename} : File does not exist") if not File.exist?(@environment_file)
48
+ stringify_values(::YAML.load_file(filename))
49
+ else
50
+ {}
51
+ end
52
+ rescue IOError, SystemCallError, ::Psych::Exception => ex
53
+ raise SoarEnvironment::LoadError.new("Failed to load file #{@environment_file} : #{ex}")
54
+ end
55
+
56
+ def stringify_values(hash)
57
+ Hash[hash.map{ |k, v| [k, v.to_s] }]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_environment/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_environment"
8
+ spec.version = SoarEnvironment::VERSION
9
+ spec.authors = ["Ernst Van Graan"]
10
+ spec.email = ["ernst.van.graan@hetzner.co.za"]
11
+
12
+ spec.summary = %q{This library determines the set of environment variables for a service component in the SOAR architecture}
13
+ spec.description = %q{This library determines the set of environment variables for a service component in the SOAR architecture}
14
+ spec.homepage = "https://github.com/hetznerZA/soar_environment"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "psych", "~> 2.1.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "byebug"
36
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_environment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.11
5
+ platform: ruby
6
+ authors:
7
+ - Ernst Van Graan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This library determines the set of environment variables for a service
84
+ component in the SOAR architecture
85
+ email:
86
+ - ernst.van.graan@hetzner.co.za
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/soar_environment.rb
103
+ - lib/soar_environment/version.rb
104
+ - soar_environment.gemspec
105
+ homepage: https://github.com/hetznerZA/soar_environment
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: This library determines the set of environment variables for a service component
129
+ in the SOAR architecture
130
+ test_files: []