drive_env 0.2.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e02eaa6173a06ac6d5bd70b14a3c140726492cc
4
- data.tar.gz: bf98f156864538fc2908d6ec5773e0dca4a55a5e
2
+ SHA256:
3
+ metadata.gz: c8a55c9e4871eb5653df12a3565c57e8b1b833da4705949e3fcb0acfd89d3a71
4
+ data.tar.gz: ef4b83412f6da3e8a0f15327eb8d6890a285a8754f466631dc37f17711cbb139
5
5
  SHA512:
6
- metadata.gz: 5aafd1399256f69ed91b23d6550bbd606ff2935b6c4b0bc848698e45ad7300a5bbb27b66684627e06a8d1218f0a0348c5d16620be6fd54398fd20f062620be47
7
- data.tar.gz: 2b81379873bb1c5a69e442718ac0661799840b29d8121b2a929e2f59ae1d723ba701623c2d990aa6e9fa64975e2c9312dbb8774bffc802d490b752f42ee8cfd1
6
+ metadata.gz: a1923957903414ee3d4eba96bfd50f7498c9854beb0ab10d18a9716a4c6326a52ac897dcd10fa1269902b14be87cfa415d6f0bad8fd180cf8bf34d3dffd00cc6
7
+ data.tar.gz: 668f4b68f42e20910bac21c9cbd3cb8722b92f66a45083692c90515a11610259edba556f2ed57559f2187dc897a7ad61c37a255d0b1a0e1094ccd03f3e631ae1
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ name: Test
8
+ strategy:
9
+ matrix:
10
+ ruby_version:
11
+ - '3.0'
12
+ - 2.7
13
+ fail-fast: false
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby_version }}
20
+ bundler-cache: true
21
+ - run: bundle exec rake spec
22
+
data/README.md CHANGED
@@ -36,16 +36,17 @@ Or install it yourself as:
36
36
 
37
37
  ## Usage
38
38
 
39
- First, you need to login Google Cloud Platform and enable APIs.
39
+ First, you need to login Google Cloud Platform and enable APIs. We support authentication with `User account` and `Service account`.
40
40
 
