drive_env 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +22 -0
- data/README.md +21 -3
- data/lib/drive_env/cli/spreadsheet.rb +13 -8
- data/lib/drive_env/version.rb +1 -1
- data/lib/drive_env.rb +11 -3
- metadata +4 -4
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff4a1453c14161faa7baf74042a882fe3f526dd21a574d814c2a34870560d2f
|
4
|
+
data.tar.gz: a89a3ccb92efe3453f4ee51e1a0b3b3fbcabc2f9b25c00a56b3f9020d0eec3a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf0f097b20c55fe087557b462c20fe41dcb31a6b1e30a75cb0fc110b8f798b2d15dad6cbca5d1fc55dece490fe813ecc7d69ee15fc31c58d23fff35e3317e6eb
|
7
|
+
data.tar.gz: e66fff342312c3226d427f3259d100416af648f175e4540db1effba146301d62554a344552a299be89771fbf282c05c40e864173f5c059612c0c1d2b1157187d
|
@@ -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,7 +36,9 @@ 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
|
+
|
41
|
+
### User authentication
|
40
42
|
|
41
43
|
1. Open [API library page](https://console.developers.google.com/apis/library)
|
42
44
|
2. Create/Select project
|
@@ -56,6 +58,23 @@ $ drive_env auth login
|
|
56
58
|
|
57
59
|
Now you have access token and refresh token, you can access to Google APIs.
|
58
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
|
+
|
59
78
|
Show Spreadsheet in Google Drive:
|
60
79
|
|
61
80
|
```
|
@@ -99,7 +118,7 @@ $ your-ruby-application-with-dotenv-gem
|
|
99
118
|
|
100
119
|
## Development
|
101
120
|
|
102
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
121
|
+
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.
|
103
122
|
|
104
123
|
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).
|
105
124
|
|
@@ -111,4 +130,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/groove
|
|
111
130
|
## License
|
112
131
|
|
113
132
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
114
|
-
|
@@ -75,14 +75,20 @@ module DriveEnv
|
|
75
75
|
|
76
76
|
def credential
|
77
77
|
unless @credential
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
case authorizer
|
79
|
+
when Google::Auth::UserAuthorizer
|
80
|
+
@credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
|
81
|
+
case
|
82
|
+
when @credential.nil?
|
83
|
+
abort "please set access_token: #{$0} auth login"
|
84
|
+
when @credential.expired?
|
85
|
+
@credential.fetch_access_token!
|
86
|
+
@credential.expires_at = credential.issued_at + credential.expires_in
|
87
|
+
authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
|
88
|
+
end
|
89
|
+
when Google::Auth::ServiceAccountCredentials
|
90
|
+
@credential = authorizer
|
83
91
|
@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
92
|
end
|
87
93
|
end
|
88
94
|
@credential
|
@@ -134,4 +140,3 @@ module DriveEnv
|
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
137
|
-
|
data/lib/drive_env/version.rb
CHANGED
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
|
-
|
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
|
-
|
18
|
-
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YAMADA Tsuyoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|
@@ -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,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
172
|
+
rubygems_version: 3.2.26
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Generate `.env` file from Spreadsheet in Google Drive
|