cl-magic 0.3.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 +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/README.md +211 -0
- data/bin/cl +17 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/cl-magic.gemspec +38 -0
- data/lib/cl/magic/cl +97 -0
- data/lib/cl/magic/cl-auth +109 -0
- data/lib/cl/magic/cl-aws-okta-auth +52 -0
- data/lib/cl/magic/cl-aws-okta-env +79 -0
- data/lib/cl/magic/cl-dk +402 -0
- data/lib/cl/magic/cl-envkey +70 -0
- data/lib/cl/magic/cl-gc-sql +135 -0
- data/lib/cl/magic/cl-gc-tags +171 -0
- data/lib/cl/magic/cl-glab-commit +68 -0
- data/lib/cl/magic/cl-history +44 -0
- data/lib/cl/magic/cl-kube-cp +99 -0
- data/lib/cl/magic/cl-kube-deployment +120 -0
- data/lib/cl/magic/cl-kube-ktx +60 -0
- data/lib/cl/magic/cl-kube-logs +114 -0
- data/lib/cl/magic/cl-kube-restart +84 -0
- data/lib/cl/magic/cl-kube-search +111 -0
- data/lib/cl/magic/cl-kube-search-all +97 -0
- data/lib/cl/magic/cl-kube-ssh +94 -0
- data/lib/cl/magic/cl-poll +51 -0
- data/lib/cl/magic/cl-sandbox +49 -0
- data/lib/cl/magic/cl-vault +84 -0
- data/lib/cl/magic/common/common_options.rb +16 -0
- data/lib/cl/magic/common/gcloud.rb +71 -0
- data/lib/cl/magic/common/kubectl.rb +236 -0
- data/lib/cl/magic/common/logging.rb +25 -0
- data/lib/cl/magic/common/parse_and_pick.rb +81 -0
- data/lib/cl/magic/version.rb +7 -0
- data/lib/cl/magic.rb +9 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 504fca48eea3cb6eca83e8025a98e4f3187f19286b81134b42b53a0a639f2b9b
|
4
|
+
data.tar.gz: 1269ba9642497c4e7541598d3ba180a09b2e5c033627ae9e60cbd545ba3f4e91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b56850adb7d7182d6a72777236902b7b961493f3780c209675c268381c4ccfc78a339ea740f38ed9dd16c2a96f8c102efa24ea3527435699830219b7a5b9e8c9
|
7
|
+
data.tar.gz: a83324b6a355286f9ad2cfaf7b034ca93b710f2706da1fb4e1b61722575a6477e42763d669b082bc72dc308fa5c78195cedaa64c755f9ef4d250f98b36e443b0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cl-magic (0.3.0)
|
5
|
+
optparse-subcommand
|
6
|
+
pastel
|
7
|
+
tty-command
|
8
|
+
tty-logger
|
9
|
+
tty-prompt
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
byebug (11.1.3)
|
15
|
+
minitest (5.18.0)
|
16
|
+
optparse-subcommand (1.0.0)
|
17
|
+
pastel (0.8.0)
|
18
|
+
tty-color (~> 0.5)
|
19
|
+
rake (13.0.6)
|
20
|
+
tty-color (0.6.0)
|
21
|
+
tty-command (0.10.1)
|
22
|
+
pastel (~> 0.8)
|
23
|
+
tty-cursor (0.7.1)
|
24
|
+
tty-logger (0.6.0)
|
25
|
+
pastel (~> 0.8)
|
26
|
+
tty-prompt (0.23.1)
|
27
|
+
pastel (~> 0.8)
|
28
|
+
tty-reader (~> 0.8)
|
29
|
+
tty-reader (0.9.0)
|
30
|
+
tty-cursor (~> 0.7)
|
31
|
+
tty-screen (~> 0.8)
|
32
|
+
wisper (~> 2.0)
|
33
|
+
tty-screen (0.8.1)
|
34
|
+
wisper (2.0.1)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
arm64-darwin-21
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
byebug
|
42
|
+
cl-magic!
|
43
|
+
minitest (~> 5.0)
|
44
|
+
rake (~> 13.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.3.6
|
data/README.md
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
# CL-MAGIC
|
2
|
+
|
3
|
+
Magic tools for a turnkey developer experience.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install cl-magic
|
9
|
+
```
|
10
|
+
|
11
|
+
And make it available everywhere
|
12
|
+
|
13
|
+
```
|
14
|
+
# find magic tools
|
15
|
+
MAGIC_INSTALLED_AT="$(gem info cl-magic | grep Installed | cut -d':' -f2 | xargs)/gems"
|
16
|
+
MAGIC_DIR="$(ls -d1 $MAGIC_INSTALLED_AT/cl-magic-*)"
|
17
|
+
|
18
|
+
# install vendorized gems
|
19
|
+
cd $MAGIC_DIR bundle install --path=vendor
|
20
|
+
|
21
|
+
# symlink
|
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`
|
data/bin/cl
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# know where you were
|
4
|
+
CL_WORKING_DIR="$(pwd)"
|
5
|
+
|
6
|
+
# know where magic happens
|
7
|
+
SOURCE="${BASH_SOURCE[0]}"
|
8
|
+
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
9
|
+
MAGIC_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
10
|
+
SOURCE="$(readlink "$SOURCE")"
|
11
|
+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
12
|
+
done
|
13
|
+
MAGIC_DIR="$( cd -P "$( dirname "$SOURCE" )/../lib/cl/magic" >/dev/null 2>&1 && pwd )"
|
14
|
+
|
15
|
+
# make magic - with the correct version of ruby & the bundle
|
16
|
+
cd $MAGIC_DIR
|
17
|
+
RBENV_VERSION=2.7.5 CL_WORKING_DIR=$CL_WORKING_DIR bundle exec cl $@
|
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 "cl/magic"
|
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/cl-magic.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/cl/magic/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cl-magic"
|
7
|
+
spec.version = Cl::Magic::VERSION
|
8
|
+
spec.authors = ["Don Najd"]
|
9
|
+
spec.email = ["dnajd7@gmail.com"]
|
10
|
+
spec.summary = "Magic tools for a turnkey developer experience"
|
11
|
+
spec.description = ""
|
12
|
+
spec.homepage = "https://gitlab.com/beesbot/cl-magic"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
# metadata
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/beesbot/cl-magic"
|
20
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/beesbot/cl-magic"
|
21
|
+
|
22
|
+
# files
|
23
|
+
spec.files = Dir.glob("{bin,lib}/**/*")
|
24
|
+
spec.files << 'cl-magic.gemspec'
|
25
|
+
spec.files << 'Gemfile'
|
26
|
+
spec.files << 'Gemfile.lock'
|
27
|
+
spec.files << 'README.md'
|
28
|
+
spec.require_path = "lib"
|
29
|
+
|
30
|
+
# dependencies
|
31
|
+
spec.add_development_dependency "rake"
|
32
|
+
spec.add_dependency "optparse-subcommand"
|
33
|
+
spec.add_dependency "tty-logger"
|
34
|
+
spec.add_dependency "tty-command"
|
35
|
+
spec.add_dependency "tty-prompt"
|
36
|
+
spec.add_dependency "pastel"
|
37
|
+
spec.add_development_dependency "byebug"
|
38
|
+
end
|
data/lib/cl/magic/cl
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'tty-command'
|
4
|
+
require 'cl/magic/common/logging.rb'
|
5
|
+
|
6
|
+
|
7
|
+
@logger = get_logger()
|
8
|
+
|
9
|
+
#
|
10
|
+
# Features
|
11
|
+
#
|
12
|
+
|
13
|
+
def get_command_tree()
|
14
|
+
command_tree = {}
|
15
|
+
filenames = Dir.glob('cl-*').select { |e| File.file? e }
|
16
|
+
filenames.each do |filename|
|
17
|
+
fn_parts = filename.split('-')[1..-1]
|
18
|
+
case fn_parts.length
|
19
|
+
when 1
|
20
|
+
# add top level command
|
21
|
+
cmd_group = command_tree.fetch('', []) << {
|
22
|
+
cmd: fn_parts.first,
|
23
|
+
filename: filename,
|
24
|
+
}
|
25
|
+
command_tree[''] = cmd_group
|
26
|
+
else
|
27
|
+
# add nested command
|
28
|
+
cmd_group = command_tree.fetch(fn_parts.first, []) << {
|
29
|
+
cmd: fn_parts[1..-1].join('-'),
|
30
|
+
filename: filename,
|
31
|
+
}
|
32
|
+
command_tree[fn_parts.first] = cmd_group
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return command_tree
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_help(banner, command_tree)
|
39
|
+
puts banner
|
40
|
+
command_tree.keys.sort.each do |group|
|
41
|
+
puts ""
|
42
|
+
puts group unless group.empty?
|
43
|
+
sorted_commands = command_tree[group].sort_by{|h| h[:cmd]}
|
44
|
+
print_commands(sorted_commands)
|
45
|
+
end
|
46
|
+
puts ""
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_commands(commands, prefix=' ')
|
50
|
+
commands.sort_by{|h| h[:cmd]}.each do |cmd_hash|
|
51
|
+
puts "#{prefix}#{cmd_hash[:cmd]}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute_subcommand(subcommand, command_tree)
|
56
|
+
commands = command_tree.fetch(subcommand, [])
|
57
|
+
|
58
|
+
case commands.length
|
59
|
+
when 0
|
60
|
+
commands = command_tree[''] # global command?
|
61
|
+
else
|
62
|
+
commands = command_tree.fetch(subcommand, [])
|
63
|
+
subcommand = ARGV.shift if commands.any? # next part of command
|
64
|
+
if subcommand.nil?
|
65
|
+
print_commands(commands)
|
66
|
+
exit(0)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
cmd = commands.select {|c| c[:cmd]==subcommand}.first
|
70
|
+
final = "bundle exec ./#{cmd[:filename]} #{ARGV.join(' ')}"
|
71
|
+
exec(final)
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Options
|
76
|
+
#
|
77
|
+
|
78
|
+
banner = <<DOC
|
79
|
+
|
80
|
+
Commmand Line Magic Tools
|
81
|
+
|
82
|
+
Usage: cl [sub-command]
|
83
|
+
|
84
|
+
COMMANDS:
|
85
|
+
DOC
|
86
|
+
|
87
|
+
#
|
88
|
+
# Run
|
89
|
+
#
|
90
|
+
|
91
|
+
subcommand = ARGV.shift
|
92
|
+
command_tree = get_command_tree()
|
93
|
+
if subcommand.nil?
|
94
|
+
print_help(banner, command_tree)
|
95
|
+
else
|
96
|
+
execute_subcommand(subcommand, command_tree)
|
97
|
+
end
|
@@ -0,0 +1,109 @@
|
|
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-auth"
|
14
|
+
|
15
|
+
#
|
16
|
+
# Features
|
17
|
+
#
|
18
|
+
|
19
|
+
def auth_gcp_docker(options)
|
20
|
+
write_history("""#{@cl_cmd_name}""")
|
21
|
+
cmd = "gcloud auth configure-docker"
|
22
|
+
@logger.puts
|
23
|
+
@logger.wait cmd
|
24
|
+
exec(cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
def github_cli(options)
|
28
|
+
write_history("""#{@cl_cmd_name}""")
|
29
|
+
cmd = "gh auth login"
|
30
|
+
@logger.puts
|
31
|
+
@logger.wait cmd
|
32
|
+
exec(cmd)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Options
|
37
|
+
#
|
38
|
+
|
39
|
+
|
40
|
+
options = {}
|
41
|
+
global_banner = <<DOC
|
42
|
+
|
43
|
+
Authenticate things from the command line
|
44
|
+
|
45
|
+
Usage: #{@cl_cmd_name} [options]
|
46
|
+
|
47
|
+
DOC
|
48
|
+
|
49
|
+
gcp_docker_banner = <<DOC
|
50
|
+
|
51
|
+
Authenticate with google cloud docker
|
52
|
+
|
53
|
+
Usage: #{@cl_cmd_name} gcp-docker [options]
|
54
|
+
|
55
|
+
DOC
|
56
|
+
|
57
|
+
github_cli_banner = <<DOC
|
58
|
+
|
59
|
+
Authenticate with https://cli.github.com/
|
60
|
+
|
61
|
+
Usage: #{@cl_cmd_name} github-cli [options]
|
62
|
+
|
63
|
+
DOC
|
64
|
+
|
65
|
+
aws_okta_banner = <<DOC
|
66
|
+
|
67
|
+
Authenticate with https://github.com/segmentio/aws-okta
|
68
|
+
|
69
|
+
Usage: #{@cl_cmd_name} aws-okta [options]
|
70
|
+
|
71
|
+
DOC
|
72
|
+
|
73
|
+
global = OptionParser.new do |g|
|
74
|
+
g.banner = global_banner
|
75
|
+
add_help_and_verbose(g)
|
76
|
+
|
77
|
+
g.subcommand 'gcp-docker' do |s|
|
78
|
+
s.banner = gcp_docker_banner
|
79
|
+
options[:action] = :gcp_docker
|
80
|
+
end
|
81
|
+
|
82
|
+
g.subcommand 'github-cli' do |s|
|
83
|
+
s.banner = github_cli_banner
|
84
|
+
options[:action] = :github_cli
|
85
|
+
end
|
86
|
+
|
87
|
+
g.subcommand 'aws-okta' do |s|
|
88
|
+
s.banner = aws_okta_banner
|
89
|
+
options[:action] = :aws_okta
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Run
|
96
|
+
#
|
97
|
+
|
98
|
+
global.parse(ARGV)
|
99
|
+
|
100
|
+
case options[:action]
|
101
|
+
when :gcp_docker
|
102
|
+
auth_gcp_docker(options)
|
103
|
+
when :github_cli
|
104
|
+
github_cli(options)
|
105
|
+
when :aws_okta
|
106
|
+
aws_okta(options)
|
107
|
+
else
|
108
|
+
puts global.parse! %w[--help]
|
109
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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)
|
@@ -0,0 +1,79 @@
|
|
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)
|