41
- 1. Open https://console.developers.google.com/project
41
+ ### User authentication
42
+
43
+ 1. Open [API library page](https://console.developers.google.com/apis/library)
42
44
  2. Create/Select project
43
- 3. Visit APIs & auth -> APIs
44
- 4. Grant access to `Drive API`
45
- 5. Visit APIs & auth -> Credentials
46
- 6. Oauth -> Create new Client ID
47
- 7. Choose Installed application (Other)
48
- 8. Note CLIENT ID, CLIENT_SECRET
45
+ 3. Enable "Google Drive API" and "Google Sheets API"
46
+ 4. Open [Credentials page](https://console.developers.google.com/apis/credentials) in the same project
47
+ 5. Click "Create credentials" and choose "OAuth client ID"
48
+ 6. Choose "Other" for "Application type", and click "create"
49
+ 7. Note CLIENT ID, CLIENT_SECRET
49
50
 
50
51
  Setup client_id, client_secret, and login.
51
52
 
@@ -57,6 +58,23 @@ $ drive_env auth login
57
58
 
58
59
  Now you have access token and refresh token, you can access to Google APIs.
59
60
 
61
+ ### Service account authentication
62
+
63
+ 1. Open [API library page](https://console.developers.google.com/apis/library)
64
+ 2. Create/Select project
65
+ 3. Enable "Google Drive API" and "Google Sheets API"
66
+ 4. Open [Credentials page](https://console.developers.google.com/apis/credentials) in the same project
67
+ 5. Click "Create credentials" and choose "Service account key"
68
+ 6. Save credentials as JSON file
69
+ 7. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variables with the value of the downloaded JSON file path.
70
+ ```
71
+ $ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account_credential.json"
72
+ ```
73
+
74
+ The application search `GOOGLE_APPLICATION_CREDENTIALS` first and then try to use user credential.
75
+
76
+ ### Access Spreadsheet
77
+
60
78
  Show Spreadsheet in Google Drive:
61
79
 
62
80
  ```
@@ -98,9 +116,47 @@ $ drive_env spreadsheet to_env sheet1 > .env
98
116
  $ your-ruby-application-with-dotenv-gem
99
117
  ```
100
118
 
119
+ #### Output format
120
+
121
+ JSON output is available by `--format=json` option.
122
+
123
+ ```
124
+ $ drive_env spreadsheet to_env sheet1 --format=json
125
+ [
126
+ {
127
+ "key": "RAILS_ENV",
128
+ "value": "production"
129
+ },
130
+ {
131
+ "key": "DATABASE_HOSTNAME",
132
+ "value": "x.x.x.x"
133
+ },
134
+ {
135
+ "key": "DATABASE_USERNAME",
136
+ "value": "appuser"
137
+ },
138
+ {
139
+ "key": "DATABASE_PASSWORD",
140
+ "value": "appuser"
141
+ },
142
+ {
143
+ "key": "SMTP_HOST",
144
+ "value": "x.x.x.x"
145
+ },
146
+ {
147
+ "key": "SMTP_USERNAME",
148
+ "value": "appuser"
149
+ },
150
+ {
151
+ "key": "SMTP_PASSWORD",
152
+ "value": "appuser"
153
+ }
154
+ ]
155
+ ```
156
+
101
157
  ## Development
102
158
 
103
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
159
+ 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.
104
160
 
105
161
  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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
162
 
@@ -112,4 +168,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/groove
112
168
  ## License
113
169
 
114
170
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
115
-
data/drive_env.gemspec CHANGED
@@ -27,13 +27,13 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "google_drive", "~> 2.1.3"
31
- spec.add_dependency "googleauth", "~> 0.5.1"
32
- spec.add_dependency "thor", "~> 0.19.1"
33
- spec.add_dependency "text-table", "~> 1.2.4"
30
+ spec.add_dependency "google_drive", "~> 3.0"
31
+ spec.add_dependency "googleauth", "~> 0.5"
32
+ spec.add_dependency "thor", "~> 0.19"
33
+ spec.add_dependency "text-table", "~> 1.2"
34
34
 
35
- spec.add_development_dependency "bundler", "~> 1.10"
36
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rake"
37
37
  spec.add_development_dependency "rspec"
38
38
  spec.add_development_dependency "pry"
39
39
  end
@@ -2,6 +2,7 @@ require 'thor'
2
2
  require 'text-table'
3
3
  require 'google_drive'
4
4
  require 'drive_env'
5
+ require 'json'
5
6
 
6
7
  module DriveEnv
7
8
  module Cli
@@ -22,19 +23,34 @@ module DriveEnv
22
23
  end
23
24
 
24
25
  desc 'to_env SPREADSHEET_URL_OR_ALIAS', ''
26
+ option :format, type: 'string', default: 'dotenv', enum: %w[dotenv json],
27
+ desc: 'output format'
25
28
  def to_env(url_or_alias)
26
29
  ws = worksheet(url_or_alias)
30
+
31
+ envs = []
27
32
  ws.rows.each.with_index do |row, idx|
28
33
  row_to_env(row) do |key, value, comment|
34
+ envs << { key: key, value: value, comment: comment }
35
+ end
36
+ end
37
+
38
+ case options[:format]
39
+ when 'dotenv'
40
+ envs.each do |env|
29
41
  case
30
- when key && value && comment
31
- puts "#{key}=#{value} #{comment}"
32
- when key && value && !comment
33
- puts "#{key}=#{value}"
34
- when !key && !value && comment
35
- puts comment
42
+ when env[:key] && env[:value] && env[:comment]
43
+ puts "#{env[:key]}=#{env[:value]} #{env[:comment]}"
44
+ when env[:key] && env[:value] && !env[:comment]
45
+ puts "#{env[:key]}=#{env[:value]}"
46
+ when !env[:key] && !env[:value] && env[:comment]
47
+ puts "#{env[:comment]}"
36
48
  end
37
49
  end
50
+ when 'json'
51
+ puts JSON.pretty_generate(
52
+ envs.select{|env| env[:key] }.map{|env| { key: env[:key], value: env[:value] } }
53
+ )
38
54
  end
39
55
  end
40
56
 
@@ -75,14 +91,20 @@ module DriveEnv
75
91
 
76
92
  def credential
77
93
  unless @credential
78
- @credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
79
- case
80
- when @credential.nil?
81
- abort "please set access_token: #{$0} auth login"
82
- when @credential.expired?
94
+ case authorizer
95
+ when Google::Auth::UserAuthorizer
96
+ @credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
97
+ case
98
+ when @credential.nil?
99
+ abort "please set access_token: #{$0} auth login"
100
+ when @credential.expired?
101
+ @credential.fetch_access_token!
102
+ @credential.expires_at = credential.issued_at + credential.expires_in
103
+ authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
104
+ end
105
+ when Google::Auth::ServiceAccountCredentials
106
+ @credential = authorizer
83
107
  @credential.fetch_access_token!
84
- @credential.expires_at = credential.issued_at + credential.expires_in
85
- authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
86
108
  end
87
109
  end
88
110
  @credential
@@ -134,4 +156,3 @@ module DriveEnv
134
156
  end
135
157
  end
136
158
  end
137
-
@@ -1,3 +1,3 @@
1
1
  module DriveEnv
2
- VERSION = '0.2.2'
2
+ VERSION = '0.4.1'
3
3
  end
data/lib/drive_env.rb CHANGED
@@ -9,13 +9,21 @@ module DriveEnv
9
9
  class << self
10
10
  def authorizer(client_id, client_secret, token_store_file)
11
11
  unless @authorizer
12
- client_id = Google::Auth::ClientId.new(client_id, client_secret)
12
+ cred = ENV['GOOGLE_APPLICATION_CREDENTIALS']
13
13
  scope = %w[
14
14
  https://www.googleapis.com/auth/drive
15
15
  https://spreadsheets.google.com/feeds/
16
16
  ]
17
- token_store = Google::Auth::Stores::FileTokenStore.new(file: token_store_file)
18
- @authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
17
+ if cred.nil?
18
+ client_id = Google::Auth::ClientId.new(client_id, client_secret)
19
+ token_store = Google::Auth::Stores::FileTokenStore.new(file: token_store_file)
20
+ @authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
21
+ else
22
+ @authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
23
+ json_key_io: File.open(cred),
24
+ scope: scope
25
+ )
26
+ end
19
27
  end
20
28
  @authorizer
21
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drive_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMADA Tsuyoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.3
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.3
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: googleauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.1
33
+ version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.1
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.19.1
47
+ version: '0.19'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.19.1
54
+ version: '0.19'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: text-table
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.4
61
+ version: '1.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.4
68
+ version: '1.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '1.10'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '1.10'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -130,9 +130,9 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".github/workflows/ci.yml"
133
134
  - ".gitignore"
134
135
  - ".rspec"
135
- - ".travis.yml"
136
136
  - Gemfile
137
137
  - LICENSE.txt
138
138
  - README.md
@@ -169,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.5.2
172
+ rubygems_version: 3.2.26
174
173
  signing_key:
175
174
  specification_version: 4
176
175
  summary: Generate `.env` file from Spreadsheet in Google Drive
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4.1
4
- - 2.3.4
5
- - 2.2.7