vps_cli 0.1.4

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
+ SHA256:
3
+ metadata.gz: a0e19909989845fd3c3a95b31f5f025d8f47369c17a0ad1f9b7b8d8ba79d1b37
4
+ data.tar.gz: f889b50b324d113cd785dae1e9c5c3768ab12984fce81796d362a398dd9abf34
5
+ SHA512:
6
+ metadata.gz: ed9fc281ebb3054329678be63293a8c21486dac410579d51605851fbb5dc071d984f15e9548355983aa87cb69efc4d0984cfa2848b27db1307ba50d5d87866c0
7
+ data.tar.gz: 37746dfe75d5275ad634e534742d4e3459ba80fb794a285d6be330dfacdfc84df12add713f9768822ca5f65536878e6ea69c1d9bbc0e101a821e4571b2cea179
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /tags
11
+ *.log*
12
+
13
+ *logs*
14
+ /.tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vps_cli.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vps_cli (0.1.4)
5
+ thor (~> 0.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ ffi (1.10.0)
12
+ formatador (0.2.5)
13
+ guard (2.15.0)
14
+ formatador (>= 0.2.4)
15
+ listen (>= 2.7, < 4.0)
16
+ lumberjack (>= 1.0.12, < 2.0)
17
+ nenv (~> 0.1)
18
+ notiffany (~> 0.0)
19
+ pry (>= 0.9.12)
20
+ shellany (~> 0.0)
21
+ thor (>= 0.18.1)
22
+ guard-compat (1.2.1)
23
+ guard-minitest (2.4.6)
24
+ guard-compat (~> 1.2)
25
+ minitest (>= 3.0)
26
+ listen (3.1.5)
27
+ rb-fsevent (~> 0.9, >= 0.9.4)
28
+ rb-inotify (~> 0.9, >= 0.9.7)
29
+ ruby_dep (~> 1.2)
30
+ lumberjack (1.0.13)
31
+ method_source (0.9.2)
32
+ minitest (5.11.3)
33
+ nenv (0.3.0)
34
+ notiffany (0.1.1)
35
+ nenv (~> 0.1)
36
+ shellany (~> 0.0)
37
+ pry (0.12.2)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ rake (10.5.0)
41
+ rb-fsevent (0.10.3)
42
+ rb-inotify (0.10.0)
43
+ ffi (~> 1.0)
44
+ ruby_dep (1.5.0)
45
+ shellany (0.0.1)
46
+ thor (0.20.3)
47
+ yard (0.9.19)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 2.0)
54
+ guard (~> 2.15)
55
+ guard-minitest (~> 2.4)
56
+ minitest (~> 5.0)
57
+ rake (~> 10.0)
58
+ vps_cli!
59
+ yard (~> 0.9)
60
+
61
+ BUNDLED WITH
62
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 paramagicdev
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,72 @@
1
+ # VpsCli
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vps_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ This gem is currently unfinished and purely for my own personal use.
6
+ This project of pulling and pushing dotfiles as well as performing installations
7
+ etc has taken many iterations and this is its 3rd iteration
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'vps_cli', git: 'https://github.com/ParamagicDev/vps_cli'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install vps_cli
24
+
25
+ ## Usage
26
+
27
+ This is a personal gem intended to help keep dotfiles the and packages
28
+ the same across installations
29
+
30
+ General usage is as follows:
31
+
32
+ ```bash
33
+ vps-cli init
34
+ ```
35
+
36
+ This will create a .vps_cli file in your home folder.
37
+
38
+ You should check out the contents of this file because this will provide
39
+ the defaults used for configuration
40
+
41
+ This opens up further commands like:
42
+
43
+ ```bash
44
+ vps-cli pull
45
+ # pulls in all the dotfiles to your specified dotfiles and misc_files
46
+
47
+ vps-cli copy
48
+ # copies all the dotfiles and misc files to your specified local_dir
49
+
50
+ vps-cli git_pull
51
+ # pulls in changes to your config_files directory
52
+
53
+ vps-cli git_push
54
+ # pushes changes in your config_files directory
55
+
56
+ vps-cli
57
+ # will list all available commands
58
+ ```
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vps_cli.
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test_task) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task :import_pgp_key do
13
+ puts "Importing sops_testing_keys.asc...\n\n"
14
+ sh('gpg -q --import sops_testing_key.asc')
15
+ puts ""
16
+ end
17
+
18
+ task test: %i[import_pgp_key test_task]
19
+
20
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vps_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
data/bin/vps-cli ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'vps_cli'
5
+
6
+ VpsCli::Cli.start(ARGV)
@@ -0,0 +1,39 @@
1
+ github:
2
+ username: ENC[AES256_GCM,data:QWu5q5V41jA=,iv:mSGsgJqA8umM3Iov5jEmdtlCoqi1G2HZqkAtyvMnra4=,tag:YdgUYCnGkQaN7L7P1bb5BA==,type:str]
3
+ email: ENC[AES256_GCM,data:D56889RUJ6PyZXWXYtZceAM=,iv:pq0NGFRlTBurjL+PNJNgAgTqMOLLHzWKH9XYi76Tjd0=,tag:qin+BiG5jo8ifcdfw8BIoQ==,type:str]
4
+ api_token: ENC[AES256_GCM,data:fM3gSjIWDxq/PJ6wB9N0DmiA,iv:cFKlhPc41wa9EXXdcoyjR6F3kKHqBGnT5G7r8sZBrG8=,tag:SleMk4xyZEa5EhAxu6i/qQ==,type:str]
5
+ heroku_unencrypted:
6
+ - The values of heroku can be obtained from $HOME/.netrc
7
+ - If you have logged in via the following commands before
8
+ - heroku login or heroku login --interactive
9
+ heroku:
10
+ api:
11
+ machine: ENC[AES256_GCM,data:5YPhnneMN0Tz8dOmgQW5IIXqwYrrxA==,iv:lc98tNybmTwn8wvTi2zLBUkiUFQvv5cfX6QQFq3GDgA=,tag:xv/kvlO3n46fyX63/94mkg==,type:str]
12
+ login: ENC[AES256_GCM,data:uD352OlvbHBAdSWdYPoyFQN2Cbvn,iv:JoR8WUjMdeTfgwOoXCFv/hOJjZE17xwez8bWoeenUj0=,tag:Tj8zqaNVVxjSecDO4wdY7A==,type:str]
13
+ password: ENC[AES256_GCM,data:gnt+Ku6RhluVhVMlOTXYUQhDLv8x,iv:BchO+5RYoM6yNPJ5jWr6Dcb3nOykH3gUlenuBWy0Niw=,tag:0CFEVfcLIvzE6U3mWcQn/w==,type:str]
14
+ git:
15
+ machine: ENC[AES256_GCM,data:VUmZZfRYBzf5VTavYYzBUVuO5sB9/g==,iv:JZ/GMiNryOvBYmNBsSXFyc3+Y/Z3TlJHuVFkvmr+BIA=,tag:+XbC5wVlAhk38+H0xCMM2Q==,type:str]
16
+ login: ENC[AES256_GCM,data:qbomNJOdE42zEyqQvLRqyitC4kOh,iv:HkcpOWED3ygKsJ1N5//Lhj/DI59MW4QCIOTuXuz7xMk=,tag:rCKVGETjVNdvdq4makkGFg==,type:str]
17
+ password: ENC[AES256_GCM,data:jjif+u2jccL1LY6zvMnPJ6eokTtjbCAhTns=,iv:2HFpvGoa9kghMnrnUWa2gkZXT7Nzrbk6Cq1c2Ac2tRo=,tag:ZouL+57G/mL4HFCoNI8uSA==,type:str]
18
+ sops:
19
+ kms: []
20
+ gcp_kms: []
21
+ azure_kv: []
22
+ lastmodified: '2019-04-04T08:15:58Z'
23
+ mac: ENC[AES256_GCM,data:+SOfo1TYp88Kv7HODrSUkkja7iR0TIdiI+BxQERax5Iw+wrYhrkpcauESvPktWzNAFSNLCLF39JjkN3MsGsq5UcCzv8PoYCXRlbJDagxiH1UWdIniQAaYS96GBqE195QSm8rZbWzRO1TKckMrvBZ8RrYaH889NtqzWt9TDUoCjw=,iv:zvPGaOyrFtXm0x0VaLvOlMZOAGA2JmRuaktfB3vxFus=,tag:sJUU5aSS8ATVf2pGstQ8Ng==,type:str]
24
+ pgp:
25
+ - created_at: '2019-04-04T08:10:01Z'
26
+ enc: |-
27
+ -----BEGIN PGP MESSAGE-----
28
+
29
+ wYwDEEVDpnzXnMABBACHm3C+7xuMCAgWTim8tCwWY/RyNjk3NsOiJSj9XQ1VuI7/
30
+ 3RKOY++j3MR6vHb2LdHsUDHr3+WyKq+uJqX6D600v4ghu/8tDoV03ozqtmucFcW4
31
+ YIv/iS4xlaGRjAMzjvGZpOGdoT68QZd61GIca4JwqShWg9sN/GCAvhKw/Q1RA9Lg
32
+ AeT0ZQDWQ+jhNLYLEf4SOCwN4V9i4G7g8OFFgeAh4hC19QLg0OWlgkIUlR8Vhl2T
33
+ qfIyGtIwAPneQviEqvcZ+ySRGaZ3SeCO5CHU4/p7vzfb/RqNEyBT1/Li9QPiy+Gm
34
+ oQA=
35
+ =AE0i
36
+ -----END PGP MESSAGE-----
37
+ fp: 1022470DE3F0BC54BC6AB62DE05550BC07FB1A0A
38
+ unencrypted_suffix: _unencrypted
39
+ version: 3.2.0
data/exe/vps-cli ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'vps_cli'
5
+
6
+ VpsCli::Cli.start(ARGV)
@@ -0,0 +1,176 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @see https://ruby-doc.org/stdlib-2.6.0.preview2/libdoc/open3/rdoc/Open3.html
4
+ require 'open3'
5
+ require 'json'
6
+ require 'vps_cli/helpers/access_helper'
7
+ require 'vps_cli/helpers/github_http'
8
+
9
+ module VpsCli
10
+ # Used for various things related to logins, ssh keys, etc
11
+ class Access
12
+ extend AccessHelper
13
+ # logs into various things either via a .yaml file or via cmd line
14
+ # Accepts a Configuration object or a hash
15
+ # @see https://github.com/mozilla/sops
16
+ # @see VpsCli::Access#decrypt
17
+ # @see https://github.com/settings/tokens
18
+ # I prefer to use authentication tokens versus sending
19
+ # regular access info
20
+ # @return void
21
+
22
+ # fixing to accept a configuration
23
+ def self.provide_credentials(config = VpsCli.configuration)
24
+ if File.exist?(config.credentials)
25
+ file_login(yaml_file: config.credentials, netrc_file: config.netrc)
26
+ else
27
+ command_line_login
28
+ end
29
+
30
+ # originally accepts an opts arguemnt
31
+ generate_ssh_key
32
+ post_github_ssh_key(config)
33
+ end
34
+
35
+ # Provides all login credentials via a SOPS encrypted yaml file
36
+ # @param yaml_file [File] File formatted in yaml and encrypted with SOPS
37
+ # @param netrc_file [File] ($HOME/.netrc) Location of the .netrc for heroku
38
+ # @return void
39
+ def self.file_login(yaml_file:, netrc_file: nil)
40
+ netrc_file ||= File.join(Dir.home, '.netrc')
41
+ git_file_login(yaml_file: yaml_file)
42
+ heroku_file_login(yaml_file: yaml_file, netrc_file: netrc_file)
43
+ end
44
+
45
+ # Logs in via the command line if no yaml_file given
46
+ def self.command_line_login
47
+ set_git_config
48
+ heroku_login
49
+ end
50
+
51
+ # Sets the .gitconfig file
52
+ # @param username [String] Username to set in .gitconfig
53
+ # @param email [String] email to use for .gitconfig
54
+ # @return void
55
+ def self.set_git_config(username = nil, email = nil)
56
+ puts 'Please enter your git username:'
57
+ username ||= $stdin.gets.chomp
58
+ Rake.sh("git config --global user.name #{username}")
59
+
60
+ puts 'Please enter your email:'
61
+ email ||= $stdin.gets.chomp
62
+ Rake.sh("git config --global user.email #{email}")
63
+
64
+ puts "Git config complete.\n"
65
+ rescue RuntimeError => error
66
+ msg = 'Something went wrong. Make sure to set your .gitconfig manually'
67
+
68
+ VpsCli.errors << error.exception("#{error}\n\n#{msg}")
69
+ end
70
+
71
+ # Command line heroku login
72
+ # @return void
73
+ def self.heroku_login
74
+ puts 'Please login to heroku:'
75
+ Rake.sh('heroku login --interactive')
76
+ rescue RuntimeError => error
77
+ message = "\nUnable not login to heroku. To login, type: 'heroku login'"
78
+ VpsCli.errors << error.exception("#{error}\n\n#{message}")
79
+ end
80
+
81
+ # Logs into git by setting it in your .gitconfig file
82
+ # @param yaml_file [File] Sets your git login via the values in your
83
+ # yaml_file
84
+ # @return nil
85
+ def self.git_file_login(yaml_file:)
86
+ username_key = dig_for_path(:github, :username)
87
+ email_key = dig_for_path(:github, :email)
88
+
89
+ username = decrypt(yaml_file: yaml_file, path: username_key)
90
+ email = decrypt(yaml_file: yaml_file, path: email_key)
91
+
92
+ set_git_config(username, email)
93
+ end
94
+
95
+ # Logs into heroku if given an encrypted yaml_file
96
+ # @param yaml_file [File] The yaml file to be decrypted
97
+ # @param netrc_file [File] The netrc file to write to
98
+ # @return void
99
+ def self.heroku_file_login(yaml_file:, netrc_file: nil)
100
+ netrc_file ||= File.join(Dir.home, '.netrc')
101
+
102
+ api_string = heroku_api_string(yaml_file: yaml_file)
103
+ git_string = heroku_git_string(yaml_file: yaml_file)
104
+
105
+ netrc_string = api_string + "\n" + git_string
106
+
107
+ write_to_netrc(netrc_file: netrc_file, string: netrc_string)
108
+ end
109
+
110
+ # Generates an ssh key with the given values for opts
111
+ # this has not been extensively tested by myself so proceed with caution
112
+ # @param opts [Hash] Options hash
113
+ # @option opts [String] :type ('rsa') What kind of encryption
114
+ # You want for your ssh key
115
+ # @option opts [Fixnum] :bits (4096) Strength of encryption
116
+ # @option opts [String] :email (#get_email) The email comment
117
+ # to add to the end of the ssh key
118
+ # @option opts [String, File] :output_file (~/.ssh/id_rsa)
119
+ # Where you want the key to be saved
120
+ # @option opts [Boolean] :create_password (nil)
121
+ # if true, prompt to create a password
122
+ def self.generate_ssh_key
123
+ o_file = File.join(Dir.home, '.ssh', 'id_rsa')
124
+
125
+ return puts 'ssh key already exists' if File.exist?(o_file)
126
+
127
+ type = 'rsa'
128
+ bits = 4096
129
+ email = get_email
130
+
131
+ no_pass = ' -P ""' unless opts[:create_password]
132
+
133
+ # if opts[:create_password] is false, make a blank password
134
+ # if its true, go through ssh-keygen
135
+ # this will also autoprompt overwrite as well
136
+ cmd = "ssh-keygen -t #{type} -b #{bits} -C #{email} -f #{o_file}#{no_pass}"
137
+ Rake.sh(cmd)
138
+ end
139
+
140
+ # the wrapper around the GithubHTTP class to be able to send the ssh key
141
+ # @param opts [Hash] Options parameter meant for cli usage
142
+ # @option opts [String] :uri (URI('https://api.github.com/user/keys'))
143
+ # url of the api youd like to hit
144
+ # @option opts [File] :yaml_file (nil) the file to decrypt values with.
145
+ #
146
+ def self.post_github_ssh_key(config = VpsCli.configuration)
147
+ uri = URI('https://api.github.com/user/keys')
148
+
149
+ api_token = proc do |yaml, path|
150
+ decrypt(yaml_file: yaml, path: path)
151
+ end
152
+
153
+ api_path = dig_for_path(:github, :api_token)
154
+
155
+ token = api_token.call(config.credentials, api_path)
156
+ ssh_file = File.join(Dir.home, '.ssh', 'id_rsa.pub')
157
+ title = get_title
158
+
159
+ github = GithubHTTP.new(uri: uri, token: token,
160
+ ssh_file: ssh_file, title: title)
161
+ github.push_ssh_key
162
+ end
163
+
164
+ def self.get_email
165
+ puts "\n"
166
+ puts 'please enter an email for your ssh key:'
167
+ $stdin.gets.chomp
168
+ end
169
+
170
+ def self.get_title
171
+ puts "\n"
172
+ puts 'please enter a title for your ssh key'
173
+ $stdin.gets.chomp
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'open3'
5
+
6
+ module VpsCli
7
+ # The CLI component of this library
8
+ # Integrates Thor
9
+ # @see http://whatisthor.com/
10
+ class Cli < Thor
11
+ # this is available as a flag for all methods
12
+ class_option :config, aliases: :c, default: File.join(Dir.home, '.vps_cli')
13
+
14
+ desc 'fresh_install', 'accepts no arguments, my own personal command'
15
+ def fresh_install
16
+ VpsCli.load_configuration(options[:config])
17
+ Copy.all
18
+ Install.all_install
19
+
20
+ Access.provide_credentials
21
+
22
+ VpsCli.errors.each { |error| puts error.message }
23
+ end
24
+
25
+
26
+ desc 'init [-c (File)]', 'Creates a default vps_cli configuration file in the home directory'
27
+ def init(file = options[:config])
28
+ VpsCli.create_configuration(file)
29
+ end
30
+
31
+ desc 'install_gems', 'runs gem install on all gems in packages.rb'
32
+ def install_gems
33
+ Packages::GEMS.each do |g|
34
+ Rake.sh("gem install #{g}")
35
+ end
36
+ end
37
+
38
+ desc 'copy [OPTIONS]', 'Copies files from <vps_cli/config_files>'
39
+ def copy
40
+ VpsCli.load_configuration(options[:config])
41
+ Copy.all
42
+ end
43
+
44
+ desc 'pull [OPTIONS]', 'Pulls files into your vps_cli repo'
45
+ options %i[dotfiles_dir misc_files_dir]
46
+ def pull
47
+ VpsCli.load_configuration(options[:config])
48
+ Pull.all
49
+ end
50
+
51
+ desc 'install [OPTIONS]', 'installs based on the flag provided'
52
+ def install
53
+ msg = puts 'Only VpsCli::Install#all_install has been implemented'
54
+ return msg unless options[:all]
55
+
56
+ Install.all_install
57
+
58
+ return if VpsCli.errors.empty?
59
+
60
+ VpsCli.errors.each do |error|
61
+ if error.responds_to?(:message)
62
+ puts error.message
63
+ else
64
+ puts error
65
+ end
66
+ end
67
+ end
68
+
69
+ desc 'git_pull', 'Automatically pulls in changes in your config_files repo'
70
+ def git_pull
71
+ swap_dir { Rake.sh('git pull') }
72
+ end
73
+
74
+ desc 'git_push [message]', 'Automatically pushes changes of your config_files'
75
+ def git_push(message = nil)
76
+
77
+ message ||= "auto push files"
78
+
79
+ swap_dir do
80
+ Rake.sh('git add -A')
81
+ Rake.sh("git commit -m \"#{message}\"")
82
+ Rake.sh('git push')
83
+ end
84
+ end
85
+
86
+ desc 'git_status', 'provides the status of your config_files'
87
+ def git_status
88
+ swap_dir { Rake.sh('git status') }
89
+ end
90
+
91
+ no_commands do
92
+ def swap_dir
93
+ VpsCli.load_configuration(options[:config])
94
+ Rake.cd(VpsCli.configuration.config_files)
95
+ yield
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VpsCli
4
+ # Used for keeping a consistent config across the entire project
5
+ class Configuration
6
+ # local files
7
+ attr_accessor :local_dir, :backup_dir, :local_sshd_config
8
+ attr_accessor :sshd_backup
9
+
10
+ # configuration files to be used
11
+ attr_accessor :config_files, :misc_files, :dotfiles
12
+ attr_accessor :credentials, :netrc
13
+
14
+ # used for displaying info
15
+ attr_accessor :verbose, :interactive, :testing
16
+
17
+ def initialize
18
+ # Values for items to be copied to
19
+ @local_dir = Dir.home
20
+ @backup_dir = File.join(Dir.home, 'backup_files')
21
+ @local_sshd_config = File.join(Dir.home, '.ssh', 'sshd_config')
22
+ @sshd_backup = File.join(@backup_dir, 'sshd_config.orig')
23
+
24
+ # values for items to be copied from
25
+ # set to nil so that someone must set a path
26
+ @config_files = nil
27
+ @dotfiles = nil
28
+ @misc_files = nil
29
+
30
+ # Location of your SOPS encrypted yaml file
31
+ @credentials = nil
32
+ @netrc = nil
33
+
34
+ # used for displaying info
35
+ @verbose = false
36
+ @interactive = true
37
+ @testing = false
38
+ end
39
+ end
40
+
41
+ def self.configure
42
+ @configuration ||= Configuration.new
43
+ yield(configuration)
44
+ end
45
+
46
+ def self.configuration
47
+ @configuration ||= Configuration.new
48
+ end
49
+
50
+ def self.reset_configuration
51
+ @configuration = Configuration.new
52
+ end
53
+
54
+ def self.load_test_configuration
55
+ test_config = File.join(File.expand_path(__dir__), 'configurations', 'testing_configuration.rb')
56
+ load_configuration(test_config)
57
+ end
58
+
59
+ def self.load_configuration(file = File.join(Dir.home, '.vps_cli'))
60
+ msg = 'Unable to location a configuration file. The default location is'
61
+ msg += '$HOME/.vps_cli'
62
+ msg += "\nTo create a standard default config, run 'vps-cli init'"
63
+
64
+ raise Exception, msg unless File.exist?(file)
65
+
66
+ load file
67
+ end
68
+
69
+ def self.create_configuration(file = File.join(Dir.home, '.vps_cli'))
70
+ msg = "Creating a default configuration files @ $HOME/.vps_cli"
71
+ msg += "\nPlease modify any values that are nil"
72
+
73
+ puts msg
74
+ default_config = File.join(File.expand_path(__dir__), 'configurations', 'default_configuration.rb')
75
+
76
+ Rake.cp(default_config, file)
77
+ end
78
+ end