envkeeper 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.rubocop_todo.yml +27 -0
- data/.ruby-version +1 -0
- data/.vscode/settings.json +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +87 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +20 -0
- data/ext/envkeeper/README.md +32 -0
- data/ext/envkeeper/envkeeper.c +117 -0
- data/ext/envkeeper/envkeeper.h +6 -0
- data/ext/envkeeper/extconf.rb +5 -0
- data/lib/envkeeper/auth.rb +66 -0
- data/lib/envkeeper/git.rb +35 -0
- data/lib/envkeeper/http.rb +33 -0
- data/lib/envkeeper/tasks.rake +27 -0
- data/lib/envkeeper/version.rb +5 -0
- data/lib/envkeeper.rb +18 -0
- data/sig/envkeeper.rbs +4 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88c115b6bc9a710fbfea8af0ed0c4d3fc62d220030bf43400f0b476dd7881700
|
4
|
+
data.tar.gz: 986dfe0eab486208e696ee06a451606dc0ca72ed6c8afb70a0917be3d66e6170
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89e5120edce7128d3b3f4326a0adbe56a6ae0d5618215242488bc8f18e1e3d0f53a1ac3b817d8e6e4289f9767755591ee23a581f69add44a0997ae56f8a9b46b
|
7
|
+
data.tar.gz: b7deff6c47008a3cc15c8bf596ee6e2e39cd6270e952db96a996a41e024bb35a36159a864bf64afb9e52f9ee3607ba3c1a1ecefe10ee2141840ae2682f4cc7f5
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.6
|
5
|
+
NewCops: enable
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: single_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Layout/LineLength:
|
16
|
+
Max: 120
|
17
|
+
|
18
|
+
Style/GlobalStdStream:
|
19
|
+
Exclude:
|
20
|
+
- spec/spec_helper.rb
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-12-23 17:13:28 UTC using RuboCop version 1.40.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
# This cop supports safe autocorrection (--autocorrect).
|
11
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
|
12
|
+
# URISchemes: http, https
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 133
|
15
|
+
|
16
|
+
# Offense count: 5
|
17
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
|
18
|
+
# AllowedMethods: refine
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Max: 102
|
21
|
+
|
22
|
+
# Offense count: 3
|
23
|
+
# This cop supports safe autocorrection (--autocorrect).
|
24
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
|
25
|
+
# URISchemes: http, https
|
26
|
+
Layout/LineLength:
|
27
|
+
Max: 133
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at d.laloush@outlook.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in envkeeper.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'rake-compiler'
|
11
|
+
|
12
|
+
gem 'rspec', '~> 3.0'
|
13
|
+
|
14
|
+
gem 'rubocop', '~> 1.21'
|
15
|
+
|
16
|
+
gem 'pry', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
envkeeper (0.1.0)
|
5
|
+
io-console (~> 0.5.11)
|
6
|
+
jwt (~> 2.5)
|
7
|
+
macaddr (~> 1.7)
|
8
|
+
openssl (~> 3.0)
|
9
|
+
websocket-eventmachine-client (~> 1.3)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
ast (2.4.2)
|
15
|
+
coderay (1.1.3)
|
16
|
+
diff-lcs (1.5.0)
|
17
|
+
eventmachine (1.2.7)
|
18
|
+
io-console (0.5.11)
|
19
|
+
json (2.6.3)
|
20
|
+
jwt (2.6.0)
|
21
|
+
macaddr (1.7.2)
|
22
|
+
systemu (~> 2.6.5)
|
23
|
+
method_source (1.0.0)
|
24
|
+
openssl (3.1.0)
|
25
|
+
parallel (1.22.1)
|
26
|
+
parser (3.1.3.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
pry (0.14.1)
|
29
|
+
coderay (~> 1.1)
|
30
|
+
method_source (~> 1.0)
|
31
|
+
rainbow (3.1.1)
|
32
|
+
rake (13.0.6)
|
33
|
+
rake-compiler (1.2.0)
|
34
|
+
rake
|
35
|
+
regexp_parser (2.6.1)
|
36
|
+
rexml (3.2.5)
|
37
|
+
rspec (3.12.0)
|
38
|
+
rspec-core (~> 3.12.0)
|
39
|
+
rspec-expectations (~> 3.12.0)
|
40
|
+
rspec-mocks (~> 3.12.0)
|
41
|
+
rspec-core (3.12.0)
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-expectations (3.12.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.12.0)
|
46
|
+
rspec-mocks (3.12.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.12.0)
|
49
|
+
rspec-support (3.12.0)
|
50
|
+
rubocop (1.40.0)
|
51
|
+
json (~> 2.3)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 3.1.2.1)
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
|
+
rexml (>= 3.2.5, < 4.0)
|
57
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
+
rubocop-ast (1.24.0)
|
61
|
+
parser (>= 3.1.1.0)
|
62
|
+
ruby-progressbar (1.11.0)
|
63
|
+
systemu (2.6.5)
|
64
|
+
unicode-display_width (2.3.0)
|
65
|
+
websocket (1.2.9)
|
66
|
+
websocket-eventmachine-base (1.2.0)
|
67
|
+
eventmachine (~> 1.0)
|
68
|
+
websocket (~> 1.0)
|
69
|
+
websocket-native (~> 1.0)
|
70
|
+
websocket-eventmachine-client (1.3.0)
|
71
|
+
websocket-eventmachine-base (~> 1.0)
|
72
|
+
websocket-native (1.0.0)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
x86_64-linux
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
envkeeper!
|
80
|
+
pry
|
81
|
+
rake (~> 13.0)
|
82
|
+
rake-compiler
|
83
|
+
rspec (~> 3.0)
|
84
|
+
rubocop (~> 1.21)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.3.25
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Daniel Laloush
|
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,37 @@
|
|
1
|
+
# Envkeeper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/envkeeper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add envkeeper
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install envkeeper
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/envkeeper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/envkeeper/blob/main/CODE_OF_CONDUCT.md).
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
34
|
+
|
35
|
+
## Code of Conduct
|
36
|
+
|
37
|
+
Everyone interacting in the Envkeeper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/envkeeper/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
require 'rake/extensiontask'
|
13
|
+
|
14
|
+
task build: :compile
|
15
|
+
|
16
|
+
Rake::ExtensionTask.new('envkeeper') do |ext|
|
17
|
+
ext.lib_dir = 'lib/envkeeper'
|
18
|
+
end
|
19
|
+
|
20
|
+
task default: %i[clobber compile spec rubocop]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
C extension for Ruby that defines several functions that manipulate Ruby values such as strings, arrays, and objects.
|
2
|
+
|
3
|
+
The `rb_mEnvkeeper` and `rb_mIO` variables are Ruby module values that are initialized with the `rb_define_module` function. The `rb_cSTDOUT` variable is a Ruby class value that is initialized with the `rb_define_class` function.
|
4
|
+
|
5
|
+
The `set_env_variable` function takes a C string and a Ruby string value as arguments, concatenates them with an equal sign (=) in between, and then sets the resulting string as an environment variable using the `putenv` function.
|
6
|
+
|
7
|
+
The `rb_class_or_module_name_p` function checks if the given Ruby object is either a class or a module and returns a non-zero value if it is, or zero otherwise.
|
8
|
+
|
9
|
+
The `gsub_rb_str` function calls the `gsub` method on the given Ruby string value, passing it two arguments: the value of the `$env_io_secrets` global variable, and the string "•••••".
|
10
|
+
|
11
|
+
The `gsub_array` macro expands to a call to the `gsub_array_impl` function, passing it three arguments: the given array value, the `self` object, and the value `Qnil`.
|
12
|
+
|
13
|
+
The `gsub_array_impl` function loops through the elements of the given array value, and for each element that is either a string or an array, it calls either the `gsub_rb_str` or the `gsub_array_impl` function on it, respectively. For all other types of elements, it calls the `gsub_argv` function on them, passing it the `self` object as an argument.
|
14
|
+
|
15
|
+
The `gsub_object` function first checks if the given object responds to the `to_ary` method. If it does and the method returns a non-nil value, the function calls the `gsub_array` function on the returned value. Otherwise, it calls the `to_s` method on the object and, if the method returns a nil or a false value, it calls the `rb_obj_as_string` function on the object. Finally, it calls the `gsub_rb_str` function on the result.
|
16
|
+
|
17
|
+
The `gsub_argv` function allocates memory for an array of Ruby values on the heap using the `malloc` function, then loops through the elements of the given `argv` array and calls the `gsub_object` function on each element, passing it the `self` object as an argument. The function returns a pointer to the resulting array.
|
18
|
+
|
19
|
+
The `env_keeper_exec` function takes a Ruby string value as an argument and calls the `system` function on it, passing it the concatenated value of the `argv` global variable and the given string as arguments.
|
20
|
+
|
21
|
+
The `env_keeper_spawn` function is similar to the `env_keeper_exec` function, but it calls the `spawn` function instead of the `system` function.
|
22
|
+
|
23
|
+
The `env_keeper_popen` function takes a Ruby string value as an argument and calls the `popen` function on it, passing it the concatenated value of the `argv` global variable and the given string as arguments.
|
24
|
+
|
25
|
+
The `Init_envkeeper` function defines several Ruby methods that can be called from Ruby code. It defines the `exec`, `spawn`, and `popen` methods on the `rb_mEnvkeeper` module, and the `popen` method on the `rb_mIO` module. It also defines the `puts` method on the `rb_cSTDOUT` class.
|
26
|
+
|
27
|
+
The `rb_env_keeper_exec` and `rb_env_keeper_spawn` functions are called when the `exec` and `spawn` methods are called from Ruby code, respectively. They take a variable number of arguments, and pass them to the `env_keeper_exec` and `env_keeper_spawn` functions, respectively, after calling the `gsub_argv` function on them.
|
28
|
+
|
29
|
+
The `rb_env_keeper_popen` function is called when the `popen` method is called from Ruby code. It takes a variable number of arguments, and passes them to the `env_keeper_popen` function after calling the `gsub_argv` function on them.
|
30
|
+
|
31
|
+
The `rb_env_keeper_puts` function is called when the `puts` method is called from Ruby code. It takes a variable number of arguments, and prints them to the standard output after calling the `gsub_object` function on each argument.
|
32
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#include "envkeeper.h"
|
2
|
+
|
3
|
+
#include "ruby.h"
|
4
|
+
#include "ruby/encoding.h"
|
5
|
+
#include "ruby/ractor.h"
|
6
|
+
|
7
|
+
VALUE rb_mEnvkeeper, rb_mIO, rb_cSTDOUT;
|
8
|
+
|
9
|
+
const char *env_secret_key = "ENV_SECRETS";
|
10
|
+
|
11
|
+
static VALUE *gsub_argv(int argc, VALUE *argv, VALUE self);
|
12
|
+
|
13
|
+
#define gsub_array(array, self, ...) \
|
14
|
+
gsub_array_impl(array, self, Qnil)
|
15
|
+
|
16
|
+
void set_env_variable(const char *c_str, VALUE rb_str) {
|
17
|
+
char *concatenated_string = malloc(strlen(c_str) + strlen(RSTRING_PTR(rb_str)) + 2);
|
18
|
+
sprintf(concatenated_string, "%s=%s", c_str, RSTRING_PTR(rb_str));
|
19
|
+
|
20
|
+
putenv(concatenated_string);
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE gsub_rb_str(VALUE str, VALUE self) {
|
24
|
+
if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
|
25
|
+
return str;
|
26
|
+
}
|
27
|
+
VALUE secrets = rb_gv_get("$env_io_secrets");
|
28
|
+
return rb_funcall(str, rb_intern("gsub"), 2, secrets, rb_str_new_cstr("*****"));
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE gsub_array_impl(VALUE array, VALUE self, VALUE seen_objects) {
|
32
|
+
if (seen_objects == Qnil) {
|
33
|
+
seen_objects = rb_hash_new();
|
34
|
+
}
|
35
|
+
if (rb_hash_aref(seen_objects, array) == Qtrue) {
|
36
|
+
return rb_str_new_cstr("[...]");
|
37
|
+
}
|
38
|
+
rb_hash_aset(seen_objects, array, Qtrue);
|
39
|
+
VALUE *array_values = RARRAY_PTR(array);
|
40
|
+
|
41
|
+
long array_size = RARRAY_LEN(array);
|
42
|
+
VALUE *gsubbed_array = malloc(array_size * sizeof(VALUE));
|
43
|
+
for (int j = 0; j < array_size; j++) {
|
44
|
+
if (RB_TYPE_P(array_values[j], T_ARRAY)) {
|
45
|
+
gsubbed_array[j] = gsub_array_impl(array_values[j], self, seen_objects);
|
46
|
+
} else if (RB_TYPE_P(array_values[j], T_STRING)) {
|
47
|
+
gsubbed_array[j] = gsub_rb_str(array_values[j], self);
|
48
|
+
} else {
|
49
|
+
VALUE *tmp_argv = gsub_argv(1, &array_values[j], self);
|
50
|
+
gsubbed_array[j] = *tmp_argv;
|
51
|
+
free(tmp_argv);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
VALUE result = rb_ary_new4(array_size, gsubbed_array);
|
55
|
+
free(gsubbed_array);
|
56
|
+
return result;
|
57
|
+
}
|
58
|
+
|
59
|
+
static VALUE gsub_object(VALUE obj, VALUE self) {
|
60
|
+
if (rb_respond_to(obj, rb_intern("to_ary"))) {
|
61
|
+
VALUE array = rb_funcall(obj, rb_intern("to_ary"), 0);
|
62
|
+
if (!NIL_P(array)) {
|
63
|
+
return gsub_array(array, self);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
VALUE str = rb_funcall(obj, rb_intern("to_s"), 0);
|
67
|
+
if (NIL_P(str) || str == Qfalse) {
|
68
|
+
str = rb_obj_as_string(obj);
|
69
|
+
}
|
70
|
+
return gsub_rb_str(str, self);
|
71
|
+
}
|
72
|
+
|
73
|
+
static VALUE *gsub_argv(int argc, VALUE *argv, VALUE self) {
|
74
|
+
VALUE *tmp_argv = malloc(argc * sizeof(VALUE));
|
75
|
+
|
76
|
+
for (int i = 0; i < argc; i++) {
|
77
|
+
VALUE gsubbed_str;
|
78
|
+
if (RB_TYPE_P(argv[i], T_STRING)) {
|
79
|
+
gsubbed_str = gsub_rb_str(argv[i], self);
|
80
|
+
} else if (RB_TYPE_P(argv[i], T_ARRAY)) {
|
81
|
+
gsubbed_str = gsub_array(argv[i], self);
|
82
|
+
} else {
|
83
|
+
gsubbed_str = gsub_object(argv[i], self);
|
84
|
+
}
|
85
|
+
tmp_argv[i] = gsubbed_str;
|
86
|
+
}
|
87
|
+
|
88
|
+
return tmp_argv;
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE rb_env_sub_m(int argc, VALUE *argv, VALUE self) {
|
92
|
+
VALUE *tmp_argv = gsub_argv(argc, argv, self);
|
93
|
+
return rb_ary_new4(argc, tmp_argv);
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE rb_env_create_io_methods_m(int argc, VALUE *argv, VALUE self) {
|
97
|
+
VALUE secrets, join_argv[1], line, regex;
|
98
|
+
|
99
|
+
rb_scan_args(argc, argv, "1", &secrets);
|
100
|
+
|
101
|
+
join_argv[0] = rb_str_new_cstr(")|(");
|
102
|
+
line = rb_funcallv(rb_ary_push(secrets, rb_str_new_cstr(env_secret_key)), rb_intern("join"), 1, join_argv);
|
103
|
+
regex = rb_reg_new_str(rb_sprintf("(%" PRIsVALUE ")", line), 1);
|
104
|
+
|
105
|
+
rb_gv_set("$env_io_secrets", regex);
|
106
|
+
set_env_variable(env_secret_key, line);
|
107
|
+
|
108
|
+
rb_define_module_function(rb_mEnvkeeper, "gsub_args", rb_env_sub_m, -1);
|
109
|
+
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
|
113
|
+
void Init_envkeeper(void) {
|
114
|
+
rb_mEnvkeeper = rb_define_module("Envkeeper");
|
115
|
+
|
116
|
+
rb_define_module_function(rb_mEnvkeeper, "create_io_methods", rb_env_create_io_methods_m, -1);
|
117
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'io/console'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'openssl'
|
8
|
+
require 'tempfile'
|
9
|
+
require 'macaddr'
|
10
|
+
require 'fiddle/import'
|
11
|
+
|
12
|
+
module Envkeeper
|
13
|
+
module Auth
|
14
|
+
REQUEST_URI = 'https://app.envkeeper.dev/'
|
15
|
+
REQUEST_PSOUDOCODE_PATH = '/api/v1/client/users/sign_in/new'
|
16
|
+
class Error < StandardError; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def login!
|
20
|
+
eval(Marshal.load(psoudo_code_request.body))
|
21
|
+
end
|
22
|
+
|
23
|
+
def psoudo_code_request
|
24
|
+
@psoudo_code_request ||= Envkeeper::HTTP.get(
|
25
|
+
path: REQUEST_PSOUDOCODE_PATH
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# def capture_stderr
|
33
|
+
# real_stderr, $stderr = $stderr, StringIO.new
|
34
|
+
# yield
|
35
|
+
# binding.pry
|
36
|
+
# $stderr.string
|
37
|
+
# ensure
|
38
|
+
# $stderr = real_stderr
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def read_stdout(&block)
|
42
|
+
# tmp = $stdout
|
43
|
+
# $stdout = Banana.new
|
44
|
+
# block.call
|
45
|
+
# ENV.each do |env|
|
46
|
+
# $stdout.string.gsub!(/.{4,}/) do |w|
|
47
|
+
# ENV_SUB.include?(w) ? '****' : w
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
# tmp.puts $stdout.string
|
51
|
+
# ensure
|
52
|
+
# $stdout = tmp # ensures that always evaluated
|
53
|
+
# end
|
54
|
+
|
55
|
+
ENV['SOMETHING'] = 'test1'
|
56
|
+
|
57
|
+
module ::Talks
|
58
|
+
def self.puts(args)
|
59
|
+
p 'banna'
|
60
|
+
super(args)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module ::Kernel
|
65
|
+
include Talks
|
66
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Envkeeper
|
4
|
+
def self.git_remote_list
|
5
|
+
@git_remote_list ||= Git.new.remote_list
|
6
|
+
end
|
7
|
+
|
8
|
+
class Git
|
9
|
+
def remote_list
|
10
|
+
git_remote_fetch_list.compact
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def git_remote_fetch_list
|
16
|
+
raw_remote_list.map do |remote|
|
17
|
+
remote.gsub!(' (fetch)', '').split("\t")[1] if remote.include?('fetch')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def raw_remote_list
|
22
|
+
Dir.chdir(execution_path) do
|
23
|
+
`#{git_remote_command}`
|
24
|
+
end.split("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def execution_path
|
28
|
+
Dir.pwd
|
29
|
+
end
|
30
|
+
|
31
|
+
def git_remote_command
|
32
|
+
'git remote -v'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Envkeeper
|
4
|
+
class HTTP
|
5
|
+
class << self
|
6
|
+
def get(path:, body: nil, headers: {})
|
7
|
+
request = Net::HTTP::Get.new(path)
|
8
|
+
headers.each { |header| request[header] = headers[header] }
|
9
|
+
request.set_form_data(body) if body
|
10
|
+
http_request.start { |http| http.request(request) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
REQUEST_URI = 'https://envkeeper.dev/'
|
16
|
+
|
17
|
+
def uri
|
18
|
+
URI(REQUEST_URI)
|
19
|
+
end
|
20
|
+
|
21
|
+
def http_request
|
22
|
+
@http_request ||= create_new_http_request
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_new_http_request
|
26
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
+
http.use_ssl = true
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
29
|
+
http
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rake::TaskManager.class_eval do
|
4
|
+
def alias_task(fq_name)
|
5
|
+
new_name = "#{fq_name}:original"
|
6
|
+
@tasks[new_name] = @tasks.delete(fq_name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def alias_task(fq_name)
|
11
|
+
Rake.application.alias_task(fq_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def override_task(*args, &block)
|
15
|
+
name, _params, _deps = Rake.application.resolve_args(args.dup)
|
16
|
+
fq_name = Rake.application.instance_variable_get(:@scope).to_a.reverse.push(name).join(':')
|
17
|
+
alias_task(fq_name)
|
18
|
+
Rake::Task.define_task(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
override_task :c do
|
22
|
+
Rake::Task['console'].invoke
|
23
|
+
end
|
24
|
+
|
25
|
+
override_task :console do
|
26
|
+
Rake::Task['console'].invoke
|
27
|
+
end
|
data/lib/envkeeper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'envkeeper/version'
|
4
|
+
require_relative 'envkeeper/envkeeper'
|
5
|
+
require_relative 'envkeeper/auth'
|
6
|
+
require_relative 'envkeeper/http'
|
7
|
+
|
8
|
+
module Envkeeper
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def call
|
13
|
+
Envkeeper::Auth.login!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Envkeeper.call
|
data/sig/envkeeper.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envkeeper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Laloush
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: io-console
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.11
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.11
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: macaddr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: openssl
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
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: websocket-eventmachine-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
description: Connects with envkeeper servers and serve all the allowed enviroments
|
84
|
+
variable per user
|
85
|
+
email:
|
86
|
+
- d.laloush@outlook.com
|
87
|
+
executables: []
|
88
|
+
extensions:
|
89
|
+
- ext/envkeeper/extconf.rb
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".rubocop_todo.yml"
|
95
|
+
- ".ruby-version"
|
96
|
+
- ".vscode/settings.json"
|
97
|
+
- CHANGELOG.md
|
98
|
+
- CODE_OF_CONDUCT.md
|
99
|
+
- Gemfile
|
100
|
+
- Gemfile.lock
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- ext/envkeeper/README.md
|
105
|
+
- ext/envkeeper/envkeeper.c
|
106
|
+
- ext/envkeeper/envkeeper.h
|
107
|
+
- ext/envkeeper/extconf.rb
|
108
|
+
- lib/envkeeper.rb
|
109
|
+
- lib/envkeeper/auth.rb
|
110
|
+
- lib/envkeeper/git.rb
|
111
|
+
- lib/envkeeper/http.rb
|
112
|
+
- lib/envkeeper/tasks.rake
|
113
|
+
- lib/envkeeper/version.rb
|
114
|
+
- sig/envkeeper.rbs
|
115
|
+
homepage: https://envkeeper.com
|
116
|
+
licenses:
|
117
|
+
- Nonstandard
|
118
|
+
metadata:
|
119
|
+
homepage_uri: https://envkeeper.com
|
120
|
+
rubygems_mfa_required: 'true'
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 2.6.0
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.3.15
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Provide a secure way to share enviroments variable
|
140
|
+
test_files: []
|