cl-magic 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -3
- data/README.md +1 -189
- data/bin/install_gem +81 -0
- data/lib/cl/magic/cl +22 -4
- data/lib/cl/magic/cl-auth +53 -3
- data/lib/cl/magic/cl-dk +29 -12
- data/lib/cl/magic/cl-envkey +12 -2
- data/lib/cl/magic/cl-gc-sql +1 -0
- data/lib/cl/magic/cl-gc-tags +1 -0
- data/lib/cl/magic/cl-glab-commit +2 -1
- data/lib/cl/magic/cl-history +1 -0
- data/lib/cl/magic/cl-kube-cp +1 -0
- data/lib/cl/magic/cl-kube-deployment +1 -0
- data/lib/cl/magic/cl-kube-ktx +1 -0
- data/lib/cl/magic/cl-kube-logs +1 -0
- data/lib/cl/magic/cl-kube-restart +1 -0
- data/lib/cl/magic/cl-kube-search +1 -0
- data/lib/cl/magic/cl-kube-search-all +1 -0
- data/lib/cl/magic/cl-kube-ssh +1 -0
- data/lib/cl/magic/cl-poll +1 -0
- data/lib/cl/magic/cl-sandbox +1 -0
- data/lib/cl/magic/cl-vault +1 -0
- data/lib/cl/magic/version.rb +1 -1
- metadata +3 -4
- data/lib/cl/magic/cl-aws-okta-auth +0 -52
- data/lib/cl/magic/cl-aws-okta-env +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59e560fb715bdcd247aea92b23e9c580eae68acfefb3e7e30460eefe66f2c6e0
|
4
|
+
data.tar.gz: 971cfba6bc9c1f23ab642361c8dd1fe5bb1f1dba51d685d80d4807083e8bb8fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f309a92da4cf9daa7ee3463dbeb558ef5b1c41c9227b5b71c098d98b0df5753714f24d28e329eaa568a06ae98a358256114416914b284340b5bfee5b31e2fd6
|
7
|
+
data.tar.gz: 90291922b6d70dc189f6a8c72da32c45242ed3c84d3305698e3cb8f7f829680ed71f02121fd0ae10d677d5855db524683eb4b7d94382d5e1b2969a710bc60f89
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cl-magic (0.3.
|
4
|
+
cl-magic (0.3.5)
|
5
5
|
optparse-subcommand
|
6
6
|
pastel
|
7
7
|
tty-command
|
@@ -34,7 +34,6 @@ GEM
|
|
34
34
|
wisper (2.0.1)
|
35
35
|
|
36
36
|
PLATFORMS
|
37
|
-
arm64-darwin-21
|
38
37
|
ruby
|
39
38
|
|
40
39
|
DEPENDENCIES
|
@@ -44,4 +43,4 @@ DEPENDENCIES
|
|
44
43
|
rake (~> 13.0)
|
45
44
|
|
46
45
|
BUNDLED WITH
|
47
|
-
2.
|
46
|
+
2.1.4
|
data/README.md
CHANGED
@@ -20,192 +20,4 @@ cd $MAGIC_DIR bundle install --path=vendor
|
|
20
20
|
|
21
21
|
# symlink
|
22
22
|
ln -s $MAGIC_DIR/bin/cl /usr/local/bin
|
23
|
-
```
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
TODO: Write usage instructions here
|
28
|
-
|
29
|
-
## Development
|
30
|
-
|
31
|
-
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.
|
32
|
-
|
33
|
-
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).
|
34
|
-
|
35
|
-
# OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
|
36
|
-
|
37
|
-
# Terminal
|
38
|
-
|
39
|
-
* `sudo nano /etc/motd`
|
40
|
-
* add some [ascii art](https://www.asciiart.eu/) to bring you joy
|
41
|
-
* make your prompt not suck PROMPT='\w $ '
|
42
|
-
* or [customize the prompt](https://ss64.com/bash/syntax-prompt.html) yourself
|
43
|
-
|
44
|
-
## IOS
|
45
|
-
|
46
|
-
Install [iTerm2](https://iterm2.com/) and fix the coloring
|
47
|
-
|
48
|
-
By adding the following to your `.zshrc`
|
49
|
-
|
50
|
-
```
|
51
|
-
export CLICOLOR=1
|
52
|
-
export TERM=xterm-256color
|
53
|
-
```
|
54
|
-
|
55
|
-
Install [homebrew](https://brew.sh/)
|
56
|
-
|
57
|
-
# Useful packages
|
58
|
-
|
59
|
-
Install the basics: `jq git vim`
|
60
|
-
* mac `the_silver_searcher`
|
61
|
-
* linux `silversearcher-ag`
|
62
|
-
|
63
|
-
## IOS
|
64
|
-
|
65
|
-
Database clients
|
66
|
-
|
67
|
-
```
|
68
|
-
brew install libpq
|
69
|
-
brew link --force libpq
|
70
|
-
brew install mysql-client
|
71
|
-
```
|
72
|
-
|
73
|
-
Github CLI
|
74
|
-
|
75
|
-
```
|
76
|
-
brew install gh
|
77
|
-
```
|
78
|
-
|
79
|
-
## Linux
|
80
|
-
|
81
|
-
Database clients
|
82
|
-
|
83
|
-
```
|
84
|
-
sudo apt-get install default-mysql-client postgresql-client
|
85
|
-
```
|
86
|
-
|
87
|
-
Github CLI
|
88
|
-
|
89
|
-
* [install instructions](https://github.com/cli/cli/blob/trunk/docs/install_linux.md)
|
90
|
-
|
91
|
-
# Editor
|
92
|
-
|
93
|
-
[VSCode](https://code.visualstudio.com/)
|
94
|
-
|
95
|
-
# Docker
|
96
|
-
|
97
|
-
Install docker
|
98
|
-
|
99
|
-
* [docker desktop](https://docs.docker.com/get-docker/)
|
100
|
-
* [docker on linux](https://docs.docker.com/engine/install/debian/)
|
101
|
-
|
102
|
-
Resources
|
103
|
-
|
104
|
-
* go to your docker desktop -> preferences -> resources and set CPU=5 and Memory 10GB
|
105
|
-
* give it a healthy amount of resources if you don't like waiting and want to avoid Error 137
|
106
|
-
* Remember to "apply & restart" or restart with `sudo systemctl restart docker`
|
107
|
-
|
108
|
-
# Git
|
109
|
-
Often pre-installed, but you need to configure it by editing `~/.gitconfig`
|
110
|
-
|
111
|
-
```
|
112
|
-
[user]
|
113
|
-
email = you@domain.com
|
114
|
-
name = First Last
|
115
|
-
[core]
|
116
|
-
excludesfile = ~/.gitignore
|
117
|
-
[alias]
|
118
|
-
map = log --pretty=oneline --abbrev-commit --graph --all
|
119
|
-
ls = log --graph --pretty=oneline --abbrev-commit
|
120
|
-
[pull]
|
121
|
-
rebase = true
|
122
|
-
[init]
|
123
|
-
defaultBranch = main
|
124
|
-
[log]
|
125
|
-
abbrevcommit = yes
|
126
|
-
[fetch]
|
127
|
-
prune = true
|
128
|
-
```
|
129
|
-
|
130
|
-
# SSH key
|
131
|
-
|
132
|
-
* generate a key with `ssh-keygen`, if you don't already have one?
|
133
|
-
* go with the default name `id_rsa` and give it a password
|
134
|
-
* then cat `~/.ssh/id_rsa.pub` and copy the contents to github settings ssh keys
|
135
|
-
|
136
|
-
# Cloud tools
|
137
|
-
|
138
|
-
## Install gcloud
|
139
|
-
|
140
|
-
* confirm python works `python3 --version`; if not install it `brew install python3`.
|
141
|
-
* then follow instructions: [Install the Google Cloud CLI](https://cloud.google.com/sdk/docs/install-sdk)
|
142
|
-
* when you `gcloud init`, you'll need to know your project name and zone
|
143
|
-
|
144
|
-
## K8 tools
|
145
|
-
|
146
|
-
Install [kubectl](https://kubernetes.io/docs/tasks/tools/)
|
147
|
-
|
148
|
-
Install Krew
|
149
|
-
* Kubectl [has plugins](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) and
|
150
|
-
* the [krew plugin manager](https://krew.sigs.k8s.io/) helps you install them.
|
151
|
-
* Use the [quickstart to install krew](https://krew.sigs.k8s.io/docs/user-guide/setup/install/#bash).
|
152
|
-
|
153
|
-
K8 Logs
|
154
|
-
|
155
|
-
* [stern](https://github.com/wercker/stern) is a must have tool for reading logs
|
156
|
-
* install with `kubectl krew install stern`
|
157
|
-
|
158
|
-
## HashiCorp Vault & Terraform
|
159
|
-
|
160
|
-
Linux users follow instructions on [terraform.io]](https://www.terraform.io/cli/install/apt)
|
161
|
-
|
162
|
-
IOS instructions
|
163
|
-
|
164
|
-
```
|
165
|
-
brew tap hashicorp/tap
|
166
|
-
brew install hashicorp/tap/vault
|
167
|
-
brew install hashicorp/tap/terraform
|
168
|
-
```
|
169
|
-
|
170
|
-
# Programming
|
171
|
-
|
172
|
-
## Node
|
173
|
-
|
174
|
-
[nodenv](https://github.com/nodenv/nodenv) - manage different versions of node
|
175
|
-
* NOTE: sometimes we install ancient versions with nodenv and that requires python2
|
176
|
-
* you’ll have it by using the ENV variable (ex. `PYENV_VERSION=2.7.15 nodenv install some_ancient_version`)
|
177
|
-
|
178
|
-
## Ruby
|
179
|
-
|
180
|
-
[rbenv](https://github.com/rbenv/rbenv) - manage different versions of ruby
|
181
|
-
|
182
|
-
# Magic Tools
|
183
|
-
|
184
|
-
Correct version of ruby
|
185
|
-
|
186
|
-
```
|
187
|
-
rbenv install 2.7.5
|
188
|
-
```
|
189
|
-
|
190
|
-
Clone the repo and install the tools
|
191
|
-
|
192
|
-
```
|
193
|
-
bundle install --path=vendor
|
194
|
-
```
|
195
|
-
|
196
|
-
Symlink so it's available everywhere
|
197
|
-
|
198
|
-
```
|
199
|
-
sudo ln -s $(pwd)/bin/cl /usr/local/bin/cl
|
200
|
-
```
|
201
|
-
|
202
|
-
## DK command
|
203
|
-
|
204
|
-
For the dk command you’ll want an alias
|
205
|
-
|
206
|
-
```
|
207
|
-
echo alias dk=\"cl dk\" >> ~/.zshrc
|
208
|
-
source ~/.zshrc
|
209
|
-
```
|
210
|
-
|
211
|
-
You’ll want to ignore the generated .cl-dk.yaml that this command creates so `echo ".cl-dk.yml" >> ~/.gitignore`
|
23
|
+
```
|
data/bin/install_gem
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
|
4
|
+
#
|
5
|
+
# Detect Ruby
|
6
|
+
#
|
7
|
+
|
8
|
+
has_ruby=$(ruby -v)
|
9
|
+
if [[ $has_ruby != *"2.7.5"* ]]; then
|
10
|
+
echo ""
|
11
|
+
echo "(missing) ruby 2.7.5"
|
12
|
+
echo "Please install ruby 2.7.5"
|
13
|
+
exit 1
|
14
|
+
else
|
15
|
+
echo ""
|
16
|
+
echo "✅ Ruby 2.7.5"
|
17
|
+
fi
|
18
|
+
|
19
|
+
#
|
20
|
+
# Detect Gem
|
21
|
+
#
|
22
|
+
|
23
|
+
has_gem=$(gem list | grep cl-magic || true)
|
24
|
+
if [[ $has_gem != *"cl-magic"* ]]; then
|
25
|
+
echo "(missing) cl-magic gem"
|
26
|
+
echo "⌛ installling cl-magic"
|
27
|
+
echo ""
|
28
|
+
gem install cl-magic
|
29
|
+
else
|
30
|
+
echo "✅ cl-magic gem"
|
31
|
+
echo ""
|
32
|
+
echo "⌛ updating cl-magic"
|
33
|
+
echo ""
|
34
|
+
gem update cl-magic || true
|
35
|
+
fi
|
36
|
+
|
37
|
+
# find magic tools
|
38
|
+
MAGIC_INSTALLED_AT="$(gem info cl-magic | grep Installed | cut -d':' -f2 | xargs)/gems"
|
39
|
+
MAGIC_DIR="$(ls -d1 $MAGIC_INSTALLED_AT/cl-magic-* | tail -1)"
|
40
|
+
|
41
|
+
#
|
42
|
+
# symlink
|
43
|
+
#
|
44
|
+
|
45
|
+
echo ""
|
46
|
+
FILE=/usr/local/bin/cl
|
47
|
+
if test -f "$FILE"; then
|
48
|
+
echo "⌛ removing old symlink"
|
49
|
+
rm $FILE
|
50
|
+
fi
|
51
|
+
echo "⌛ linking 'cl' into /usr/local/bin"
|
52
|
+
ln -s $MAGIC_DIR/bin/cl /usr/local/bin
|
53
|
+
|
54
|
+
#
|
55
|
+
# vendorized gems
|
56
|
+
#
|
57
|
+
|
58
|
+
echo "⌛ installing dependencies"
|
59
|
+
echo ""
|
60
|
+
cd $MAGIC_DIR && bundle install --path=vendor
|
61
|
+
|
62
|
+
#
|
63
|
+
# Complete
|
64
|
+
#
|
65
|
+
|
66
|
+
echo ""
|
67
|
+
echo "✅ tools installed"
|
68
|
+
echo ""
|
69
|
+
echo "IMPORTANT: follow up steps."
|
70
|
+
echo ""
|
71
|
+
|
72
|
+
echo "Step 1: add the 'dk' alias to your bash startup file"
|
73
|
+
echo ""
|
74
|
+
if [[ $SHELL == *"zsh"* ]]; then
|
75
|
+
bash_startup_file="~/.zshrc"
|
76
|
+
else
|
77
|
+
bash_startup_file="~/.bashrc"
|
78
|
+
fi
|
79
|
+
echo " echo \"alias dk='cl dk'\" >> $bash_startup_file"
|
80
|
+
echo " source $bash_startup_file"
|
81
|
+
echo ""
|
data/lib/cl/magic/cl
CHANGED
@@ -21,6 +21,7 @@ def get_command_tree()
|
|
21
21
|
cmd_group = command_tree.fetch('', []) << {
|
22
22
|
cmd: fn_parts.first,
|
23
23
|
filename: filename,
|
24
|
+
description: get_description(filename)
|
24
25
|
}
|
25
26
|
command_tree[''] = cmd_group
|
26
27
|
else
|
@@ -28,6 +29,7 @@ def get_command_tree()
|
|
28
29
|
cmd_group = command_tree.fetch(fn_parts.first, []) << {
|
29
30
|
cmd: fn_parts[1..-1].join('-'),
|
30
31
|
filename: filename,
|
32
|
+
description: get_description(filename)
|
31
33
|
}
|
32
34
|
command_tree[fn_parts.first] = cmd_group
|
33
35
|
end
|
@@ -35,20 +37,33 @@ def get_command_tree()
|
|
35
37
|
return command_tree
|
36
38
|
end
|
37
39
|
|
40
|
+
def get_description(filename)
|
41
|
+
# Optionally, subcommands can put a description on the second line of the file
|
42
|
+
lines = File.readlines(filename)
|
43
|
+
description = if lines[1] && lines[1].strip.start_with?('#')
|
44
|
+
lines[1].strip.gsub(/^#\s*/, '')
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
return description ? description : ""
|
49
|
+
end
|
50
|
+
|
38
51
|
def print_help(banner, command_tree)
|
39
52
|
puts banner
|
40
53
|
command_tree.keys.sort.each do |group|
|
54
|
+
prefix = group.empty? ? "" : " "
|
41
55
|
puts ""
|
42
56
|
puts group unless group.empty?
|
43
57
|
sorted_commands = command_tree[group].sort_by{|h| h[:cmd]}
|
44
|
-
print_commands(sorted_commands)
|
58
|
+
print_commands(sorted_commands, prefix)
|
45
59
|
end
|
46
60
|
puts ""
|
47
61
|
end
|
48
62
|
|
49
63
|
def print_commands(commands, prefix=' ')
|
64
|
+
just_len = 20 - prefix.length
|
50
65
|
commands.sort_by{|h| h[:cmd]}.each do |cmd_hash|
|
51
|
-
puts "#{prefix}#{cmd_hash[:cmd]}"
|
66
|
+
puts "#{prefix}#{cmd_hash[:cmd].ljust(just_len)} #{cmd_hash[:description]}"
|
52
67
|
end
|
53
68
|
end
|
54
69
|
|
@@ -60,9 +75,12 @@ def execute_subcommand(subcommand, command_tree)
|
|
60
75
|
commands = command_tree[''] # global command?
|
61
76
|
else
|
62
77
|
commands = command_tree.fetch(subcommand, [])
|
63
|
-
|
64
|
-
if
|
78
|
+
sub_subcommand = ARGV.shift if commands.any? # next part of command
|
79
|
+
if sub_subcommand.nil?
|
80
|
+
puts ""
|
81
|
+
puts "#{subcommand}"
|
65
82
|
print_commands(commands)
|
83
|
+
puts ""
|
66
84
|
exit(0)
|
67
85
|
end
|
68
86
|
end
|
data/lib/cl/magic/cl-auth
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Need to login to something? Check here first.
|
2
3
|
require 'optparse'
|
3
4
|
require 'optparse/subcommand'
|
4
5
|
require 'tty-command'
|
@@ -10,14 +11,14 @@ require 'cl/magic/common/gcloud.rb'
|
|
10
11
|
require 'cl/magic/common/kubectl.rb'
|
11
12
|
|
12
13
|
@logger = get_logger()
|
13
|
-
@cl_cmd_name = "cl
|
14
|
+
@cl_cmd_name = "cl auth"
|
14
15
|
|
15
16
|
#
|
16
17
|
# Features
|
17
18
|
#
|
18
19
|
|
19
20
|
def auth_gcp_docker(options)
|
20
|
-
write_history("""#{@cl_cmd_name}""")
|
21
|
+
write_history("""#{@cl_cmd_name} gcp-docker""")
|
21
22
|
cmd = "gcloud auth configure-docker"
|
22
23
|
@logger.puts
|
23
24
|
@logger.wait cmd
|
@@ -25,13 +26,45 @@ def auth_gcp_docker(options)
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def github_cli(options)
|
28
|
-
write_history("""#{@cl_cmd_name}""")
|
29
|
+
write_history("""#{@cl_cmd_name} github-cli""")
|
29
30
|
cmd = "gh auth login"
|
30
31
|
@logger.puts
|
31
32
|
@logger.wait cmd
|
32
33
|
exec(cmd)
|
33
34
|
end
|
34
35
|
|
36
|
+
def get_aws_profiles()
|
37
|
+
command = "cat ~/.aws/config | grep 'profile' | cut -d ' ' -f 2 | cut -d ']' -f 1"
|
38
|
+
return TTY::Command.new(:printer => :null).run(command).out.strip.chomp.split(' ').collect {|v|[v]}
|
39
|
+
end
|
40
|
+
|
41
|
+
def aws_okta(options)
|
42
|
+
is_tty = $stdout.isatty
|
43
|
+
|
44
|
+
# pick profile
|
45
|
+
profiles = get_aws_profiles()
|
46
|
+
profile = pick_single_result(profiles, "Pick aws profile", options[:aws_profile])
|
47
|
+
options[:aws_profile] = profile.first
|
48
|
+
|
49
|
+
# history
|
50
|
+
history_command = """#{@cl_cmd_name} aws-okta \\
|
51
|
+
--aws-profile #{options[:aws_profile]}
|
52
|
+
"""
|
53
|
+
write_history(history_command)
|
54
|
+
|
55
|
+
# cmd = "aws-okta add" # old
|
56
|
+
# do work
|
57
|
+
if is_tty
|
58
|
+
puts
|
59
|
+
@logger.info "export into your environment with"
|
60
|
+
puts
|
61
|
+
puts "export $(#{history_command})"
|
62
|
+
else
|
63
|
+
cmd = "aws-okta exec #{options[:aws_profile]} -- env | grep AWS_"
|
64
|
+
exec(cmd)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
35
68
|
#
|
36
69
|
# Options
|
37
70
|
#
|
@@ -62,6 +95,14 @@ github_cli_banner = <<DOC
|
|
62
95
|
|
63
96
|
DOC
|
64
97
|
|
98
|
+
aws_okta_banner = <<DOC
|
99
|
+
|
100
|
+
Authenticate with https://github.com/segmentio/aws-okta
|
101
|
+
|
102
|
+
Usage: #{@cl_cmd_name} aws-okta [options]
|
103
|
+
|
104
|
+
DOC
|
105
|
+
|
65
106
|
global = OptionParser.new do |g|
|
66
107
|
g.banner = global_banner
|
67
108
|
add_help_and_verbose(g)
|
@@ -76,6 +117,15 @@ global = OptionParser.new do |g|
|
|
76
117
|
options[:action] = :github_cli
|
77
118
|
end
|
78
119
|
|
120
|
+
g.subcommand 'aws-okta' do |s|
|
121
|
+
s.banner = aws_okta_banner
|
122
|
+
options[:action] = :aws_okta
|
123
|
+
|
124
|
+
s.on("-p", "--aws-profile PROFILE", "aws profile name in ~/.aws/config") do |v|
|
125
|
+
options[:aws_profile] = v
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
79
129
|
end
|
80
130
|
|
81
131
|
#
|
data/lib/cl/magic/cl-dk
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Turnkey docker development tool
|
2
3
|
require 'yaml'
|
3
4
|
require 'json'
|
4
5
|
require 'tty-command'
|
@@ -16,7 +17,7 @@ require 'cl/magic/common/parse_and_pick.rb'
|
|
16
17
|
#
|
17
18
|
|
18
19
|
def get_base_compose_hash()
|
19
|
-
cmd = "cd #{@working_dir} && docker compose config"
|
20
|
+
cmd = "cd #{@working_dir} && docker compose config 2> /dev/null"
|
20
21
|
return YAML.load(`#{cmd}`)
|
21
22
|
end
|
22
23
|
|
@@ -24,6 +25,18 @@ def get_save_parts_filepath()
|
|
24
25
|
return File.join(@working_dir, ".cl-dk-parts.yml")
|
25
26
|
end
|
26
27
|
|
28
|
+
def get_base_compose_parts_and_make_hashes()
|
29
|
+
compose_hash = get_base_compose_hash()
|
30
|
+
dk_parts_hash = {}
|
31
|
+
dk_make_hash = {}
|
32
|
+
if compose_hash
|
33
|
+
compose_hash = merge_world_files(compose_hash, show_help=ARGV.include?("--help"))
|
34
|
+
dk_parts_hash = compose_hash['x-dk-parts'] ? compose_hash.delete('x-dk-parts') : {}
|
35
|
+
dk_make_hash = compose_hash['x-dk-make'] ? compose_hash.delete('x-dk-make') : {}
|
36
|
+
end
|
37
|
+
return compose_hash, dk_parts_hash, dk_make_hash
|
38
|
+
end
|
39
|
+
|
27
40
|
# world
|
28
41
|
|
29
42
|
def get_repo_basename()
|
@@ -152,11 +165,21 @@ def print_set_world_help()
|
|
152
165
|
end
|
153
166
|
|
154
167
|
def print_set_parts_help()
|
168
|
+
compose_hash, dk_parts_hash, dk_make_hash = get_base_compose_parts_and_make_hashes()
|
169
|
+
|
170
|
+
# print help
|
155
171
|
puts ""
|
156
172
|
puts "Usage: dk [DK_PARTS] set-parts"
|
157
173
|
puts ""
|
158
174
|
puts "Set parts for a project and apply to every 'dk' command"
|
159
175
|
puts ""
|
176
|
+
if dk_parts_hash.keys.any?
|
177
|
+
puts "Parts:"
|
178
|
+
dk_parts_hash.keys.each do |key|
|
179
|
+
print_dk_help_line(key, dk_parts_hash[key].fetch('help'))
|
180
|
+
end
|
181
|
+
puts ""
|
182
|
+
end
|
160
183
|
end
|
161
184
|
|
162
185
|
#
|
@@ -468,19 +491,10 @@ when "set-context"
|
|
468
491
|
when "set-parts"
|
469
492
|
run_dk_set_parts()
|
470
493
|
else
|
471
|
-
|
472
|
-
# get compose settings
|
473
|
-
compose_hash = get_base_compose_hash()
|
494
|
+
compose_hash, dk_parts_hash, dk_make_hash = get_base_compose_parts_and_make_hashes()
|
474
495
|
if compose_hash
|
475
496
|
|
476
|
-
#
|
477
|
-
compose_hash = merge_world_files(compose_hash, show_help=ARGV.include?("--help"))
|
478
|
-
|
479
|
-
# x-dk fragments
|
480
|
-
dk_parts_hash = compose_hash['x-dk-parts'] ? compose_hash.delete('x-dk-parts') : {}
|
481
|
-
dk_make_hash = compose_hash['x-dk-make'] ? compose_hash.delete('x-dk-make') : {}
|
482
|
-
|
483
|
-
# parts
|
497
|
+
# parts & args
|
484
498
|
saved_part_keys = get_saved_parts(dk_parts_hash)
|
485
499
|
compose_args, selected_part_keys = merge_parts_save_and_prep_args(compose_hash, dk_parts_hash, dk_make_hash, saved_part_keys)
|
486
500
|
|
@@ -492,5 +506,8 @@ else
|
|
492
506
|
else
|
493
507
|
run_dk(compose_args)
|
494
508
|
end
|
509
|
+
else
|
510
|
+
@logger.error "no docker configuration found"
|
511
|
+
exit 1
|
495
512
|
end
|
496
513
|
end
|
data/lib/cl/magic/cl-envkey
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Human readable envkeys
|
2
3
|
require 'optparse'
|
3
4
|
require 'optparse/subcommand'
|
4
5
|
require 'tty-command'
|
@@ -17,16 +18,25 @@ require 'cl/magic/common/kubectl.rb'
|
|
17
18
|
#
|
18
19
|
|
19
20
|
def do_work(options)
|
20
|
-
|
21
|
+
cmd = "envkey-source"
|
22
|
+
@logger.wait cmd
|
23
|
+
envkey_str = `cd #{@working_dir} && #{cmd}`
|
24
|
+
|
25
|
+
@logger.wait "making it readable"
|
21
26
|
envkey_array = envkey_str.split(' ')
|
22
27
|
result = if options[:filter]
|
23
28
|
envkey_array.select {|o|
|
24
29
|
o.gsub("'","").start_with? options[:filter]
|
25
30
|
}
|
26
31
|
else
|
32
|
+
@logger.wait "consider using --filter next time"
|
27
33
|
envkey_array
|
28
34
|
end
|
29
|
-
|
35
|
+
|
36
|
+
@logger.puts ""
|
37
|
+
result.each do |r|
|
38
|
+
@logger.puts r
|
39
|
+
end
|
30
40
|
end
|
31
41
|
|
32
42
|
#
|
data/lib/cl/magic/cl-gc-sql
CHANGED
data/lib/cl/magic/cl-gc-tags
CHANGED
data/lib/cl/magic/cl-glab-commit
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Find a gitlab commit and open it up in a browser
|
2
3
|
require 'optparse'
|
3
4
|
require 'optparse/subcommand'
|
4
5
|
require 'tty-command'
|
@@ -18,7 +19,7 @@ require 'cl/magic/common/kubectl.rb'
|
|
18
19
|
|
19
20
|
def do_work(options)
|
20
21
|
cmd = "glab api /projects/:id/repository/commits/#{options[:commit]} | jq .web_url | xargs open"
|
21
|
-
@logger.
|
22
|
+
@logger.wait cmd
|
22
23
|
exec("cd #{@working_dir} && #{cmd}")
|
23
24
|
end
|
24
25
|
|
data/lib/cl/magic/cl-history
CHANGED
data/lib/cl/magic/cl-kube-cp
CHANGED
data/lib/cl/magic/cl-kube-ktx
CHANGED
data/lib/cl/magic/cl-kube-logs
CHANGED
data/lib/cl/magic/cl-kube-search
CHANGED
data/lib/cl/magic/cl-kube-ssh
CHANGED
data/lib/cl/magic/cl-poll
CHANGED
data/lib/cl/magic/cl-sandbox
CHANGED
data/lib/cl/magic/cl-vault
CHANGED
data/lib/cl/magic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cl-magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Najd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -120,13 +120,12 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- bin/cl
|
122
122
|
- bin/console
|
123
|
+
- bin/install_gem
|
123
124
|
- bin/setup
|
124
125
|
- cl-magic.gemspec
|
125
126
|
- lib/cl/magic.rb
|
126
127
|
- lib/cl/magic/cl
|
127
128
|
- lib/cl/magic/cl-auth
|
128
|
-
- lib/cl/magic/cl-aws-okta-auth
|
129
|
-
- lib/cl/magic/cl-aws-okta-env
|
130
129
|
- lib/cl/magic/cl-dk
|
131
130
|
- lib/cl/magic/cl-envkey
|
132
131
|
- lib/cl/magic/cl-gc-sql
|
@@ -1,52 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
|
-
require 'optparse/subcommand'
|
4
|
-
require 'tty-command'
|
5
|
-
require 'tty-prompt'
|
6
|
-
|
7
|
-
require 'cl/magic/common/common_options.rb'
|
8
|
-
require 'cl/magic/common/logging.rb'
|
9
|
-
require 'cl/magic/common/gcloud.rb'
|
10
|
-
require 'cl/magic/common/kubectl.rb'
|
11
|
-
|
12
|
-
@logger = get_logger()
|
13
|
-
@cl_cmd_name = File.basename(__FILE__).split('-').join(' ')
|
14
|
-
|
15
|
-
#
|
16
|
-
# Features
|
17
|
-
#
|
18
|
-
|
19
|
-
def aws_okta(options)
|
20
|
-
write_history("""#{@cl_cmd_name}""")
|
21
|
-
cmd = "aws-okta add"
|
22
|
-
@logger.puts
|
23
|
-
@logger.wait cmd
|
24
|
-
exec(cmd)
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Options
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
options = {}
|
33
|
-
global_banner = <<DOC
|
34
|
-
|
35
|
-
Authenticate with https://github.com/segmentio/aws-okta
|
36
|
-
|
37
|
-
Usage: #{@cl_cmd_name} aws-okta auth [options]
|
38
|
-
|
39
|
-
DOC
|
40
|
-
|
41
|
-
global = OptionParser.new do |g|
|
42
|
-
g.banner = global_banner
|
43
|
-
add_help_and_verbose(g)
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Run
|
48
|
-
#
|
49
|
-
|
50
|
-
global.parse(ARGV)
|
51
|
-
|
52
|
-
aws_okta(options)
|
@@ -1,79 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
|
-
require 'optparse/subcommand'
|
4
|
-
require 'tty-command'
|
5
|
-
require 'tty-prompt'
|
6
|
-
|
7
|
-
require 'cl/magic/common/common_options.rb'
|
8
|
-
require 'cl/magic/common/logging.rb'
|
9
|
-
require 'cl/magic/common/gcloud.rb'
|
10
|
-
require 'cl/magic/common/kubectl.rb'
|
11
|
-
|
12
|
-
@logger = get_logger()
|
13
|
-
@cl_cmd_name = "cl aws okta-env"
|
14
|
-
|
15
|
-
#
|
16
|
-
# Features
|
17
|
-
#
|
18
|
-
|
19
|
-
def get_aws_profiles()
|
20
|
-
command = "cat ~/.aws/config | grep 'profile' | cut -d ' ' -f 2 | cut -d ']' -f 1"
|
21
|
-
return TTY::Command.new(:printer => :null).run(command).out.strip.chomp.split(' ').collect {|v|[v]}
|
22
|
-
end
|
23
|
-
|
24
|
-
def do_work(options)
|
25
|
-
is_tty = $stdout.isatty
|
26
|
-
|
27
|
-
# pick profile
|
28
|
-
profiles = get_aws_profiles()
|
29
|
-
profile = pick_single_result(profiles, "Pick aws profile", options[:aws_profile])
|
30
|
-
options[:aws_profile] = profile.first
|
31
|
-
|
32
|
-
# history
|
33
|
-
history_command = """#{@cl_cmd_name} \\
|
34
|
-
--aws-profile #{options[:aws_profile]}
|
35
|
-
"""
|
36
|
-
write_history(history_command)
|
37
|
-
|
38
|
-
# do work
|
39
|
-
if is_tty
|
40
|
-
puts
|
41
|
-
@logger.info "export into your environment with"
|
42
|
-
puts
|
43
|
-
puts "export $(#{history_command})"
|
44
|
-
else
|
45
|
-
cmd = "aws-okta exec #{options[:aws_profile]} -- env | grep AWS_"
|
46
|
-
exec(cmd)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Options
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
options = {}
|
56
|
-
global_banner = <<DOC
|
57
|
-
|
58
|
-
Fetch environment variables using https://github.com/segmentio/aws-okta
|
59
|
-
|
60
|
-
Usage: #{@cl_cmd_name} aws-okta env [options]
|
61
|
-
|
62
|
-
DOC
|
63
|
-
|
64
|
-
global = OptionParser.new do |g|
|
65
|
-
g.banner = global_banner
|
66
|
-
add_help_and_verbose(g)
|
67
|
-
|
68
|
-
g.on("-p", "--aws-profile PROFILE", "aws profile name in ~/.aws/config") do |v|
|
69
|
-
options[:aws_profile] = v
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
#
|
74
|
-
# Run
|
75
|
-
#
|
76
|
-
|
77
|
-
global.parse(ARGV)
|
78
|
-
|
79
|
-
do_work(options)
|