barruun 0.1.1 → 0.1.5

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: 64f304a776a79c69b23f954502e22e6b0ec84808dcf5bb8448fd3574fde4d692
4
- data.tar.gz: 0eeabbcb7f812219d92f6b0105a50c2189eaafbb1e9e1494104a6b86f49414c5
3
+ metadata.gz: 9decd7dacebba1fb4656151f53f93ffb9eb40e50d11cf2857d94f8c39a91dcb3
4
+ data.tar.gz: 288089cad737ee2aeab66e9ca916b0b06d8cc2418da2b9fe2a0560016b2a7be2
5
5
  SHA512:
6
- metadata.gz: 6241c035c3b74444334fd115d5b8376749a5cb338ec7d639103778045ead094e906a552c56fc8f97a422631c94e7d36293b36e97d23f8462d504a45c2f76b561
7
- data.tar.gz: 0e2b71e50c8e641cc88501c2fb25ed9b660f81a0cead88e6e708dfcd9252a4312c1180fadbbe4c8bbfa7e0c1cddf59499e1dd61ff5003666876a05d8ada27d97
6
+ metadata.gz: 80b36585f4e4b397208992ea82ed2ab90ed98147b5a37535f419ddb5b24f06ce619be1533dfae3fffa0fe9da0f76986eca1a6769d3ca0a76dac33374bc75da41
7
+ data.tar.gz: e7b8efa49ae874feb0f6e72f3fbc45dff60923209a072a60dc74724972b65ec79d42e6c1f2bd1a4ade594b2651fa89e2e1185d631a0143e19d799c10f0c590d6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barruun (0.1.1)
4
+ barruun (0.1.5)
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/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 or update bucket"
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 or update sink"
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 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/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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Barruun
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.5"
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.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cc-kawakami
@@ -60,11 +60,13 @@ files:
60
60
  - exe/barruun
61
61
  - lib/barruun.rb
62
62
  - lib/barruun/cli.rb
63
- - lib/barruun/logging/sink.rb
64
- - lib/barruun/logging/sink/config.rb
65
- - lib/barruun/storage/bucket.rb
66
- - lib/barruun/storage/bucket/config.rb
67
- - lib/barruun/utils.rb
63
+ - lib/barruun/configurations/bigquery/dataset.rb
64
+ - lib/barruun/configurations/logging/sink.rb
65
+ - lib/barruun/configurations/storage/bucket.rb
66
+ - lib/barruun/managers/bigquery/dataset.rb
67
+ - lib/barruun/managers/logging/sink.rb
68
+ - lib/barruun/managers/storage/bucket.rb
69
+ - lib/barruun/managers/utils.rb
68
70
  - lib/barruun/version.rb
69
71
  homepage:
70
72
  licenses: []
@@ -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
data/lib/barruun/utils.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} already exists. Nothing to do."
11
- else
12
- puts "#{self.class.name} #{@config.name} not found."
13
- create
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