bucket_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.gitlab-ci.yml +70 -0
  4. data/.idea/bucket_client.iml +105 -0
  5. data/.idea/encodings.xml +4 -0
  6. data/.idea/misc.xml +7 -0
  7. data/.idea/modules.xml +8 -0
  8. data/.idea/runConfigurations/Integration_Test.xml +37 -0
  9. data/.idea/runConfigurations/Unit_Test.xml +37 -0
  10. data/.rspec +3 -0
  11. data/CODE_OF_CONDUCT.md +74 -0
  12. data/Gemfile +6 -0
  13. data/Gemfile.lock +114 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +870 -0
  16. data/Rakefile +6 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/bucket_client.gemspec +46 -0
  20. data/integration/aws_blob_spec.rb +134 -0
  21. data/integration/aws_bucket_spec.rb +145 -0
  22. data/integration/azure_blob_spec.rb +132 -0
  23. data/integration/azure_bucket_spec.rb +132 -0
  24. data/integration/dev_blob_spec.rb +131 -0
  25. data/integration/dev_bucket_spec.rb +140 -0
  26. data/integration/do_blob_spec.rb +134 -0
  27. data/integration/do_bucket_spec.rb +144 -0
  28. data/integration/gcp_blob_spec.rb +132 -0
  29. data/integration/gcp_bucket_spec.rb +132 -0
  30. data/integration/img.jpg +0 -0
  31. data/lib/bucket_client.rb +66 -0
  32. data/lib/bucket_client/aws/aws_bucket.rb +85 -0
  33. data/lib/bucket_client/aws/aws_client.rb +195 -0
  34. data/lib/bucket_client/aws/aws_http_client.rb +32 -0
  35. data/lib/bucket_client/aws/aws_policy_factory.rb +26 -0
  36. data/lib/bucket_client/aws4_request_signer.rb +133 -0
  37. data/lib/bucket_client/azure/azure_bucket.rb +83 -0
  38. data/lib/bucket_client/azure/azure_client.rb +197 -0
  39. data/lib/bucket_client/bucket.rb +388 -0
  40. data/lib/bucket_client/bucket_operation_exception.rb +8 -0
  41. data/lib/bucket_client/client.rb +408 -0
  42. data/lib/bucket_client/dev/local_bucket.rb +84 -0
  43. data/lib/bucket_client/dev/local_client.rb +148 -0
  44. data/lib/bucket_client/digital_ocean/digital_ocean_acl_factory.rb +39 -0
  45. data/lib/bucket_client/digital_ocean/digital_ocean_bucket.rb +81 -0
  46. data/lib/bucket_client/digital_ocean/digital_ocean_client.rb +275 -0
  47. data/lib/bucket_client/digital_ocean/digital_ocean_http_client.rb +31 -0
  48. data/lib/bucket_client/gcp/gcp_bucket.rb +79 -0
  49. data/lib/bucket_client/gcp/gcp_client.rb +171 -0
  50. data/lib/bucket_client/operation_result.rb +33 -0
  51. data/lib/bucket_client/version.rb +3 -0
  52. metadata +246 -0
