wonder_credentials 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c53716ea4a4658a5f5c6b512227ea867061e0d1df1ddd8afa9ad486a17469699
4
+ data.tar.gz: d3324c6a4f222bbcbcbe707d8b000a535ffef88b05f79284d3e0019e384a8582
5
+ SHA512:
6
+ metadata.gz: 5b6118a1da01da108b5361d8a57ba933b372defe3783675d3909b215bfa6ef9d7fe7156ec4b9ca1e0d4ff1a4a74f3297b12bdff064114e85309f38738471da74
7
+ data.tar.gz: 470b8075eae90bd814c64d80dc7a26216359e16921724ab11a7c971fdf09e8d4ac6b653482bcb23db3a584949a87e195deadd63fe8ab6d622086663020fb4f92
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ inherit_gem:
2
+ wonder-ruby-style:
3
+ - presets/latest.yml
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at leonardo.falk@hotmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in wonder_oracle_database.gemspec
6
+ gemspec
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wonder_credentials (1.0.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ ast (2.4.0)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ docile (1.1.5)
19
+ i18n (1.1.0)
20
+ concurrent-ruby (~> 1.0)
21
+ json (2.1.0)
22
+ minitest (5.11.3)
23
+ parallel (1.12.1)
24
+ parser (2.5.0.5)
25
+ ast (~> 2.4.0)
26
+ powerpack (0.1.1)
27
+ rainbow (3.0.0)
28
+ rake (12.3.1)
29
+ rspec (3.7.0)
30
+ rspec-core (~> 3.7.0)
31
+ rspec-expectations (~> 3.7.0)
32
+ rspec-mocks (~> 3.7.0)
33
+ rspec-core (3.7.1)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-expectations (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-mocks (3.7.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-support (3.7.1)
42
+ rubocop (0.54.0)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.5)
45
+ powerpack (~> 0.1)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (~> 1.0, >= 1.0.1)
49
+ rubocop-rspec (1.25.1)
50
+ rubocop (>= 0.53.0)
51
+ ruby-progressbar (1.9.0)
52
+ simplecov (0.13.0)
53
+ docile (~> 1.1.0)
54
+ json (>= 1.8, < 3)
55
+ simplecov-html (~> 0.10.0)
56
+ simplecov-html (0.10.2)
57
+ thread_safe (0.3.6)
58
+ tzinfo (1.2.5)
59
+ thread_safe (~> 0.1)
60
+ unicode-display_width (1.3.0)
61
+ wonder-ruby-style (0.54.0)
62
+ rubocop (~> 0.49)
63
+ rubocop-rspec (~> 1.15)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler
70
+ rake
71
+ rspec
72
+ simplecov
73
+ wonder-ruby-style
74
+ wonder_credentials!
75
+
76
+ BUNDLED WITH
77
+ 1.16.5
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Leonardo Falk
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.
@@ -0,0 +1,112 @@
1
+ # Wonder Credentials
2
+
3
+ > Helpers para Rails Credentials API.
4
+
5
+ ## Instalação
6
+
7
+ Adicione essa linha ao Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wonder_credentials'
11
+ ```
12
+
13
+ Então execute:
14
+
15
+ $ bundle
16
+
17
+ ## Uso
18
+
19
+ Altere as credenciais do Rails, organizando-a por ambientes:
20
+
21
+ $ rails credentials:edit
22
+
23
+ ```yaml
24
+ # config/credentials.yml.enc
25
+
26
+ default: &default
27
+ AWS:
28
+ ACCESS_KEY_ID: &default_aws_access_key_id
29
+ "shared_access_key_value"
30
+ SECRET_ACCESS_KEY: &default_aws_secret_access_key
31
+ "shared_secrets"
32
+
33
+ REGION: &default_aws_region
34
+ "sa-east-1"
35
+
36
+ SQS_REGION: *default_aws_region
37
+ SNS_REGION: *default_aws_region
38
+
39
+ development:
40
+ <<: *default
41
+
42
+ test:
43
+ <<: *default
44
+
45
+ production:
46
+ <<: *default
47
+ AWS:
48
+ ACCESS_KEY_ID: "real_access_key"
49
+ SECRET_ACCESS_KEY: "real_secrets"
50
+ ```
51
+
52
+ Em development/test:
53
+
54
+ ```ruby
55
+ WonderCredentials.get('AWS.ACCESS_KEY_ID')
56
+ # => "shared_access_key_value"
57
+ ```
58
+
59
+ Em production:
60
+
61
+ ```ruby
62
+ WonderCredentials.get('AWS.ACCESS_KEY_ID')
63
+ # => "real_access_key"
64
+ ```
65
+
66
+ ##### Hash
67
+
68
+ ```ruby
69
+ credentials = WonderCredentials.get(
70
+ access_key_id: 'AWS.ACCESS_KEY_ID',
71
+ secret_access_key: 'AWS.SECRET_ACCESS_KEY',
72
+ region: 'AWS.REGION'
73
+ )
74
+ # => { access_key_id: 'shared_access_key_value', secret_access_key: 'shared_secrets', region: 'sa-east-1' }
75
+
76
+ Aws.configure(credentials)
77
+ ```
78
+
79
+ Também funciona em qualquer nível do hash.
80
+
81
+ ```ruby
82
+ WonderCredentials.get({ a: { b: { c: 'AWS.ACCESS_KEY_ID ' } } })
83
+ # => { a: { b: { c: 'shared_access_key_value' } } }
84
+
85
+ Aws.configure(credentials)
86
+ ```
87
+
88
+ ##### Array
89
+
90
+ ```ruby
91
+ WonderCredentials.get(['AWS.ACCESS_KEY_ID', 'AWS.SECRET_ACCESS_KEY'])
92
+
93
+ # => ['shared_access_key_value', 'shared_secrets']
94
+ ```
95
+
96
+ #### Fallback
97
+
98
+ ##### Environment
99
+
100
+ ```ruby
101
+ WonderCredentials.get('AWS.SQS_ACCESS_KEY_ID', env: true)
102
+
103
+ # => Credentials['AWS.SQS_ACCESS_KEY_ID'] ou ENV['AWS.SQS_ACCESS_KEY_ID'] ou null
104
+ ```
105
+
106
+ ##### Default Value
107
+
108
+ ```ruby
109
+ WonderCredentials.get('AWS.SQS_ACCESS_KEY_ID', env: true, default: 'key not found')
110
+
111
+ # => Credentials['AWS.SQS_ACCESS_KEY_ID'] ou ENV['AWS.SQS_ACCESS_KEY_ID'] ou 'key not found'
112
+ ```
@@ -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
@@ -0,0 +1,62 @@
1
+ require 'wonder_credentials/version'
2
+ require 'active_support/hash_with_indifferent_access'
3
+
4
+ class WonderCredentials
5
+ class << self
6
+ def get(path, options = {})
7
+ new(options).get(path)
8
+ end
9
+ end
10
+
11
+ def initialize(options = {})
12
+ @options = options.with_indifferent_access
13
+ @default_value = @options[:default]
14
+ @environment = @options[:env] || @options[:env_fallback] || false
15
+ end
16
+
17
+ def inspect
18
+
19
+ end
20
+
21
+ def get(path)
22
+ case path.class.name
23
+ when 'String', 'Symbol'
24
+ return get_string(path)
25
+ when 'Array'
26
+ return get_array(path)
27
+ when 'Hash', 'ActiveSupport::HashWithIndifferentAccess'
28
+ return get_hash(path)
29
+ else
30
+ raise "Unknown class name '#{path.class.name}' for WonderCredentials::Service#get, must be Array, Hash or String."
31
+
32
+ return nil
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def credentials
39
+ (::Rails.application.credentials[::Rails.env.to_sym] || {}).with_indifferent_access
40
+ end
41
+
42
+ def get_string(path)
43
+ value = nil
44
+ unless path.empty?
45
+ # com o path empty passaria a retornar todos os credentials
46
+ variable_path = path.to_s.split(/\./).collect(&:to_sym)
47
+ value = credentials
48
+ variable_path.each { |k| value = value.try(:[], k) }
49
+ end
50
+ value = ENV[path] if @environment && value.blank?
51
+ value = @default_value unless value
52
+ value
53
+ end
54
+
55
+ def get_array(path)
56
+ path.collect { |v| get(v) }
57
+ end
58
+
59
+ def get_hash(path)
60
+ path.collect { |k, v| { k => get(v) } }.reduce(&:merge)
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module WonderCredentials
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class WonderCredentials
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wonder_credentials/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wonder_credentials'
8
+ spec.version = WonderCredentials::VERSION
9
+ spec.authors = ['Wonder Sistemas']
10
+ spec.email = ['leonardo@wonder.com.br']
11
+
12
+ spec.summary = 'Wonder Sistemas\' helpers for Rails Credentials API.'
13
+ spec.description = 'Wonder Sistemas\' helpers for Rails Credentials API.'
14
+ spec.homepage = 'https://github.com/wondersistemas/wonder_credentials-ruby.git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'activesupport'
26
+
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'simplecov'
31
+ spec.add_development_dependency 'wonder-ruby-style'
32
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wonder_credentials
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wonder Sistemas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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
+ - !ruby/object:Gem::Dependency
84
+ name: wonder-ruby-style
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Wonder Sistemas' helpers for Rails Credentials API.
98
+ email:
99
+ - leonardo@wonder.com.br
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/wonder_credentials.rb
114
+ - lib/wonder_credentials/service.rb
115
+ - lib/wonder_credentials/version.rb
116
+ - wonder_credentials.gemspec
117
+ homepage: https://github.com/wondersistemas/wonder_credentials-ruby.git
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ allowed_push_host: https://rubygems.org
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.7
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Wonder Sistemas' helpers for Rails Credentials API.
142
+ test_files: []