barruun 0.1.2 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -15
- data/README.md +15 -0
- data/barruun.gemspec +1 -2
- data/lib/barruun/cli.rb +12 -4
- data/lib/barruun/configurations/bigquery/dataset.rb +19 -0
- data/lib/barruun/{logging/sink/config.rb → configurations/logging/sink.rb} +9 -3
- data/lib/barruun/{storage/bucket/config.rb → configurations/storage/bucket.rb} +3 -3
- data/lib/barruun/managers/bigquery/dataset.rb +20 -0
- data/lib/barruun/managers/logging/sink.rb +20 -0
- data/lib/barruun/managers/storage/bucket.rb +20 -0
- data/lib/barruun/managers/utils.rb +32 -0
- data/lib/barruun/version.rb +1 -1
- metadata +9 -21
- data/lib/barruun/logging/sink.rb +0 -18
- data/lib/barruun/storage/bucket.rb +0 -18
- data/lib/barruun/utils.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 687ee635c9dd48bbdef5a5aa4d9e41e6b7d527c93da7f67a197c5a41f2458384
|
4
|
+
data.tar.gz: '068eb03f2e78b5ee3df8ad20ee3eae5e69af6f84af0fc70b9c5494e738bf5af9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7722426c4de439a7159db04d4f30fd2035c521455e2c3b210c1ae75cddaff59c2bf21be687db230141d325e27049523eecc12cd71c205c4411e61033913399c
|
7
|
+
data.tar.gz: 50cdc30a34cfe43d59b9d0c38141c4d0dfd15b90e9caacfa092bbd20932b5e806528c606f622c485594bbaf84425f5a1a8ba80434b61e673a0e7ada95ba97cd7
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
barruun (0.1.
|
5
|
-
active_hash
|
4
|
+
barruun (0.1.6)
|
6
5
|
thor (~> 1.1)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
|
-
active_hash (3.1.0)
|
12
|
-
activesupport (>= 5.0.0)
|
13
|
-
activesupport (7.0.1)
|
14
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
-
i18n (>= 1.6, < 2)
|
16
|
-
minitest (>= 5.1)
|
17
|
-
tzinfo (~> 2.0)
|
18
|
-
concurrent-ruby (1.1.9)
|
19
10
|
diff-lcs (1.5.0)
|
20
|
-
i18n (1.8.11)
|
21
|
-
concurrent-ruby (~> 1.0)
|
22
|
-
minitest (5.15.0)
|
23
11
|
power_assert (1.1.7)
|
24
12
|
rake (13.0.6)
|
25
13
|
rspec (3.10.0)
|
@@ -39,8 +27,6 @@ GEM
|
|
39
27
|
rspec (>= 2.14)
|
40
28
|
rspec-support (3.10.3)
|
41
29
|
thor (1.2.1)
|
42
|
-
tzinfo (2.0.4)
|
43
|
-
concurrent-ruby (~> 1.0)
|
44
30
|
webrick (1.7.0)
|
45
31
|
yard (0.9.27)
|
46
32
|
webrick (~> 1.7.0)
|
data/README.md
CHANGED
@@ -62,6 +62,21 @@ bucket-level: 'on'
|
|
62
62
|
location: us-central1
|
63
63
|
```
|
64
64
|
|
65
|
+
### BigQuery
|
66
|
+
|
67
|
+
```
|
68
|
+
Commands:
|
69
|
+
barruun bigquery dataset [FILEPATH] # Create dataset
|
70
|
+
barruun bigquery help [COMMAND] # Describe subcommands or one specific subcommand
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Dataset
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
name: foobar
|
77
|
+
location: asia-northeast1
|
78
|
+
```
|
79
|
+
|
65
80
|
## Development
|
66
81
|
|
67
82
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/barruun.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
"
|
13
13
|
spec.description = "Barruun is a simple tool for Infrastructure as Code of Google Cloud Platform using `gcloud` command.
|
14
14
|
"
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
16
|
|
17
17
|
spec.metadata["source_code_uri"] = "https://github.com/colorfulcompany/barruun"
|
18
18
|
|
@@ -26,5 +26,4 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
28
|
spec.add_runtime_dependency "thor", "~> 1.1"
|
29
|
-
spec.add_runtime_dependency "active_hash"
|
30
29
|
end
|
data/lib/barruun/cli.rb
CHANGED
@@ -2,16 +2,23 @@ require "thor"
|
|
2
2
|
|
3
3
|
module Barruun
|
4
4
|
class StorageCommand < Thor
|
5
|
-
desc "bucket [FILEPATH]", "Create
|
5
|
+
desc "bucket [FILEPATH]", "Create bucket"
|
6
6
|
def bucket(file_path)
|
7
|
-
Barruun::Storage::Bucket.new(file_path).call
|
7
|
+
Barruun::Managers::Storage::Bucket.new(file_path).call
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
class LoggingCommand < Thor
|
12
|
-
desc "sink [FILEPATH]", "Create
|
12
|
+
desc "sink [FILEPATH]", "Create sink"
|
13
13
|
def sink(file_path)
|
14
|
-
Barruun::Logging::Sink.new(file_path).call
|
14
|
+
Barruun::Managers::Logging::Sink.new(file_path).call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class BigqueryCommand < Thor
|
19
|
+
desc "dataset [FILEPATH]", "Create dataset"
|
20
|
+
def sink(file_path)
|
21
|
+
Barruun::Managers::Bigquery::Dataset.new(file_path).call
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
@@ -22,5 +29,6 @@ module Barruun
|
|
22
29
|
|
23
30
|
register(StorageCommand, 'storage', 'storage <command>', 'Manage Cloud Storage')
|
24
31
|
register(LoggingCommand, 'logging', 'logging <command>', 'Manage Cloud Logging')
|
32
|
+
register(BigqueryCommand, 'bigquery', 'bigquery <command>', 'Manage BigQuery')
|
25
33
|
end
|
26
34
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Barruun
|
2
|
+
module Configurations
|
3
|
+
module Bigquery
|
4
|
+
class Dataset
|
5
|
+
def initialize(hash)
|
6
|
+
@hash = hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
@hash["name"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def options
|
14
|
+
@hash.reject { |k| ["name"].include?(k) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
module Barruun
|
2
|
-
module
|
3
|
-
|
4
|
-
class
|
2
|
+
module Configurations
|
3
|
+
module Logging
|
4
|
+
class Sink
|
5
|
+
class ProjectIDNotProvidedError < RuntimeError; end
|
6
|
+
|
5
7
|
def initialize(hash, project_id = ENV["PROJECT_ID"])
|
6
8
|
@hash = hash
|
7
9
|
@project_id = project_id
|
10
|
+
|
11
|
+
if @project_id.nil?
|
12
|
+
raise ProjectIDNotProvidedError, "Project ID not provided"
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def name
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "../../configurations/bigquery/dataset"
|
2
|
+
require_relative "../utils"
|
3
|
+
|
4
|
+
module Barruun
|
5
|
+
module Managers
|
6
|
+
module Bigquery
|
7
|
+
class Dataset
|
8
|
+
include Barruun::Managers::Utils
|
9
|
+
|
10
|
+
def create
|
11
|
+
`bq #{location_string} mk --dataset #{options_string(@config.options)} #{@config.name}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def exist?
|
15
|
+
`bq ls`.include?(@config.name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "../../configurations/logging/sink"
|
2
|
+
require_relative "../utils"
|
3
|
+
|
4
|
+
module Barruun
|
5
|
+
module Managers
|
6
|
+
module Logging
|
7
|
+
class Sink
|
8
|
+
include Barruun::Managers::Utils
|
9
|
+
|
10
|
+
def create
|
11
|
+
`gcloud logging sinks create #{@config.name} #{@config.destination} #{options_string(@config.options)}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def exist?
|
15
|
+
`gcloud logging sinks list --filter='name: #{@config.name}'`.include?(@config.name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "../../configurations/storage/bucket"
|
2
|
+
require_relative "../utils"
|
3
|
+
|
4
|
+
module Barruun
|
5
|
+
module Managers
|
6
|
+
module Storage
|
7
|
+
class Bucket
|
8
|
+
include Barruun::Managers::Utils
|
9
|
+
|
10
|
+
def create
|
11
|
+
`gcloud alpha storage buckets create #{options_string(@config.options)} #{@config.name}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def exist?
|
15
|
+
`gcloud alpha storage buckets list --filter='name: #{@config.name}'`.include?(@config.name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Barruun
|
4
|
+
module Managers
|
5
|
+
module Utils
|
6
|
+
def self.included(obj)
|
7
|
+
obj.const_set('ConfigFileLoadError', Class.new(RuntimeError))
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(file_path, config_klass = Object.const_get("#{self.class.name.gsub("Managers", "Configurations")}"))
|
11
|
+
@file_path = file_path
|
12
|
+
if !File.exists?(@file_path)
|
13
|
+
raise self.class::ConfigFileLoadError, "Error loading config file: #{file_path}"
|
14
|
+
end
|
15
|
+
@config = config_klass.new(YAML.load_file(file_path))
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
if exist?
|
20
|
+
puts "#{self.class.name} #{@config.name} already exists. Nothing to do."
|
21
|
+
else
|
22
|
+
puts "#{self.class.name} #{@config.name} not found."
|
23
|
+
create
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def options_string(options)
|
28
|
+
options.map { |k, v| "--#{k}=#{v}" }.compact.join(" ")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/barruun/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barruun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cc-kawakami
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: active_hash
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
description: 'Barruun is a simple tool for Infrastructure as Code of Google Cloud
|
42
28
|
Platform using `gcloud` command.
|
43
29
|
|
@@ -60,11 +46,13 @@ files:
|
|
60
46
|
- exe/barruun
|
61
47
|
- lib/barruun.rb
|
62
48
|
- lib/barruun/cli.rb
|
63
|
-
- lib/barruun/
|
64
|
-
- lib/barruun/logging/sink
|
65
|
-
- lib/barruun/storage/bucket.rb
|
66
|
-
- lib/barruun/
|
67
|
-
- lib/barruun/
|
49
|
+
- lib/barruun/configurations/bigquery/dataset.rb
|
50
|
+
- lib/barruun/configurations/logging/sink.rb
|
51
|
+
- lib/barruun/configurations/storage/bucket.rb
|
52
|
+
- lib/barruun/managers/bigquery/dataset.rb
|
53
|
+
- lib/barruun/managers/logging/sink.rb
|
54
|
+
- lib/barruun/managers/storage/bucket.rb
|
55
|
+
- lib/barruun/managers/utils.rb
|
68
56
|
- lib/barruun/version.rb
|
69
57
|
homepage:
|
70
58
|
licenses: []
|
@@ -78,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
66
|
requirements:
|
79
67
|
- - ">="
|
80
68
|
- !ruby/object:Gem::Version
|
81
|
-
version: 2.
|
69
|
+
version: 2.5.0
|
82
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
71
|
requirements:
|
84
72
|
- - ">="
|
data/lib/barruun/logging/sink.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "./sink/config"
|
2
|
-
require_relative "../utils"
|
3
|
-
|
4
|
-
module Barruun
|
5
|
-
module Logging
|
6
|
-
class Sink
|
7
|
-
include Barruun::Utils
|
8
|
-
|
9
|
-
def create
|
10
|
-
`gcloud logging sinks create #{@config.name} #{@config.destination} #{options_string}`
|
11
|
-
end
|
12
|
-
|
13
|
-
def exist?
|
14
|
-
`gcloud logging sinks list --filter='name: #{@config.name}'`.include?(@config.name)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "./bucket/config"
|
2
|
-
require_relative "../utils"
|
3
|
-
|
4
|
-
module Barruun
|
5
|
-
module Storage
|
6
|
-
class Bucket
|
7
|
-
include Barruun::Utils
|
8
|
-
|
9
|
-
def create
|
10
|
-
system("gcloud alpha storage buckets create #{options_string} #{@config.name}")
|
11
|
-
end
|
12
|
-
|
13
|
-
def exist?
|
14
|
-
`gcloud alpha storage buckets list --filter='name: #{@config.name}'`.include?(@config.name)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/barruun/utils.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
|
-
module Barruun
|
4
|
-
module Utils
|
5
|
-
def initialize(file_path, config_klass = self.class::Config)
|
6
|
-
@file_path = file_path
|
7
|
-
@config = config_klass.new(YAML.load_file(file_path))
|
8
|
-
end
|
9
|
-
|
10
|
-
def call
|
11
|
-
if exist?
|
12
|
-
puts "#{self.class.name} #{@config.name} already exists. Nothing to do."
|
13
|
-
else
|
14
|
-
puts "#{self.class.name} #{@config.name} not found."
|
15
|
-
create
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def options_string
|
20
|
-
@config.options.map { |k, v| "--#{k}=#{v}" }.compact.join(" ")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|