@@ -0,0 +1,132 @@
1
+ require "bucket_client/azure/azure_bucket"
2
+ require "bucket_client/azure/azure_client"
3
+
4
+ describe BucketClient::AzureClient do
5
+
6
+ id = ENV["AZURE_ACC_ID"]
7
+ secret = ENV["AZURE_KEY"]
8
+ client = BucketClient::AzureClient.new(id, secret)
9
+ key = "kirin-bucket-client-client-integration"
10
+
11
+ before(:all) {client.delete_bucket_if_exist key}
12
+ after(:all) {client.delete_bucket_if_exist key}
13
+
14
+ describe 'exist_bucket' do
15
+ it 'should return false' do
16
+ expect(client.exist_bucket key).to be_falsey
17
+ end
18
+ end
19
+
20
+ describe 'delete_bucket_if_exist' do
21
+ it 'should be successful' do
22
+ result = client.delete_bucket_if_exist key
23
+ expect(result.code).to eq 200
24
+ expect(result.success).to be_truthy
25
+ expect(result.message).to eq "Bucket already deleted"
26
+ end
27
+ end
28
+
29
+ describe 'delete_bucket' do
30
+ it 'should fail as bucket does not exist' do
31
+ result = client.delete_bucket key
32
+ expect(result.code).to eq 404
33
+ expect(result.success).to be_falsey
34
+ expect(result.value).to be_nil
35
+ end
36
+ end
37
+
38
+ describe "set_read_policy" do
39
+ it 'should fail as bucket does not exist' do
40
+ result = client.set_read_policy key, :public
41
+ expect(result.code).to eq 404
42
+ expect(result.success).to be_falsey
43
+ expect(result.value).to be_nil
44
+ end
45
+ end
46
+
47
+ describe "get_bucket!" do
48
+ it 'should generate unsafe bucket with correct key' do
49
+ bucket = client.get_bucket! key
50
+ expect(bucket.key).to eq key
51
+ end
52
+ end
53
+
54
+ describe "put_bucket" do
55
+ it 'should create new bucket' do
56
+ result = client.put_bucket key
57
+ expect(result.code).to eq 200
58
+ expect(result.success).to be_truthy
59
+ expect(result.value.key).to eq key
60
+ end
61
+ end
62
+
63
+ describe 'create_bucket' do
64
+ it 'should fail creating a new bucket because it already exist' do
65
+
66
+ expect(client.exist_bucket key).to be_truthy
67
+ result = client.create_bucket key
68
+ expect(result.code).to eq 409
69
+ expect(result.success).to be_falsey
70
+ expect(result.value).to be_nil
71
+ end
72
+ end
73
+
74
+ describe 'delete_bucket' do
75
+ it 'should succeed deleting a new bucket' do
76
+ result = client.delete_bucket key
77
+ expect(result.code).to eq 200
78
+ expect(result.success).to be_truthy
79
+ sleep(60)
80
+ end
81
+ end
82
+
83
+ describe "create_bucket" do
84
+ it 'should succeed at creating a new bucket' do
85
+ result = client.create_bucket key
86
+ expect(result.code).to eq 200
87
+ expect(result.success).to be_truthy
88
+ expect(result.value.key).to eq key
89
+ end
90
+ end
91
+
92
+ describe 'put_bucket' do
93
+ it 'should not fail even if bucket already exist' do
94
+ result = client.put_bucket key
95
+ expect(result.code).to eq 200
96
+ expect(result.success).to be_truthy
97
+ expect(result.value.key).to eq key
98
+ end
99
+ end
100
+
101
+ describe "set_read_policy" do
102
+ it 'should fail if access is neither :public or :private' do
103
+ expect {client.set_read_policy key, :protected}.to raise_error(ArgumentError, "Read Policy not accepted")
104
+ end
105
+ it 'should succeed' do
106
+ result = client.set_read_policy key, :public
107
+ expect(result.code).to eq 200
108
+ expect(result.success).to be_truthy
109
+ expect(result.value).to be_nil
110
+ end
111
+ end
112
+
113
+ describe "set_get_cors" do
114
+ it 'should should succeed' do
115
+ result = client.set_get_cors key, ["*"]
116
+ expect(result.code).to eq 200
117
+ expect(result.success).to be_truthy
118
+ expect(result.value).to be_nil
119
+ end
120
+ end
121
+
122
+ describe "delete_bucket_if_exist" do
123
+ it 'should remove existing bucket' do
124
+ result = client.delete_bucket_if_exist key
125
+ expect(result.code).to eq 200
126
+ expect(result.success).to be_truthy
127
+ expect(result.value).to be_nil
128
+ expect(client.exist_bucket key).to be_falsey
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,131 @@
1
+ require "bucket_client/dev/local_client"
2
+ require "bucket_client/dev/local_bucket"
3
+
4
+ describe BucketClient::LocalBucket do
5
+ host = "sample-host"
6
+ client = BucketClient::LocalClient.new(host)
7
+ key = "kirin-bucket-client-bucket-integration"
8
+ file = "integration/img.jpg"
9
+ bin = IO.binread file
10
+ before(:all) {client.put_bucket key}
11
+ after(:all) {
12
+ bucket = client.get_bucket key
13
+ bucket.delete_blob_if_exist file
14
+ client.delete_bucket_if_exist key
15
+ }
16
+
17
+
18
+ describe 'Blob Behaviour' do
19
+ bucket = client.get_bucket! key
20
+ describe 'exist_blob' do
21
+ it 'should return false as blob does not exist' do
22
+ expect(bucket.exist_blob file).to be_falsey
23
+ end
24
+ end
25
+
26
+ describe 'delete_blob_if_exist' do
27
+ it 'should succeed' do
28
+ result = bucket.delete_blob_if_exist file
29
+ expect(result.code).to eq 204
30
+ expect(result.success).to be_truthy
31
+ end
32
+ end
33
+
34
+ describe 'delete_blob' do
35
+ it 'should fail as blob does not exist' do
36
+ result = bucket.delete_blob file
37
+ expect(result.success).to be_falsey
38
+ end
39
+ end
40
+
41
+ describe 'update_blob' do
42
+ it 'should fail as blob does not exist' do
43
+ result = bucket.update_blob bin, file
44
+ expect(result.success).to be_falsey
45
+ end
46
+ end
47
+
48
+ describe 'get_blob' do
49
+ it 'should fail as blob does not exist' do
50
+ result = bucket.get_blob file
51
+ expect(result.success).to be_falsey
52
+ end
53
+ end
54
+
55
+ describe "put_blob" do
56
+ it 'should succeed' do
57
+ result = bucket.put_blob bin, file
58
+ expect(result).to be_truthy
59
+ expect(result.value).to eq "#{host}/#{key}/#{file}"
60
+ end
61
+ end
62
+
63
+ describe 'exist_blob' do
64
+ it 'should exist' do
65
+ expect(bucket.exist_blob file).to be_truthy
66
+ end
67
+ end
68
+
69
+ describe "create_blob" do
70
+ it 'should fail as blob already exist' do
71
+ result = bucket.create_blob bin, file
72
+ expect(result.success).to be_falsey
73
+ end
74
+ end
75
+
76
+ describe "get_blob" do
77
+ it 'should obtain the binary of the blob' do
78
+ result = bucket.get_blob file
79
+ expect(result.success).to be_truthy
80
+ expect(result.value).to eq bin
81
+ end
82
+ end
83
+
84
+ describe "delete_blob" do
85
+ it 'should pass as blob exist' do
86
+ result = bucket.delete_blob file
87
+ expect(result.success).to be_truthy
88
+
89
+ end
90
+ end
91
+
92
+ describe "create_blob" do
93
+ it 'should work as blob does not exist' do
94
+ result = bucket.create_blob bin, file
95
+ expect(result.success).to be_truthy
96
+ expect(result.value).to eq "#{host}/#{key}/#{file}"
97
+ end
98
+ end
99
+
100
+ describe "update_blob" do
101
+ it 'should work as blob exist' do
102
+ result = bucket.update_blob bin, file
103
+ expect(result.success).to be_truthy
104
+ expect(result.value).to eq "#{host}/#{key}/#{file}"
105
+ end
106
+ end
107
+
108
+ describe "put_blob" do
109
+ it 'should work as blob exist' do
110
+ result = bucket.put_blob bin, file
111
+ expect(result.success).to be_truthy
112
+ expect(result.value).to eq "#{host}/#{key}/#{file}"
113
+ end
114
+ end
115
+
116
+ describe "delete_blob_if_exist" do
117
+ it 'should delete blob' do
118
+ result = bucket.delete_blob_if_exist file
119
+ expect(result.success).to be_truthy
120
+ end
121
+ end
122
+
123
+ describe "exist_blob" do
124
+ it 'should no longer exist' do
125
+ expect(bucket.exist_blob file).to be_falsey
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+ end
@@ -0,0 +1,140 @@
1
+ require "bucket_client/digital_ocean/digital_ocean_bucket"
2
+ require "bucket_client/digital_ocean/digital_ocean_client"
3
+ require "kirin_http"
4
+
5
+ describe BucketClient::DigitalOceanClient do
6
+
7
+ host = "sample-host"
8
+ client = BucketClient::LocalClient.new(host)
9
+ key = "kirin-bucket-client-client-integration"
10
+
11
+ before(:all) {client.delete_bucket_if_exist key}
12
+ after(:all) {client.delete_bucket_if_exist key}
13
+
14
+ describe 'exist_bucket' do
15
+ it 'should return false' do
16
+ expect(client.exist_bucket key).to be_falsey
17
+ end
18
+ end
19
+
20
+ describe 'delete_bucket_if_exist' do
21
+ it 'should be successful' do
22
+ result = client.delete_bucket_if_exist key
23
+ expect(result.code).to eq 204
24
+ expect(result.success).to be_truthy
25
+ expect(result.message).to eq "OK"
26
+ end
27
+ end
28
+
29
+ describe 'delete_bucket' do
30
+ it 'should fail as bucket does not exist' do
31
+ result = client.delete_bucket key
32
+ expect(result.code).to eq 404
33
+ expect(result.success).to be_falsey
34
+ expect(result.value).to be_nil
35
+ end
36
+ end
37
+
38
+ describe "set_read_policy" do
39
+ it 'should fail as bucket does not exist' do
40
+ result = client.set_read_policy key, :public
41
+ expect(result.code).to eq 404
42
+ expect(result.success).to be_falsey
43
+ expect(result.value).to be_nil
44
+ end
45
+ end
46
+
47
+ describe "set_get_cors" do
48
+ it 'should fail as bucket does notexist' do
49
+ result = client.set_get_cors key, ["*"]
50
+ expect(result.code).to eq 404
51
+ expect(result.success).to be_falsey
52
+ expect(result.value).to be_nil
53
+ end
54
+ end
55
+
56
+ describe "get_bucket!" do
57
+ it 'should generate unsafe bucket with correct key' do
58
+ bucket = client.get_bucket! key
59
+ expect(bucket.key).to eq key
60
+ end
61
+ end
62
+
63
+ describe "put_bucket" do
64
+ it 'should create new bucket' do
65
+ result = client.put_bucket key
66
+ expect(result.code).to eq 200
67
+ expect(result.success).to be_truthy
68
+ expect(result.value.key).to eq key
69
+ end
70
+ end
71
+
72
+ describe 'create_bucket' do
73
+ it 'should fail creating a new bucket because it already exist' do
74
+
75
+ expect(client.exist_bucket key).to be_truthy
76
+ result = client.create_bucket key
77
+ expect(result.code).to eq 409
78
+ expect(result.success).to be_falsey
79
+ expect(result.value).to be_nil
80
+ end
81
+ end
82
+
83
+ describe 'delete_bucket' do
84
+ it 'should succeed deleting a new bucket' do
85
+ result = client.delete_bucket key
86
+ expect(result.code).to eq 204
87
+ expect(result.success).to be_truthy
88
+ end
89
+ end
90
+
91
+ describe "create_bucket" do
92
+ it 'should succeed at creating a new bucket' do
93
+ result = client.create_bucket key
94
+ expect(result.code).to eq 200
95
+ expect(result.success).to be_truthy
96
+ expect(result.value.key).to eq key
97
+ end
98
+ end
99
+
100
+ describe 'put_bucket' do
101
+ it 'should not fail even if bucket already exist' do
102
+ result = client.put_bucket key
103
+ expect(result.code).to eq 200
104
+ expect(result.success).to be_truthy
105
+ expect(result.value.key).to eq key
106
+ end
107
+ end
108
+
109
+ describe "set_read_policy" do
110
+ it 'should fail if access is neither :public or :private' do
111
+ expect {client.set_read_policy key, :protected}.to raise_error(ArgumentError, "Read Policy not accepted")
112
+ end
113
+ it 'should succeed' do
114
+ result = client.set_read_policy key, :public
115
+ expect(result.code).to eq 200
116
+ expect(result.success).to be_truthy
117
+ expect(result.value).to be_nil
118
+ end
119
+ end
120
+
121
+ describe "set_get_cors" do
122
+ it 'should should succeed' do
123
+ result = client.set_get_cors key, ["*"]
124
+ expect(result.code).to eq 200
125
+ expect(result.success).to be_truthy
126
+ expect(result.value).to be_nil
127
+ end
128
+ end
129
+
130
+ describe "delete_bucket_if_exist" do
131
+ it 'should remove existing bucket' do
132
+ result = client.delete_bucket_if_exist key
133
+ expect(result.code).to eq 204
134
+ expect(result.success).to be_truthy
135
+ expect(result.value).to be_nil
136
+ expect(client.exist_bucket key).to be_falsey
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,134 @@
1
+ require "bucket_client/digital_ocean/digital_ocean_bucket"
2
+ require "bucket_client/digital_ocean/digital_ocean_client"
3
+ require "kirin_http"
4
+
5
+ describe BucketClient::DigitalOceanBucket do
6
+ http = KirinHttp::BasicClient.new
7
+ id = ENV["DO_ID"]
8
+ secret = ENV["DO_SECRET"]
9
+ region = ENV["DO_REGION"]
10
+ client = BucketClient::DigitalOceanClient.new(http, id, secret, region)
11
+ key = "kirin-bucket-client-bucket-integration"
12
+ file = "img.jpg"
13
+ bin = IO.binread "./integration/#{file}"
14
+ before(:all) {client.put_bucket key}
15
+ after(:all) {
16
+ bucket = client.get_bucket key
17
+ bucket.delete_blob_if_exist file
18
+ client.delete_bucket_if_exist key
19
+ }
20
+
21
+
22
+ describe 'Blob Behaviour' do
23
+ bucket = client.get_bucket! key
24
+ describe 'exist_blob' do
25
+ it 'should return false as blob does not exist' do
26
+ expect(bucket.exist_blob file).to be_falsey
27
+ end
28
+ end
29
+
30
+ describe 'delete_blob_if_exist' do
31
+ it 'should succeed' do
32
+ result = bucket.delete_blob_if_exist file
33
+ expect(result.code).to eq 204
34
+ expect(result.success).to be_truthy
35
+ end
36
+ end
37
+
38
+ describe 'delete_blob' do
39
+ it 'should fail as blob does not exist' do
40
+ result = bucket.delete_blob file
41
+ expect(result.success).to be_falsey
42
+ end
43
+ end
44
+
45
+ describe 'update_blob' do
46
+ it 'should fail as blob does not exist' do
47
+ result = bucket.update_blob bin, file
48
+ expect(result.success).to be_falsey
49
+ end
50
+ end
51
+
52
+ describe 'get_blob' do
53
+ it 'should fail as blob does not exist' do
54
+ result = bucket.get_blob file
55
+ expect(result.success).to be_falsey
56
+ end
57
+ end
58
+
59
+ describe "put_blob" do
60
+ it 'should succeed' do
61
+ result = bucket.put_blob bin, file
62
+ expect(result).to be_truthy
63
+ expect(result.value).to eq "https://#{region}.digitaloceanspaces.com/#{key}/#{file}"
64
+ end
65
+ end
66
+
67
+ describe 'exist_blob' do
68
+ it 'should exist' do
69
+ expect(bucket.exist_blob file).to be_truthy
70
+ end
71
+ end
72
+
73
+ describe "create_blob" do
74
+ it 'should fail as blob already exist' do
75
+ result = bucket.create_blob bin, file
76
+ expect(result.success).to be_falsey
77
+ end
78
+ end
79
+
80
+ describe "get_blob" do
81
+ it 'should obtain the binary of the blob' do
82
+ result = bucket.get_blob file
83
+ expect(result.success).to be_truthy
84
+ expect(result.value).to eq bin
85
+ end
86
+ end
87
+
88
+ describe "delete_blob" do
89
+ it 'should pass as blob exist' do
90
+ result = bucket.delete_blob file
91
+ expect(result.success).to be_truthy
92
+ end
93
+ end
94
+
95
+ describe "create_blob" do
96
+ it 'should work as blob does not exist' do
97
+ result = bucket.create_blob bin, file
98
+ expect(result.success).to be_truthy
99
+ expect(result.value).to eq "https://#{region}.digitaloceanspaces.com/#{key}/#{file}"
100
+ end
101
+ end
102
+
103
+ describe "update_blob" do
104
+ it 'should work as blob exist' do
105
+ result = bucket.update_blob bin, file
106
+ expect(result.success).to be_truthy
107
+ expect(result.value).to eq "https://#{region}.digitaloceanspaces.com/#{key}/#{file}"
108
+ end
109
+ end
110
+
111
+ describe "put_blob" do
112
+ it 'should work as blob exist' do
113
+ result = bucket.put_blob bin, file
114
+ expect(result.success).to be_truthy
115
+ expect(result.value).to eq "https://#{region}.digitaloceanspaces.com/#{key}/#{file}"
116
+ end
117
+ end
118
+
119
+ describe "delete_blob_if_exist" do
120
+ it 'should delete blob' do
121
+ result = bucket.delete_blob_if_exist file
122
+ expect(result.success).to be_truthy
123
+ end
124
+ end
125
+
126
+ describe "exist_blob" do
127
+ it 'should no longer exist' do
128
+ expect(bucket.exist_blob file).to be_falsey
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ end