gclouder 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/gclouder/resources/storage/buckets.rb +105 -0
- data/lib/gclouder/resources/storage/notifications.rb +93 -0
- data/lib/gclouder/version.rb +1 -1
- data/lib/gclouder.rb +9 -2
- metadata +4 -3
- data/lib/gclouder/resources/storagebuckets.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7311a9316efc730260a93a0b835151265579e08
|
4
|
+
data.tar.gz: eda71d3ca4b1001f2ef5bd1e0e7f913f66b7d99c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f1d9ecd8560d94f2a542deb5c78fc4ece8e435b153ad19980ad1fdc0e267be1c0f081019eb69396600bb21d8dc0d27b0b4c95c6f2f96f89fcd1518a1a80b1c
|
7
|
+
data.tar.gz: 403efac259b7d0036365ea05fd0bba0f22a44d644056eb313a7182a18e5f0e6930e2bfd8232fa2f29cf0d113de73fb898540329e59b16e5d71f0083e343b7dde
|
data/README.md
CHANGED
@@ -119,5 +119,10 @@ To build and install a gem run:
|
|
119
119
|
```
|
120
120
|
rake build
|
121
121
|
gem install pkg/gclouder-<version>.gem
|
122
|
-
|
122
|
+
```
|
123
|
+
|
124
|
+
To perform a release
|
125
|
+
```
|
126
|
+
# adjust version in lib/gclouder/version.rb then run:
|
127
|
+
rake release
|
123
128
|
```
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module GClouder
|
4
|
+
module Resources
|
5
|
+
module Storage
|
6
|
+
module Buckets
|
7
|
+
include GClouder::Logging
|
8
|
+
include GClouder::Shell
|
9
|
+
include GClouder::Resource::Cleaner
|
10
|
+
|
11
|
+
def self.header(stage = :ensure)
|
12
|
+
info "[#{stage}] storage / buckets", title: true, indent: 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.validate
|
16
|
+
return if Local.list.empty?
|
17
|
+
header :validate
|
18
|
+
Local.validate
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ensure
|
22
|
+
return if Local.list.empty?
|
23
|
+
header
|
24
|
+
|
25
|
+
Local.list.each do |region, region_config|
|
26
|
+
info region, heading: true, indent: 2
|
27
|
+
region_config.each do |bucket|
|
28
|
+
info
|
29
|
+
Bucket.ensure(region, bucket)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Local
|
35
|
+
def self.list
|
36
|
+
instances
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.validate
|
40
|
+
# Validation knowledge included here because we don't have arguments parser for gsutil.
|
41
|
+
# We also don't support every key that gsutil does. See Bucket.ensure() below.
|
42
|
+
permitted_and_required_keys = {
|
43
|
+
"default_access"=>{"type"=>"String", "required"=>true}
|
44
|
+
}
|
45
|
+
|
46
|
+
Resources::Validate::Region.instances(
|
47
|
+
instances,
|
48
|
+
permitted_keys: permitted_and_required_keys
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.instances
|
53
|
+
Resources::Region.instances(path: ["storage", "buckets"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module Remote
|
58
|
+
include GClouder::GSUtil
|
59
|
+
|
60
|
+
# FIXME: make more robust(!)
|
61
|
+
def self.list
|
62
|
+
gsutil("ls", "-L").to_s.split("gs://").delete_if(&:empty?).each_with_object({}) do |data, collection|
|
63
|
+
normalized = data.split("\n").map! { |b| b.delete("\t") }
|
64
|
+
bucket_name = normalized[0].delete("/ :")
|
65
|
+
region = normalized.select { |e| e.match("^Location constraint:") }.last.split(":").last.downcase
|
66
|
+
collection[region] ||= []
|
67
|
+
collection[region] << { "name" => bucket_name }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
module Bucket
|
73
|
+
include GClouder::GSUtil
|
74
|
+
include GClouder::Config::CLIArgs
|
75
|
+
|
76
|
+
def self.setDefaultAccess(bucket_name, default_access)
|
77
|
+
info "# gsutil defacl ch -u #{default_access} gs://#{bucket_name}" if cli_args[:debug]
|
78
|
+
|
79
|
+
return if cli_args[:dry_run]
|
80
|
+
|
81
|
+
# Just use shell, as -p flag is not valid for 'defacl ch'.
|
82
|
+
shell("gsutil defacl ch -u #{default_access} gs://#{bucket_name}")
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.check_exists?(region, bucket_name)
|
86
|
+
gsutil_exec("ls", "gs://#{bucket_name} > /dev/null 2>&1 && echo 0 || echo 1").to_i == 0
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.ensure(region, bucket)
|
90
|
+
if check_exists?(region, bucket["name"])
|
91
|
+
good bucket["name"]
|
92
|
+
return
|
93
|
+
end
|
94
|
+
|
95
|
+
add "#{bucket["name"]} [#{bucket["default_access"]}]"
|
96
|
+
gsutil "mb", "-l #{region} gs://#{bucket["name"]}"
|
97
|
+
|
98
|
+
|
99
|
+
setDefaultAccess bucket["name"], bucket["default_access"] if bucket.key?("default_access")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module GClouder
|
4
|
+
module Resources
|
5
|
+
module Storage
|
6
|
+
module Notifications
|
7
|
+
include GClouder::Logging
|
8
|
+
include GClouder::Shell
|
9
|
+
|
10
|
+
def self.header(stage = :ensure)
|
11
|
+
info "[#{stage}] storage / notifications", title: true, indent: 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.validate
|
15
|
+
return if Local.list.empty?
|
16
|
+
header :validate
|
17
|
+
Local.validate
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.ensure
|
21
|
+
return if Local.list.empty?
|
22
|
+
header
|
23
|
+
|
24
|
+
Local.list.each do |region, region_config|
|
25
|
+
info region, heading: true, indent: 2
|
26
|
+
region_config.each do |notification|
|
27
|
+
info
|
28
|
+
Notification.ensure(notification)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Local
|
34
|
+
def self.list
|
35
|
+
instances
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.validate
|
39
|
+
# Validation knowledge included here because we don't have arguments parser for gsutil.
|
40
|
+
# We also don't support every key that gsutil does. See Notification.ensure() below.
|
41
|
+
permitted_and_required_keys = {
|
42
|
+
"bucket"=>{"type"=>"String", "required"=>true},
|
43
|
+
"topic"=>{"type"=>"String", "required"=>true},
|
44
|
+
"events"=>{"type"=>"Array", "required"=>false}
|
45
|
+
}
|
46
|
+
|
47
|
+
Resources::Validate::Region.instances(
|
48
|
+
instances,
|
49
|
+
permitted_keys: permitted_and_required_keys
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.instances
|
54
|
+
Resources::Region.instances(path: ["storage", "notifications"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module Notification
|
59
|
+
include GClouder::GSUtil
|
60
|
+
include GClouder::Config::CLIArgs
|
61
|
+
|
62
|
+
def self.notification_exists?(notification)
|
63
|
+
notifications_exist = gsutil_exec("notification list", " gs://#{notification["bucket"]} > /dev/null 2>&1 && echo 0 || echo 1").to_i == 0
|
64
|
+
if not notifications_exist
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
68
|
+
return gsutil("notification list", "gs://#{notification["bucket"]}", force: true)
|
69
|
+
.include?("projects/#{project["project_id"]}/topics/#{notification["topic"]}")
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.ensure(notification)
|
74
|
+
if notification_exists?(notification)
|
75
|
+
good "notification topic: #{notification["name"]}; bucket: #{notification["bucket"]}", indent: 4
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
event_type_args = ""
|
80
|
+
if notification.has_key?("events")
|
81
|
+
event_type_args = "-e #{notification["events"].join(",")}"
|
82
|
+
end
|
83
|
+
|
84
|
+
args = "-t #{notification["name"]} #{event_type_args} -f json gs://#{notification["bucket"]}"
|
85
|
+
|
86
|
+
add "notification topic: #{notification["name"]}; bucket: #{notification["bucket"]}", indent: 4
|
87
|
+
gsutil "notification create", args
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/gclouder/version.rb
CHANGED
data/lib/gclouder.rb
CHANGED
@@ -53,7 +53,8 @@ require "gclouder/resources/project_id"
|
|
53
53
|
require "gclouder/resources/project"
|
54
54
|
require "gclouder/resources/project/iam_policy_binding.rb"
|
55
55
|
|
56
|
-
require "gclouder/resources/
|
56
|
+
require "gclouder/resources/storage/buckets"
|
57
|
+
require "gclouder/resources/storage/notifications"
|
57
58
|
|
58
59
|
require "gclouder/resources/compute/networks"
|
59
60
|
require "gclouder/resources/compute/networks/subnets"
|
@@ -161,10 +162,16 @@ module GClouder
|
|
161
162
|
|
162
163
|
{
|
163
164
|
name: "storage-buckets",
|
164
|
-
module: Resources::
|
165
|
+
module: Resources::Storage::Buckets,
|
165
166
|
skip: [ :check ],
|
166
167
|
},
|
167
168
|
|
169
|
+
{
|
170
|
+
name: "storage-notifications",
|
171
|
+
module: Resources::Storage::Notifications,
|
172
|
+
skip: [ :check, :clean ],
|
173
|
+
},
|
174
|
+
|
168
175
|
{
|
169
176
|
name: "networks",
|
170
177
|
module: Resources::Compute::Networks,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gclouder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Wilson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-06-
|
12
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -251,7 +251,8 @@ files:
|
|
251
251
|
- lib/gclouder/resources/project_id.rb
|
252
252
|
- lib/gclouder/resources/pubsub/subscriptions.rb
|
253
253
|
- lib/gclouder/resources/pubsub/topics.rb
|
254
|
-
- lib/gclouder/resources/
|
254
|
+
- lib/gclouder/resources/storage/buckets.rb
|
255
|
+
- lib/gclouder/resources/storage/notifications.rb
|
255
256
|
- lib/gclouder/resources/validate/global.rb
|
256
257
|
- lib/gclouder/resources/validate/local.rb
|
257
258
|
- lib/gclouder/resources/validate/region.rb
|
@@ -1,103 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
module GClouder
|
4
|
-
module Resources
|
5
|
-
module StorageBuckets
|
6
|
-
include GClouder::Logging
|
7
|
-
include GClouder::Shell
|
8
|
-
include GClouder::Resource::Cleaner
|
9
|
-
|
10
|
-
def self.header(stage = :ensure)
|
11
|
-
info "[#{stage}] storage / buckets", title: true, indent: 1
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.validate
|
15
|
-
return if Local.list.empty?
|
16
|
-
header :validate
|
17
|
-
Local.validate
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.ensure
|
21
|
-
return if Local.list.empty?
|
22
|
-
header
|
23
|
-
|
24
|
-
Local.list.each do |region, region_config|
|
25
|
-
info region, heading: true, indent: 2
|
26
|
-
region_config.each do |bucket|
|
27
|
-
info
|
28
|
-
StorageBucket.ensure(region, bucket)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module Local
|
34
|
-
def self.list
|
35
|
-
instances
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.validate
|
39
|
-
# Validation knowledge included here because we don't have arguments parser for gsutil.
|
40
|
-
# We also don't support every key that gsutil does. See StorageBucket.ensure() below.
|
41
|
-
permitted_and_required_keys = {
|
42
|
-
"default_access"=>{"type"=>"String", "required"=>true}
|
43
|
-
}
|
44
|
-
|
45
|
-
Resources::Validate::Region.instances(
|
46
|
-
instances,
|
47
|
-
permitted_keys: permitted_and_required_keys
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.instances
|
52
|
-
Resources::Region.instances(path: ["storage", "buckets"])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
module Remote
|
57
|
-
include GClouder::GSUtil
|
58
|
-
|
59
|
-
# FIXME: make more robust(!)
|
60
|
-
def self.list
|
61
|
-
gsutil("ls", "-L").to_s.split("gs://").delete_if(&:empty?).each_with_object({}) do |data, collection|
|
62
|
-
normalized = data.split("\n").map! { |b| b.delete("\t") }
|
63
|
-
bucket_name = normalized[0].delete("/ :")
|
64
|
-
region = normalized.select { |e| e.match("^Location constraint:") }.last.split(":").last.downcase
|
65
|
-
collection[region] ||= []
|
66
|
-
collection[region] << { "name" => bucket_name }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module StorageBucket
|
72
|
-
include GClouder::GSUtil
|
73
|
-
include GClouder::Config::CLIArgs
|
74
|
-
|
75
|
-
def self.setDefaultAccess(bucket_name, default_access)
|
76
|
-
info "# gsutil defacl ch -u #{default_access} gs://#{bucket_name}" if cli_args[:debug]
|
77
|
-
|
78
|
-
return if cli_args[:dry_run]
|
79
|
-
|
80
|
-
# Just use shell, as -p flag is not valid for 'defacl ch'.
|
81
|
-
shell("gsutil defacl ch -u #{default_access} gs://#{bucket_name}")
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.check_exists?(region, bucket_name)
|
85
|
-
gsutil_exec("ls", "gs://#{bucket_name} > /dev/null 2>&1 && echo 0 || echo 1").to_i == 0
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.ensure(region, bucket)
|
89
|
-
if check_exists?(region, bucket["name"])
|
90
|
-
good bucket["name"]
|
91
|
-
return
|
92
|
-
end
|
93
|
-
|
94
|
-
add "#{bucket["name"]} [#{bucket["default_access"]}]"
|
95
|
-
gsutil "mb", "-l #{region} gs://#{bucket["name"]}"
|
96
|
-
|
97
|
-
|
98
|
-
setDefaultAccess bucket["name"], bucket["default_access"] if bucket.key?("default_access")
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|