heroku_cli 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96ddaf84c357baeded58ceb6e9cfd712acf07cc3
4
+ data.tar.gz: d4a9c9a72c2cf2655273947c28cf92b7f5d12b18
5
+ SHA512:
6
+ metadata.gz: 3d248d3d86582092d17bd7634525142aafa1e383b606fefcc7b1dda98a7b12f00ff6a9f02a4396cf5770bca86c8c2fabd50c4d2f7d2bd8975b09ee5384f82025
7
+ data.tar.gz: a331e22d58cd1cb2d3416852b62bc463d7a2a6eb297db610498be6896630226766ebd25d803f76e65144579f26d7c84e9d1e7ace0f28b30e885126e9f4033b8e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rasmus.bergholdt@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in heroku_cli.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Rasmus Bergholdt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # HerokuCLI
2
+
3
+ This gem will wrap the Heroku CLI so it may be used in ruby code
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'heroku_cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install heroku_cli
20
+
21
+ ## Usage
22
+
23
+ Create a new database in staging that follows the production database and promote it to main DB when ready
24
+ ```ruby
25
+ require 'heroku_cli'
26
+
27
+ production = HerokuCLI.application('production')
28
+ production_db = production.pg.main
29
+
30
+ staging = HerokuCLI.application('staging')
31
+ staging.pg.create_follower(production_db)
32
+ staging.pg.wait
33
+ new_db = staging.pg.followers.first
34
+ staging.promote(new_db)
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bergholdt/heroku_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the HerokuCLI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bergholdt/heroku_cli/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "heroku_cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "heroku_cli/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroku_cli"
8
+ spec.version = HerokuCLI::VERSION
9
+ spec.authors = ["Rasmus Bergholdt"]
10
+ spec.email = ["rasmus.bergholdt@gmail.com"]
11
+
12
+ spec.summary = %q{A tiny wrapper for Heroku CLI}
13
+ spec.description = %q{Wrap the Heroku CLI to make it more accessable from your ruby script}
14
+ spec.homepage = "https://github.com/Flightlogger/heroku_cli"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,33 @@
1
+ module HerokuCLI
2
+ class Application
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ # tools and services for developing, extending, and operating your app
10
+ def addons
11
+ []
12
+ end
13
+
14
+ # disables an app feature
15
+ def features
16
+ []
17
+ end
18
+
19
+ # display the current maintenance status of app
20
+ def maintenance
21
+ @maintenance ||= Maintenance.new(self)
22
+ end
23
+
24
+ # manage postgresql databases
25
+ def pg
26
+ @pg ||= PG.new(self)
27
+ end
28
+
29
+ def ps
30
+ @ps ||= ProcessStatus.new(self)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module HerokuCLI
2
+ class Base
3
+ attr_reader :application
4
+
5
+ def initialize(application)
6
+ @application = application.is_a?(String) ? Application.new(application) : application
7
+ end
8
+
9
+ protected
10
+
11
+ def heroku(cmd)
12
+ %x{ heroku #{cmd} -a #{application.name} }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module HerokuCLI
2
+ # Maintenance status of app
3
+ class Maintenance < Base
4
+ # display the current maintenance status of app
5
+ def status
6
+ heroku('maintenance').strip
7
+ end
8
+
9
+ # take the app out of maintenance mode
10
+ def off
11
+ heroku 'maintenance:off'
12
+ end
13
+
14
+ # put the app into maintenance mode
15
+ def on
16
+ heroku 'maintenance:on'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,94 @@
1
+ module HerokuCLI
2
+ class PG < Base
3
+ class Database
4
+ attr_reader :url_name, :info
5
+
6
+ def initialize(info)
7
+ @url_names = info.shift
8
+ @url_names = @url_names.sub('=== ','').split(',').map(&:strip)
9
+ @info = {}
10
+ info.each do |line|
11
+ k = line.split(':')[0].strip
12
+ v = line.split(':')[1..-1].join(':').strip
13
+ next if k.nil? || v.nil?
14
+ @info[k] = v
15
+ end
16
+ end
17
+
18
+ def url_name
19
+ @url_names.first
20
+ end
21
+
22
+ def to_s
23
+ result = ["=== #{@url_names.join(', ')}"]
24
+ result.concat(info.map { |k, v| format("%-22.22s %s", "#{k}:", v)})
25
+ result.concat([''])
26
+ result.join("\n")
27
+ end
28
+
29
+ def name
30
+ @name ||= url_name.gsub(/_URL\z/, '')
31
+ end
32
+
33
+ def plan
34
+ info['Plan'].gsub(' ', '-').downcase
35
+ end
36
+
37
+ def data_size
38
+ info['Data Size']
39
+ end
40
+
41
+ def status
42
+ info['Status']
43
+ end
44
+
45
+ def tables
46
+ info['Tables'].match(/(\d+)/)[0]&.to_i || 0
47
+ end
48
+
49
+ def version
50
+ Gem::Version.new(info['PG Version'])
51
+ end
52
+
53
+ def followers
54
+ info['Followers']
55
+ end
56
+
57
+ def forks
58
+ info['Forks'].split(',').map(&:strip)
59
+ end
60
+
61
+ def following
62
+ info['Following'].strip
63
+ end
64
+
65
+ def main?
66
+ !fork? && @url_names.include?('DATABASE_URL')
67
+ end
68
+
69
+ def fork?
70
+ info.key?('Forks')
71
+ end
72
+
73
+ def follower?
74
+ info.key?('Following')
75
+ end
76
+
77
+ def behind?
78
+ behind_by.positive?
79
+ end
80
+
81
+ def behind_by
82
+ info['Behind By']&.match(/(\d+)/)&.first&.to_i || 0
83
+ end
84
+
85
+ def region
86
+ info['Region']
87
+ end
88
+
89
+ def resource_name
90
+ info['Add-on']
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'pg/database'
2
+
3
+ module HerokuCLI
4
+ # manage postgresql databases
5
+ class PG < Base
6
+ # show database information
7
+ def info
8
+ @info ||= begin
9
+ heroku('pg:info').split("===").reject(&:empty?).map do |stdout|
10
+ next if stdout.nil? || stdout.length.zero?
11
+ stdout = stdout.split("\n")
12
+ stdout[0] = "===#{stdout[0]}"
13
+ Database.new(stdout)
14
+ end
15
+ end
16
+ end
17
+
18
+ # create a follower database
19
+ def create_follower(database, options = {})
20
+ plan = options.delete(:plan) || database.plan
21
+ heroku "addons:create heroku-postgresql:#{plan} --follow #{database.resource_name}"
22
+ end
23
+
24
+ # Remove the following of a database and put DB into write mode
25
+ def un_follow(database)
26
+ raise "Not a following database #{database.name}" unless database.follower?
27
+ heroku "pg:unfollow #{database.url_name} -c #{application.name}"
28
+ end
29
+
30
+ # sets DATABASE as your DATABASE_URL
31
+ def promote(database)
32
+ raise "Database already main #{database.name}" if database.main?
33
+ un_follow(database) if database.follower?
34
+ heroku "pg:promote #{database.resource_name}"
35
+ end
36
+
37
+ def destroy(database)
38
+ raise "Cannot destroy #{application.name} main database" if database.main?
39
+ heroku "addons:destroy #{database.url_name} -c #{application.name}"
40
+ end
41
+
42
+ # Return the main database
43
+ def main
44
+ info.find(&:main?)
45
+ end
46
+
47
+ # Returns an array of allow forks databases
48
+ def forks
49
+ info.find_all(&:fork?)
50
+ end
51
+
52
+ # Returns an array of allow follower databases
53
+ def followers
54
+ info.find_all(&:follower?)
55
+ end
56
+
57
+ # blocks until database is available
58
+ def wait
59
+ heroku 'pg:wait'
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ module HerokuCLI
2
+ # list dynos for an app
3
+ class ProcessStatus < Base
4
+ # restart app dynos
5
+ def restart
6
+ heroku 'ps:restart'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module HerokuCLI
2
+ VERSION = "0.1.0"
3
+ end
data/lib/heroku_cli.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "heroku_cli/version"
2
+ require "heroku_cli/application"
3
+ require "heroku_cli/base"
4
+ require "heroku_cli/maintenance"
5
+ require "heroku_cli/pg"
6
+
7
+ # Wrap the CLI to interact with Heroku
8
+ module HerokuCLI
9
+ # attach to an application
10
+ def self.application(name)
11
+ Application.new(name)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rasmus Bergholdt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Wrap the Heroku CLI to make it more accessable from your ruby script
56
+ email:
57
+ - rasmus.bergholdt@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - heroku_cli.gemspec
73
+ - lib/heroku_cli.rb
74
+ - lib/heroku_cli/application.rb
75
+ - lib/heroku_cli/base.rb
76
+ - lib/heroku_cli/maintenance.rb
77
+ - lib/heroku_cli/pg.rb
78
+ - lib/heroku_cli/pg/database.rb
79
+ - lib/heroku_cli/ps.rb
80
+ - lib/heroku_cli/version.rb
81
+ homepage: https://github.com/Flightlogger/heroku_cli
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.12
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: A tiny wrapper for Heroku CLI
105
+ test_files: []
106
+ has_rdoc: