gleis 0.2.0 → 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 +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/gleis.rb +2 -0
- data/lib/gleis/auth_key.rb +50 -0
- data/lib/gleis/authentication.rb +3 -16
- data/lib/gleis/cli/auth.rb +6 -3
- data/lib/gleis/cli/auth_key.rb +21 -0
- data/lib/gleis/main.rb +1 -1
- data/lib/gleis/ssh.rb +6 -6
- data/lib/gleis/utils.rb +14 -5
- data/lib/gleis/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2481657ba18d0dc9d1c9c159ffd3057158ae6febb5aeb234ff1d17d9c26607d3
|
4
|
+
data.tar.gz: 5b2a4ad6053130dd3c4c8fb1381835c6d430df696a89cc556e2ad8466968fe08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abb5525578089f01e36cfcb20a63f546e5f0fcefb7dfd605aab827474119d393fc9d5fd6ed77a16f3642217284582fb78c55f6f19c4fbc13dacd78e950ad0aee
|
7
|
+
data.tar.gz: 1f7354bd6d77d462d3384e41dbc5419ee19f682c79571bbc9a80be8434073caa4413418043bd8937dd45b92bbcf6ed218bfb97ce426ee6c3d9ae3924cd600380
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,18 @@ All notable changes to the Gleis CLI will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## 0.3.0 - 2018-12-10
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Comment when adding new Host entry in user git config file
|
13
|
+
- Management of SSH public keys for the authentication with git server using "auth key" sub-commands
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Generation of exec parameters for supporting additional future storage types
|
18
|
+
- Possibility to enter login password as command parameter for automation to bypass interactive password prompt
|
19
|
+
|
8
20
|
## 0.2.0 - 2018-12-02
|
9
21
|
|
10
22
|
### Added
|
data/lib/gleis.rb
CHANGED
@@ -3,8 +3,10 @@ require 'gleis/authentication'
|
|
3
3
|
require 'gleis/addon'
|
4
4
|
require 'gleis/api'
|
5
5
|
require 'gleis/application'
|
6
|
+
require 'gleis/auth_key'
|
6
7
|
require 'gleis/cli/addon'
|
7
8
|
require 'gleis/cli/app'
|
9
|
+
require 'gleis/cli/auth_key'
|
8
10
|
require 'gleis/cli/auth'
|
9
11
|
require 'gleis/cli/db'
|
10
12
|
require 'gleis/cli/domain'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Gleis
|
2
|
+
# The class implements the methods required to manage git authentication keys
|
3
|
+
class AuthKey
|
4
|
+
def self.add(key_file, key_name = nil, run_server = false)
|
5
|
+
token = Token.check
|
6
|
+
abort("SSH public key file #{key_file} does not exist.") unless File.exist?(key_file)
|
7
|
+
ssh_public_key = SSH.load_public_key(key_file)
|
8
|
+
body = API.request('post', 'keys', token, 'key' => ssh_public_key, 'name' => key_name, 'run_server' => run_server)
|
9
|
+
if body['success'] == 1
|
10
|
+
puts "Successfully uploaded your SSH public key #{key_file}"
|
11
|
+
SSH.add_host_to_config(body['git_server'], key_file.gsub(/\.pub$/, ''))
|
12
|
+
# Get run server name and add Host to SSH config
|
13
|
+
if run_server
|
14
|
+
params = Params.get_cli_parameters(token)
|
15
|
+
SSH.add_host_to_config(params['run_server'], key_file.gsub(/\.pub$/, ''))
|
16
|
+
end
|
17
|
+
else
|
18
|
+
puts "Failed to upload SSH public key: #{body['message']}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.list
|
23
|
+
token = Token.check
|
24
|
+
body = API.request('get', 'keys', token)
|
25
|
+
keys = body ['data']
|
26
|
+
if keys.any?
|
27
|
+
puts "SSH public keys configured for your account:\n\n"
|
28
|
+
printf("\t%-39s %s\n", 'KEY NAME', 'CREATED ON')
|
29
|
+
printf("\t%-39s %s\n", 'PUBLIC KEY', '----------')
|
30
|
+
printf("\t%-39s\n\n", '----------')
|
31
|
+
keys.each do |_id, key|
|
32
|
+
printf("\t%-39s %s\n", key['title'], Time.parse(key['created_at']).localtime.strftime('%c'))
|
33
|
+
printf("\t%s\n\n", key['key'])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts 'No keys found.'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.remove(key_name)
|
41
|
+
token = Token.check
|
42
|
+
body = API.request('delete', "keys/#{CGI.escape(key_name)}", token)
|
43
|
+
if body['success'] == 1
|
44
|
+
puts 'Successfully removed SSH public key'
|
45
|
+
else
|
46
|
+
puts "Failed to remove SSH public key: #{body['message']}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/gleis/authentication.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Gleis
|
2
2
|
# This class implements all authentication related commands of the CLI
|
3
3
|
class Authentication
|
4
|
-
def self.login(username)
|
4
|
+
def self.login(username, password = nil)
|
5
5
|
puts 'Login to Gleis'
|
6
6
|
username = username.downcase
|
7
|
-
password
|
7
|
+
password ||= Utils.prompt_password
|
8
8
|
|
9
9
|
body = API.request('post', 'login', nil, 'username': username, 'password': password)
|
10
10
|
token = body['token']
|
@@ -14,7 +14,7 @@ module Gleis
|
|
14
14
|
puts "\nNEWS: #{body['data']}\n\n" unless body['data'].nil?
|
15
15
|
# Generate SSH key pair if not found and upload pub key
|
16
16
|
ssh_key_filename = Config::SSH_KEY_FILE_BASE + '_' + Utils.convert_username_to_filename(username)
|
17
|
-
|
17
|
+
AuthKey.add("#{ssh_key_filename}.pub", nil, true) if SSH.generate_key(ssh_key_filename, username)
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.register(email)
|
@@ -59,18 +59,5 @@ module Gleis
|
|
59
59
|
Token.delete
|
60
60
|
puts 'Logout successful'
|
61
61
|
end
|
62
|
-
|
63
|
-
def self.upload_ssh_public_key(filename, token)
|
64
|
-
ssh_public_key = SSH.load_public_key(filename)
|
65
|
-
body = API.request('post', 'upload_ssh_pub_key', token, 'ssh_public_key' => ssh_public_key)
|
66
|
-
if body['success'] == 1
|
67
|
-
puts "Successfully uploaded your SSH public key #{filename}.pub"
|
68
|
-
# Get run server name
|
69
|
-
params = Params.get_cli_parameters(token)
|
70
|
-
SSH.add_host_to_config(body['git_server'], params['run_server'], filename)
|
71
|
-
else
|
72
|
-
puts "Failed to upload SSH public key: #{body['message']}"
|
73
|
-
end
|
74
|
-
end
|
75
62
|
end
|
76
63
|
end
|
data/lib/gleis/cli/auth.rb
CHANGED
@@ -2,9 +2,12 @@ module Gleis
|
|
2
2
|
module CLI
|
3
3
|
# Authentication-related CLI commands
|
4
4
|
class Auth < Thor
|
5
|
-
desc '
|
6
|
-
|
7
|
-
|
5
|
+
desc 'key COMMAND', 'Manage git public keys: add, list, remove'
|
6
|
+
subcommand 'key', CLI::AuthKey
|
7
|
+
|
8
|
+
desc 'login USERNAME [PASSWORD]', 'Login into Gleis'
|
9
|
+
def login(username, password = nil)
|
10
|
+
Authentication.login(username, password)
|
8
11
|
end
|
9
12
|
|
10
13
|
desc 'logout', 'Logout of Gleis'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Gleis
|
2
|
+
module CLI
|
3
|
+
# Git authentication key related CLI commands
|
4
|
+
class AuthKey < Thor
|
5
|
+
desc 'add FILENAME [KEYNAME]', 'Add SSH public key file for git authentication'
|
6
|
+
def add(key_file, key_name = nil)
|
7
|
+
Gleis::AuthKey.add(key_file, key_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'list', 'List all SSH public keys allowed for git authentication'
|
11
|
+
def list
|
12
|
+
Gleis::AuthKey.list
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'remove KEYNAME', 'Remove SSH public key from git authentication'
|
16
|
+
def remove(key_name)
|
17
|
+
Gleis::AuthKey.remove(key_name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/gleis/main.rb
CHANGED
@@ -20,7 +20,7 @@ module Gleis
|
|
20
20
|
desc 'app COMMAND', 'Manage applications: create, start, stop, logs, etc.'
|
21
21
|
subcommand 'app', CLI::App
|
22
22
|
|
23
|
-
desc 'auth COMMAND', 'Authentication commands: login, logout, whoami'
|
23
|
+
desc 'auth COMMAND', 'Authentication commands: key, login, logout, whoami'
|
24
24
|
subcommand 'auth', CLI::Auth
|
25
25
|
|
26
26
|
desc 'db COMMAND', 'Manage databases: info, new, promote, psql, etc.'
|
data/lib/gleis/ssh.rb
CHANGED
@@ -16,20 +16,20 @@ module Gleis
|
|
16
16
|
"-C generated by Gleis CLI for #{username} by #{ENV['USER']}@#{hostname} on #{datetime}")
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.load_public_key(
|
20
|
-
public_key_file = key_file + '.pub'
|
19
|
+
def self.load_public_key(public_key_file)
|
21
20
|
return File.read(public_key_file).chomp if File.exist?(public_key_file)
|
22
21
|
end
|
23
22
|
|
24
|
-
def self.add_host_to_config(
|
23
|
+
def self.add_host_to_config(host_name, private_key_file)
|
25
24
|
config_file = Dir.home + '/.ssh/config'
|
26
|
-
ssh_host_line = "Host #{
|
25
|
+
ssh_host_line = "Host #{host_name}"
|
27
26
|
# Check if SSH config for hosts already exists
|
28
|
-
return if Utils.line_exists_in_file(
|
27
|
+
return if Utils.line_exists_in_file(config_file, ssh_host_line)
|
29
28
|
|
30
29
|
f = File.open(config_file, 'a')
|
30
|
+
f.puts "\n# Added by Gleis CLI on #{Time.now.strftime('%Y-%m-%d %H:%M')}"
|
31
31
|
f.puts ssh_host_line
|
32
|
-
f.puts "\tIdentityFile #{
|
32
|
+
f.puts "\tIdentityFile #{private_key_file}"
|
33
33
|
f.close
|
34
34
|
end
|
35
35
|
end
|
data/lib/gleis/utils.rb
CHANGED
@@ -92,14 +92,23 @@ module Gleis
|
|
92
92
|
def self.generate_exec_mount_param(body, app_name)
|
93
93
|
mount_param = ''
|
94
94
|
if body['success'] == 1
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
95
|
+
if body['data']['storage'].any?
|
96
|
+
storage = body['data']['storage'].pop
|
97
|
+
storage_type = get_storage_type_by_name(body['data']['storage_types'], storage['storage_type_name'])
|
98
|
+
if storage_type
|
99
|
+
mount_src = "#{storage_type['mount_source']}/#{body['data']['namespace']}/#{app_name}"
|
100
|
+
mount_param = "--mount type=#{storage_type['mount_type']},src=#{mount_src},dst=#{storage['mount_target']}"
|
101
|
+
end
|
100
102
|
end
|
101
103
|
end
|
102
104
|
mount_param
|
103
105
|
end
|
106
|
+
|
107
|
+
def self.get_storage_type_by_name(storage_types, name)
|
108
|
+
storage_types.each do |storage_type|
|
109
|
+
return storage_type if storage_type['name'] == name
|
110
|
+
end
|
111
|
+
nil
|
112
|
+
end
|
104
113
|
end
|
105
114
|
end
|
data/lib/gleis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gleis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Bigler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.20.0
|
125
125
|
description: Command-line interface to deploy and manage your Rails apps on the Swiss
|
126
|
-
PaaS
|
126
|
+
PaaS https://gleis.cloud
|
127
127
|
email:
|
128
128
|
- gleis@towards.ch
|
129
129
|
executables:
|
@@ -140,10 +140,12 @@ files:
|
|
140
140
|
- lib/gleis/addon.rb
|
141
141
|
- lib/gleis/api.rb
|
142
142
|
- lib/gleis/application.rb
|
143
|
+
- lib/gleis/auth_key.rb
|
143
144
|
- lib/gleis/authentication.rb
|
144
145
|
- lib/gleis/cli/addon.rb
|
145
146
|
- lib/gleis/cli/app.rb
|
146
147
|
- lib/gleis/cli/auth.rb
|
148
|
+
- lib/gleis/cli/auth_key.rb
|
147
149
|
- lib/gleis/cli/db.rb
|
148
150
|
- lib/gleis/cli/domain.rb
|
149
151
|
- lib/gleis/cli/management.rb
|
@@ -185,5 +187,5 @@ rubyforge_project:
|
|
185
187
|
rubygems_version: 2.7.6
|
186
188
|
signing_key:
|
187
189
|
specification_version: 4
|
188
|
-
summary: Gleis CLI to deploy and manage Rails apps on Gleis PaaS
|
190
|
+
summary: Gleis CLI to deploy and manage Rails apps on the Gleis PaaS
|
189
191
|
test_files: []
|