barruun 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1fa2933b604341ff43216307219cc5f831cb78e1f50e692a8704414a1fb4c4c
4
- data.tar.gz: 91897fdba7e08e3d193528d4c2ee8ea1d7a2d3be5e261fe0f12b2b1161b7bcd1
3
+ metadata.gz: 2b0b9a2fc5b72870179cb35d5c1da70d56253c8ee97df145bf85eac801635b84
4
+ data.tar.gz: 7dafcd4ecb497036a3f44d10f334f41f9a5208acb6643268b1abd49e162b412d
5
5
  SHA512:
6
- metadata.gz: 55ea9cf94b0a5e500ee548b2e82525d27dd0c792bfdffba702bbd994f87aeca4cc1d52458c6cc27c4da4f99732f796a8d51c993f838e0a933eab99086a4aa92a
7
- data.tar.gz: d0c105c3d7da2b1fdcd25bbdb2bb20a9ddb68912ce51af16e01c91dc21edaf968f30e6594a81cac5730a19a87267139ecb18d2a5c6290fe08bda3db480751ee8
6
+ metadata.gz: 7733b651373aed0fc762023acded6e7fcb08dd520ef417798446fcb17ea85a87bcbeea2b5b4661b05382852b9758cdd0dfde42ec3dcbf47a58bc2c3fe7ef71fe
7
+ data.tar.gz: dee542b26955853f065da1977e27d6df4aa609e8f8b5d17d5829d1fdba51e0a3e7bdbbcbae15a112756afe8d773ce65cc6a2186483d03a7a25a143b8c1320f8c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barruun (0.1.0)
4
+ barruun (0.1.4)
5
5
  active_hash
6
6
  thor (~> 1.1)
7
7
 
data/README.md CHANGED
@@ -37,9 +37,11 @@ Commands:
37
37
 
38
38
  #### Sink
39
39
 
40
+ Please set project id to `PROJECT_ID`.
41
+
40
42
  ```yaml
41
43
  name: foobar
42
- destination: bigquery.googleapis.com/projects/#{project_id}/datasets/test
44
+ destination: bigquery.googleapis.com/projects/:PROJECT_ID/datasets/test
43
45
  log-filter: 'jsonPayload."event-data":*'
44
46
  ```
45
47
 
data/barruun.gemspec CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["cc-kawakami"]
9
9
  spec.email = ["kawakami-moeki@colorfulcompany.co.jp"]
10
10
 
11
- spec.summary = "Setup Google Cloud Platform"
12
- spec.description = "Setup Google Cloud Platform"
11
+ spec.summary = "Barruun is a simple tool for Infrastructure as Code of Google Cloud Platform using `gcloud` command.
12
+ "
13
+ spec.description = "Barruun is a simple tool for Infrastructure as Code of Google Cloud Platform using `gcloud` command.
14
+ "
13
15
  spec.required_ruby_version = ">= 2.6.0"
14
16
 
15
17
  spec.metadata["source_code_uri"] = "https://github.com/colorfulcompany/barruun"
data/lib/barruun/cli.rb CHANGED
@@ -4,14 +4,14 @@ module Barruun
4
4
  class StorageCommand < Thor
5
5
  desc "bucket [FILEPATH]", "Create or update 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
12
  desc "sink [FILEPATH]", "Create or update 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
15
  end
16
16
  end
17
17
 
@@ -1,10 +1,16 @@
1
1
  module Barruun
2
- module Logging
3
- class Sink
4
- class Config
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
@@ -12,7 +18,7 @@ module Barruun
12
18
  end
13
19
 
14
20
  def destination
15
- @hash["destination"].gsub("\#\{project_id\}", @project_id)
21
+ @hash["destination"].gsub(":PROJECT_ID", @project_id)
16
22
  end
17
23
 
18
24
  def options
@@ -1,7 +1,7 @@
1
1
  module Barruun
2
- module Storage
3
- class Bucket
4
- class Config
2
+ module Configurations
3
+ module Storage
4
+ class Bucket
5
5
  def initialize(hash)
6
6
  @hash = hash
7
7
  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}`
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.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
28
+ @config.options.map { |k, v| "--#{k}=#{v}" }.compact.join(" ")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Barruun
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
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.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - cc-kawakami
@@ -38,7 +38,10 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Setup Google Cloud Platform
41
+ description: 'Barruun is a simple tool for Infrastructure as Code of Google Cloud
42
+ Platform using `gcloud` command.
43
+
44
+ '
42
45
  email:
43
46
  - kawakami-moeki@colorfulcompany.co.jp
44
47
  executables:
@@ -56,12 +59,12 @@ files:
56
59
  - bin/setup
57
60
  - exe/barruun
58
61
  - lib/barruun.rb
59
- - lib/barruun/base.rb
60
62
  - lib/barruun/cli.rb
61
- - lib/barruun/logging/sink.rb
62
- - lib/barruun/logging/sink/config.rb
63
- - lib/barruun/storage/bucket.rb
64
- - lib/barruun/storage/bucket/config.rb
63
+ - lib/barruun/configurations/logging/sink.rb
64
+ - lib/barruun/configurations/storage/bucket.rb
65
+ - lib/barruun/managers/logging/sink.rb
66
+ - lib/barruun/managers/storage/bucket.rb
67
+ - lib/barruun/managers/utils.rb
65
68
  - lib/barruun/version.rb
66
69
  homepage:
67
70
  licenses: []
@@ -85,5 +88,6 @@ requirements: []
85
88
  rubygems_version: 3.2.32
86
89
  signing_key:
87
90
  specification_version: 4
88
- summary: Setup Google Cloud Platform
91
+ summary: Barruun is a simple tool for Infrastructure as Code of Google Cloud Platform
92
+ using `gcloud` command.
89
93
  test_files: []
data/lib/barruun/base.rb DELETED
@@ -1,21 +0,0 @@
1
- module Barruun
2
- module Utils
3
- def initialize(file_path, config_klass = self.class::Config)
4
- @file_path = file_path
5
- @config = config_klass.new(YAML.load_file(file_path))
6
- end
7
-
8
- def call
9
- if exist?
10
- puts "#{self.class.name} #{@config.name} not found."
11
- create
12
- else
13
- puts "#{self.class.name} #{@config.name} already exists. Nothing to do."
14
- end
15
- end
16
-
17
- def options_string
18
- @config.options.map { |k, v| "--#{k}=#{v}" }.compact.join(" ")
19
- end
20
- end
21
- end
@@ -1,15 +0,0 @@
1
- module Barruun
2
- module Logging
3
- class Sink
4
- include Barruun::Utils
5
-
6
- def create
7
- `gcloud logging sinks create #{@config.name} #{@config.destination} #{options_string}`
8
- end
9
-
10
- def exist?
11
- `gcloud logging sinks list --filter='name: #{@config.name}'`.include?(@config.name)
12
- end
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- require "yaml"
2
- require_relative "./bucket/config"
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