barruun 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +63 -0
- data/README.md +67 -0
- data/Rakefile +13 -0
- data/barruun.gemspec +28 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/barruun +5 -0
- data/lib/barruun/base.rb +21 -0
- data/lib/barruun/cli.rb +26 -0
- data/lib/barruun/logging/sink/config.rb +24 -0
- data/lib/barruun/logging/sink.rb +15 -0
- data/lib/barruun/storage/bucket/config.rb +19 -0
- data/lib/barruun/storage/bucket.rb +18 -0
- data/lib/barruun/version.rb +5 -0
- data/lib/barruun.rb +8 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e1fa2933b604341ff43216307219cc5f831cb78e1f50e692a8704414a1fb4c4c
|
4
|
+
data.tar.gz: 91897fdba7e08e3d193528d4c2ee8ea1d7a2d3be5e261fe0f12b2b1161b7bcd1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55ea9cf94b0a5e500ee548b2e82525d27dd0c792bfdffba702bbd994f87aeca4cc1d52458c6cc27c4da4f99732f796a8d51c993f838e0a933eab99086a4aa92a
|
7
|
+
data.tar.gz: d0c105c3d7da2b1fdcd25bbdb2bb20a9ddb68912ce51af16e01c91dc21edaf968f30e6594a81cac5730a19a87267139ecb18d2a5c6290fe08bda3db480751ee8
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
barruun (0.1.0)
|
5
|
+
active_hash
|
6
|
+
thor (~> 1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
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
|
+
diff-lcs (1.5.0)
|
20
|
+
i18n (1.8.11)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
minitest (5.15.0)
|
23
|
+
power_assert (1.1.7)
|
24
|
+
rake (13.0.6)
|
25
|
+
rspec (3.10.0)
|
26
|
+
rspec-core (~> 3.10.0)
|
27
|
+
rspec-expectations (~> 3.10.0)
|
28
|
+
rspec-mocks (~> 3.10.0)
|
29
|
+
rspec-core (3.10.1)
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-expectations (3.10.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-mocks (3.10.2)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-power_assert (1.1.0)
|
38
|
+
power_assert (~> 1.1.0)
|
39
|
+
rspec (>= 2.14)
|
40
|
+
rspec-support (3.10.3)
|
41
|
+
thor (1.2.1)
|
42
|
+
tzinfo (2.0.4)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
webrick (1.7.0)
|
45
|
+
yard (0.9.27)
|
46
|
+
webrick (~> 1.7.0)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
x86_64-darwin-20
|
50
|
+
x86_64-linux
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
barruun!
|
54
|
+
rake (~> 13.0)
|
55
|
+
rspec
|
56
|
+
rspec-power_assert
|
57
|
+
yard
|
58
|
+
|
59
|
+
RUBY VERSION
|
60
|
+
ruby 3.0.3p157
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.2.32
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Barruun
|
2
|
+
|
3
|
+
Barruun is a simple tool for Infrastructure as Code of Google Cloud Platform using `gcloud` command.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'barruun'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install barruun
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
Commands:
|
25
|
+
barruun help [COMMAND] # Describe available commands or one specific command
|
26
|
+
barruun logging <command> # Manage Cloud Logging.
|
27
|
+
barruun storage <command> # Manage Cloud Storage.
|
28
|
+
```
|
29
|
+
|
30
|
+
### Logging
|
31
|
+
|
32
|
+
```
|
33
|
+
Commands:
|
34
|
+
barruun logging help [COMMAND] # Describe subcommands or one specific subcommand
|
35
|
+
barruun logging sink [FILEPATH] # Create or update sink.
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Sink
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
name: foobar
|
42
|
+
destination: bigquery.googleapis.com/projects/#{project_id}/datasets/test
|
43
|
+
log-filter: 'jsonPayload."event-data":*'
|
44
|
+
```
|
45
|
+
|
46
|
+
### Storage
|
47
|
+
|
48
|
+
```
|
49
|
+
Commands:
|
50
|
+
barruun storage bucket [FILEPATH] # Create or update bucket.
|
51
|
+
barruun storage help [COMMAND] # Describe subcommands or one specific subcommand
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Bucket
|
55
|
+
|
56
|
+
```yaml
|
57
|
+
name: foobarbox
|
58
|
+
class: regional
|
59
|
+
bucket-level: 'on'
|
60
|
+
location: us-central1
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
data/barruun.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/barruun/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "barruun"
|
7
|
+
spec.version = Barruun::VERSION
|
8
|
+
spec.authors = ["cc-kawakami"]
|
9
|
+
spec.email = ["kawakami-moeki@colorfulcompany.co.jp"]
|
10
|
+
|
11
|
+
spec.summary = "Setup Google Cloud Platform"
|
12
|
+
spec.description = "Setup Google Cloud Platform"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/colorfulcompany/barruun"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "thor", "~> 1.1"
|
27
|
+
spec.add_runtime_dependency "active_hash"
|
28
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "barruun"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/barruun
ADDED
data/lib/barruun/base.rb
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
data/lib/barruun/cli.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module Barruun
|
4
|
+
class StorageCommand < Thor
|
5
|
+
desc "bucket [FILEPATH]", "Create or update bucket"
|
6
|
+
def bucket(file_path)
|
7
|
+
Barruun::Storage::Bucket.new(file_path).call
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class LoggingCommand < Thor
|
12
|
+
desc "sink [FILEPATH]", "Create or update sink"
|
13
|
+
def sink(file_path)
|
14
|
+
Barruun::Logging::Sink.new(file_path).call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class CLI < Thor
|
19
|
+
def self.exit_on_failure?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
register(StorageCommand, 'storage', 'storage <command>', 'Manage Cloud Storage')
|
24
|
+
register(LoggingCommand, 'logging', 'logging <command>', 'Manage Cloud Logging')
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Barruun
|
2
|
+
module Logging
|
3
|
+
class Sink
|
4
|
+
class Config
|
5
|
+
def initialize(hash, project_id = ENV["PROJECT_ID"])
|
6
|
+
@hash = hash
|
7
|
+
@project_id = project_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@hash["name"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def destination
|
15
|
+
@hash["destination"].gsub("\#\{project_id\}", @project_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
@hash.reject { |k, v| %w(name destination).include?(k) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
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.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barruun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cc-kawakami
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
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
|
+
description: Setup Google Cloud Platform
|
42
|
+
email:
|
43
|
+
- kawakami-moeki@colorfulcompany.co.jp
|
44
|
+
executables:
|
45
|
+
- barruun
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rspec"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- barruun.gemspec
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- exe/barruun
|
58
|
+
- lib/barruun.rb
|
59
|
+
- lib/barruun/base.rb
|
60
|
+
- 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
|
65
|
+
- lib/barruun/version.rb
|
66
|
+
homepage:
|
67
|
+
licenses: []
|
68
|
+
metadata:
|
69
|
+
source_code_uri: https://github.com/colorfulcompany/barruun
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.6.0
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.2.32
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Setup Google Cloud Platform
|
89
|
+
test_files: []
|