Skip to content

Commit 8d150eb

Browse files
authored
Merge pull request #7 from aka-nez/feature/add-not-signed-url
Add #url for objects
2 parents bd08d85 + f4692ab commit 8d150eb

File tree

15 files changed

+86
-25
lines changed

15 files changed

+86
-25
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Layout/LineLength:
1818
Style/Documentation:
1919
Enabled: false
2020

21+
Style/RedundantInitialize:
22+
Exclude:
23+
- "lib/cloud_storage/wrappers/base.rb"
24+
2125
RSpec/MultipleExpectations:
2226
Enabled: false
2327

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- N/A
12+
13+
### Changed
14+
- N/A
15+
16+
### Deprecated
17+
- N/A
18+
19+
### Removed
20+
- N/A
21+
22+
### Fixed
23+
- N/A
24+
25+
### Security
26+
- N/A
27+
28+
## [0.2.0] - 2022-09-27
29+
30+
### Added
31+
- Added `#url` for gsc & s3 object wrapper that returns public url

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ cli = CloudStorage::Client.new(
107107
=> "http://wallarm-devtmp-ipfeeds-presigned-urls-research.s3:4569/Gemfile?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=...&X-Amz-Date=20210310T061122Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=..."
108108
```
109109

110+
### public url
111+
112+
```ruby
113+
> cli.find('test.txt').url
114+
=> "https://storage.googleapis.com/some-bucket/test_1.txt"
115+
```
116+
110117
### Download
111118

112119
```ruby

cloud_storage.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
2929
spec.bindir = 'exe'
3030
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3131
spec.require_paths = ['lib']
32+
spec.metadata['rubygems_mfa_required'] = 'true'
3233
end

docker/docker-compose.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ services:
1111
com.cloud_storage.ruby.version: $DOCKER_RUBY_VERSION
1212
environment:
1313
- BUNDLE_PATH=/bundle/${DOCKER_RUBY_VERSION}
14-
- SSH_AUTH_SOCK=/ssh/auth/sock
1514
- S3_ENDPOINT=$S3_ENDPOINT
1615
- S3_BUCKET=$S3_BUCKET
1716
- GCS_ENDPOINT=$GCS_ENDPOINT
1817
- GCS_BUCKET=$GCS_BUCKET
1918
volumes:
2019
- ..:/app
21-
- ssh-data:/ssh:ro
2220
- bundler-data:/bundle
2321
command: sh
2422
depends_on:
@@ -44,7 +42,3 @@ volumes:
4442
bundler-data:
4543
external:
4644
name: bundler_data
47-
48-
ssh-data:
49-
external:
50-
name: ssh_data

lib/cloud_storage/objects/gcs.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def signed_url(**opts)
2323
@internal.signed_url version: :v4, **opts
2424
end
2525

26+
def url
27+
@internal.url
28+
end
29+
2630
alias name key
2731

2832
def delete!

lib/cloud_storage/objects/s3.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def key
1717
@internal.key
1818
end
1919

20+
alias name key
21+
2022
def signed_url(**opts)
2123
signer = Aws::S3::Presigner.new(client: @client)
2224

@@ -28,7 +30,9 @@ def signed_url(**opts)
2830
response_content_type: opts[:content_type]
2931
end
3032

31-
alias name key
33+
def url
34+
@internal.public_url
35+
end
3236

3337
def delete!
3438
@resource.bucket(bucket_name).object(key).delete

lib/cloud_storage/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CloudStorage
4-
VERSION = '0.1.2'
4+
VERSION = '0.2.0'
55
end

spec/cloud_storage/objects/gcs_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@
1616
context 'when without options' do
1717
subject(:url) { obj.signed_url(expires_in: 30, issuer: '[email protected]', signing_key: key) }
1818

19-
it { is_expected.to match(%r{\A#{ENV['GCS_ENDPOINT']}#{ENV['GCS_BUCKET']}/test_1.txt}) }
19+
it { is_expected.to match(%r{\A#{ENV.fetch('GCS_ENDPOINT')}#{ENV.fetch('GCS_BUCKET')}/test_1.txt}) }
2020
end
2121

2222
context 'when with some internal options' do
2323
subject(:url) { obj.signed_url(expires_in: 30, issuer: '[email protected]', signing_key: key, version: :v2) }
2424

25-
it { is_expected.to match(%r{\Ahttps://storage.googleapis.com/#{ENV['GCS_BUCKET']}/test_1.txt}) }
25+
it { is_expected.to match(%r{\Ahttps://storage.googleapis.com/#{ENV.fetch('GCS_BUCKET')}/test_1.txt}) }
2626
end
2727
end
2828

29+
describe '#url' do
30+
subject(:url) { obj.url }
31+
32+
after { obj.delete! }
33+
34+
it { is_expected.to eq('https://storage.googleapis.com/some-bucket/test_1.txt') }
35+
end
36+
2937
describe '#delete!' do
3038
context 'when file exists' do
3139
it do

spec/cloud_storage/objects/s3_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@
1313
after { obj.delete! }
1414

1515
it do
16-
expect(url).to match(%r{\A#{ENV['S3_ENDPOINT']}/#{ENV['S3_BUCKET']}/test_1.txt})
16+
expect(url).to match(%r{\A#{ENV.fetch('S3_ENDPOINT')}/#{ENV.fetch('S3_BUCKET')}/test_1.txt})
1717
end
1818
end
1919

20+
describe '#url' do
21+
subject(:url) { obj.url }
22+
23+
after { obj.delete! }
24+
25+
it { is_expected.to eq("#{ENV.fetch('S3_ENDPOINT')}/#{ENV.fetch('S3_BUCKET')}/test_1.txt") }
26+
end
27+
2028
describe '#delete!' do
2129
context 'when file exists' do
2230
it do

0 commit comments

Comments
 (0)