arisu 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +42 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +88 -0
- data/README.md +56 -0
- data/Rakefile +4 -0
- data/arisu.gemspec +33 -0
- data/exe/arisu +5 -0
- data/lib/arisu/cli.rb +20 -0
- data/lib/arisu/dotenv_inject.rb +11 -0
- data/lib/arisu/load.rb +5 -0
- data/lib/arisu/version.rb +5 -0
- data/lib/arisu.rb +76 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3dd3f1428c5671f8980f1fc196eb63bf872ed81c91c0a2a4a96f05a999cd4e0a
|
4
|
+
data.tar.gz: 2fbf056506686d8224a38790aee730d99377792d0f007400ddb7bdac1fb856ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79509aea9a0b6233494eba7a781c97506d655399a7df8dda2c42d3c45bfce4c6c725adadcc976bf9c033db522ba288e56a5177740248b2a601226b4a3713801f
|
7
|
+
data.tar.gz: 0aefe35bceb2054269d9a0e87f96e70216ed2426c2948cf13cecaf7df5197df66ac0247190e9c463d3296d7b7ecceb43cff9a92cde1dbc0378a2cefd62caf67c
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Max: 170
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Max: 250
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 1000
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 70
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 100
|
18
|
+
|
19
|
+
Metrics/ModuleLength:
|
20
|
+
Max: 1000
|
21
|
+
|
22
|
+
Metrics/ParameterLists:
|
23
|
+
Max: 50
|
24
|
+
|
25
|
+
Metrics/PerceivedComplexity:
|
26
|
+
Max: 80
|
27
|
+
|
28
|
+
Layout/SpaceInsideBlockBraces:
|
29
|
+
EnforcedStyle: no_space
|
30
|
+
SpaceBeforeBlockParameters: false
|
31
|
+
|
32
|
+
Style/Documentation:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/NumericPredicate:
|
36
|
+
EnforcedStyle: comparison
|
37
|
+
|
38
|
+
Style/MultilineBlockChain:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/SpecialGlobalVars:
|
42
|
+
EnforcedStyle: use_perl_names
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
arisu (1.0.0)
|
5
|
+
dotenv
|
6
|
+
google-cloud-secret_manager
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.1)
|
12
|
+
public_suffix (>= 2.0.2, < 6.0)
|
13
|
+
dotenv (2.8.1)
|
14
|
+
faraday (2.6.0)
|
15
|
+
faraday-net_http (>= 2.0, < 3.1)
|
16
|
+
ruby2_keywords (>= 0.0.4)
|
17
|
+
faraday-net_http (3.0.1)
|
18
|
+
faraday-retry (2.0.0)
|
19
|
+
faraday (~> 2.0)
|
20
|
+
gapic-common (0.13.0)
|
21
|
+
faraday (>= 1.9, < 3.a)
|
22
|
+
faraday-retry (>= 1.0, < 3.a)
|
23
|
+
google-protobuf (~> 3.14)
|
24
|
+
googleapis-common-protos (>= 1.3.12, < 2.a)
|
25
|
+
googleapis-common-protos-types (>= 1.3.1, < 2.a)
|
26
|
+
googleauth (~> 1.0)
|
27
|
+
grpc (~> 1.36)
|
28
|
+
google-cloud-core (1.6.0)
|
29
|
+
google-cloud-env (~> 1.0)
|
30
|
+
google-cloud-errors (~> 1.0)
|
31
|
+
google-cloud-env (1.6.0)
|
32
|
+
faraday (>= 0.17.3, < 3.0)
|
33
|
+
google-cloud-errors (1.3.0)
|
34
|
+
google-cloud-secret_manager (1.2.0)
|
35
|
+
google-cloud-core (~> 1.6)
|
36
|
+
google-cloud-secret_manager-v1 (>= 0.1, < 2.a)
|
37
|
+
google-cloud-secret_manager-v1beta1 (>= 0.3, < 2.a)
|
38
|
+
google-cloud-secret_manager-v1 (0.14.0)
|
39
|
+
gapic-common (>= 0.10, < 2.a)
|
40
|
+
google-cloud-errors (~> 1.0)
|
41
|
+
grpc-google-iam-v1 (~> 1.1)
|
42
|
+
google-cloud-secret_manager-v1beta1 (0.10.0)
|
43
|
+
gapic-common (>= 0.10, < 2.a)
|
44
|
+
google-cloud-errors (~> 1.0)
|
45
|
+
grpc-google-iam-v1 (~> 1.1)
|
46
|
+
google-protobuf (3.21.9)
|
47
|
+
googleapis-common-protos (1.3.12)
|
48
|
+
google-protobuf (~> 3.14)
|
49
|
+
googleapis-common-protos-types (~> 1.2)
|
50
|
+
grpc (~> 1.27)
|
51
|
+
googleapis-common-protos-types (1.4.0)
|
52
|
+
google-protobuf (~> 3.14)
|
53
|
+
googleauth (1.3.0)
|
54
|
+
faraday (>= 0.17.3, < 3.a)
|
55
|
+
jwt (>= 1.4, < 3.0)
|
56
|
+
memoist (~> 0.16)
|
57
|
+
multi_json (~> 1.11)
|
58
|
+
os (>= 0.9, < 2.0)
|
59
|
+
signet (>= 0.16, < 2.a)
|
60
|
+
grpc (1.50.0)
|
61
|
+
google-protobuf (~> 3.21)
|
62
|
+
googleapis-common-protos-types (~> 1.0)
|
63
|
+
grpc-google-iam-v1 (1.2.0)
|
64
|
+
google-protobuf (~> 3.14)
|
65
|
+
googleapis-common-protos (>= 1.3.12, < 2.0)
|
66
|
+
grpc (~> 1.27)
|
67
|
+
jwt (2.5.0)
|
68
|
+
memoist (0.16.2)
|
69
|
+
multi_json (1.15.0)
|
70
|
+
os (1.1.4)
|
71
|
+
public_suffix (5.0.0)
|
72
|
+
rake (13.0.6)
|
73
|
+
ruby2_keywords (0.0.5)
|
74
|
+
signet (0.17.0)
|
75
|
+
addressable (~> 2.8)
|
76
|
+
faraday (>= 0.17.5, < 3.a)
|
77
|
+
jwt (>= 1.5, < 3.0)
|
78
|
+
multi_json (~> 1.10)
|
79
|
+
|
80
|
+
PLATFORMS
|
81
|
+
arm64-darwin-22
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
arisu!
|
85
|
+
rake
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
2.4.0.dev
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Arisu
|
2
|
+
|
3
|
+
私が思っていたよりも…この世界には、素敵な魔法が溢れているんですね
|
4
|
+
|
5
|
+
Dotenv files integrated with google-cloud-secret_manager.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add arisu
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install arisu
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Create .env file with a format shown below.
|
20
|
+
|
21
|
+
```
|
22
|
+
DB_PASSWORD=:arisu:db-password:
|
23
|
+
# signature ^^^^^
|
24
|
+
# ^^^^^^^^^^^ secret name
|
25
|
+
|
26
|
+
DB_PASSWORD=:arisu:db-password:latest:
|
27
|
+
# ^^^^^^ version (optional)
|
28
|
+
|
29
|
+
DB_PASSWORD=:arisu:to-you-for-me:db-password:latest:
|
30
|
+
# ^^^^^^^^^^^^^ project ID (optional)
|
31
|
+
```
|
32
|
+
|
33
|
+
You can load this .env file by calling `Arisu.load` or loading `arisu/load`.
|
34
|
+
|
35
|
+
The usage of this library is similar to Dotenv. Please refer to the documentation of Dotenv.
|
36
|
+
|
37
|
+
### Google Cloud Secret Manager Configuration
|
38
|
+
|
39
|
+
Arisu requires configuration of Google Cloud Secret Manager.
|
40
|
+
|
41
|
+
You can configure it by adding one of these environment variables:
|
42
|
+
`GOOGLE_CLOUD_CREDENTIALS`, `GOOGLE_CLOUD_KEYFILE`, `GCLOUD_KEYFILE`, `GOOGLE_CLOUD_CREDENTIALS_JSON`, `GOOGLE_CLOUD_KEYFILE_JSON`, `GCLOUD_KEYFILE_JSON`.
|
43
|
+
|
44
|
+
You can specify default project ID by setting `GOOGLE_CLOUD_PROJECT`.
|
45
|
+
|
46
|
+
These environment variables can be set also in .env files.
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
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).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Ishotihadus/arisu.
|
data/Rakefile
ADDED
data/arisu.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/arisu/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'arisu'
|
7
|
+
spec.version = Arisu::VERSION
|
8
|
+
spec.authors = ['Ishotihadus']
|
9
|
+
spec.email = ['hanachan.pao@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Dotenv with google-cloud-secret_manager'
|
12
|
+
spec.description = 'Dotenv with google-cloud-secret_manager'
|
13
|
+
spec.homepage = 'https://github.com/Ishotihadus/arisu'
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) {|f| File.basename(f)}
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'dotenv'
|
31
|
+
spec.add_dependency 'google-cloud-secret_manager'
|
32
|
+
spec.add_development_dependency 'rake'
|
33
|
+
end
|
data/exe/arisu
ADDED
data/lib/arisu/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'arisu'
|
4
|
+
require 'dotenv/cli'
|
5
|
+
|
6
|
+
module Arisu
|
7
|
+
class CLI < Dotenv::CLI
|
8
|
+
def run
|
9
|
+
if @overload
|
10
|
+
Arisu.overload!(*@filenames)
|
11
|
+
else
|
12
|
+
Arisu.load!(*@filenames)
|
13
|
+
end
|
14
|
+
rescue Errno::ENOENT => e
|
15
|
+
abort e.message
|
16
|
+
else
|
17
|
+
exec(*@argv) unless @argv.empty?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/arisu/load.rb
ADDED
data/lib/arisu.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dotenv'
|
4
|
+
require 'google-cloud-secret_manager'
|
5
|
+
require_relative 'arisu/dotenv_inject'
|
6
|
+
require_relative 'arisu/version'
|
7
|
+
|
8
|
+
module Arisu
|
9
|
+
GCP_ENV_KEYS = %w[
|
10
|
+
GOOGLE_CLOUD_PROJECT
|
11
|
+
GOOGLE_CLOUD_CREDENTIALS
|
12
|
+
GOOGLE_CLOUD_KEYFILE
|
13
|
+
GCLOUD_KEYFILE
|
14
|
+
GOOGLE_CLOUD_CREDENTIALS_JSON
|
15
|
+
GOOGLE_CLOUD_KEYFILE_JSON
|
16
|
+
GCLOUD_KEYFILE_JSON
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def load(*filenames, secret_manager: nil, project_id: nil)
|
21
|
+
env = Dotenv.parse(*filenames)
|
22
|
+
GCP_ENV_KEYS.each {|e| ENV[e] ||= env[e] if env.key?(e)}
|
23
|
+
decrypt!(env, secret_manager: secret_manager, project_id: project_id)
|
24
|
+
env.each {|k, v| ENV[k] ||= v}
|
25
|
+
end
|
26
|
+
|
27
|
+
def load!(*filenames, secret_manager: nil, project_id: nil)
|
28
|
+
env = Dotenv.parse!(*filenames)
|
29
|
+
GCP_ENV_KEYS.each {|e| ENV[e] ||= env[e] if env.key?(e)}
|
30
|
+
decrypt!(env, secret_manager: secret_manager, project_id: project_id)
|
31
|
+
env.each {|k, v| ENV[k] ||= v}
|
32
|
+
end
|
33
|
+
|
34
|
+
def overload(*filenames, secret_manager: nil, project_id: nil)
|
35
|
+
env = Dotenv.parse(*filenames)
|
36
|
+
GCP_ENV_KEYS.each {|e| ENV[e] = env[e] if env.key?(e)}
|
37
|
+
decrypt!(env, secret_manager: secret_manager, project_id: project_id)
|
38
|
+
env.each {|k, v| ENV[k] = v}
|
39
|
+
end
|
40
|
+
|
41
|
+
def overload!(*filenames, secret_manager: nil, project_id: nil)
|
42
|
+
env = Dotenv.parse!(*filenames)
|
43
|
+
GCP_ENV_KEYS.each {|e| ENV[e] = env[e] if env.key?(e)}
|
44
|
+
decrypt!(env, secret_manager: secret_manager, project_id: project_id)
|
45
|
+
env.each {|k, v| ENV[k] = v}
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def decrypt!(env, secret_manager: nil, project_id: nil)
|
51
|
+
secret_manager ||= Google::Cloud::SecretManager.secret_manager_service
|
52
|
+
project_id ||= ENV['GOOGLE_CLOUD_PROJECT']
|
53
|
+
|
54
|
+
env.transform_values! do |v|
|
55
|
+
next v unless v.size >= 9 && v[0, 7] == ':arisu:' && v[-1] == ':'
|
56
|
+
|
57
|
+
_empty, _arisu, this_project_id, key, version = v.split(':')
|
58
|
+
|
59
|
+
unless version
|
60
|
+
version = key
|
61
|
+
key = this_project_id
|
62
|
+
this_project_id = project_id
|
63
|
+
end
|
64
|
+
|
65
|
+
raise 'project ID not specified' if !this_project_id || this_project_id.empty?
|
66
|
+
|
67
|
+
name = secret_manager.secret_version_path(
|
68
|
+
project: this_project_id,
|
69
|
+
secret: key,
|
70
|
+
secret_version: version || 'latest'
|
71
|
+
)
|
72
|
+
secret_manager.access_secret_version(name: name).payload.data
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arisu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ishotihadus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dotenv
|
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: google-cloud-secret_manager
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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
|
+
description: Dotenv with google-cloud-secret_manager
|
56
|
+
email:
|
57
|
+
- hanachan.pao@gmail.com
|
58
|
+
executables:
|
59
|
+
- arisu
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- arisu.gemspec
|
69
|
+
- exe/arisu
|
70
|
+
- lib/arisu.rb
|
71
|
+
- lib/arisu/cli.rb
|
72
|
+
- lib/arisu/dotenv_inject.rb
|
73
|
+
- lib/arisu/load.rb
|
74
|
+
- lib/arisu/version.rb
|
75
|
+
homepage: https://github.com/Ishotihadus/arisu
|
76
|
+
licenses: []
|
77
|
+
metadata:
|
78
|
+
homepage_uri: https://github.com/Ishotihadus/arisu
|
79
|
+
source_code_uri: https://github.com/Ishotihadus/arisu
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.6.0
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.4.0.dev
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Dotenv with google-cloud-secret_manager
|
99
|
+
test_files: []
|