pgai 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/lib/pgai/cli/main.rb +3 -3
- data/lib/pgai/clone_manager.rb +31 -3
- data/lib/pgai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ffc13ccc5cc54a852ba48b245a1f4e470696d622fe499aa5fbce8221e77fa5d
|
4
|
+
data.tar.gz: 6e78ffd141aed55d189bab7c986c11434b8d22fbe4c40b032ddc2074875909fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5457effb587f8f4aeb75b5887cc15c977c736a37459de877ab18c18d8c0fd76e215300f7d46322e56913c398c2e869ec0c461c992aa231ab3b38e3b8bf45b9e
|
7
|
+
data.tar.gz: 4f29dc64c0553db229c009917b2676e9374ddb16b82c79e608588a9be0a655d10e804b2d8ec0566030a6d732a7ccb53c4681e3f53f65a3cb9ba4fcc59e0b3412
|
data/README.md
CHANGED
@@ -18,15 +18,27 @@ For an overview of available commands, execute:
|
|
18
18
|
pgai -h
|
19
19
|
```
|
20
20
|
|
21
|
-
Before usage `pgai config` must be executed and at least an environment must be configured with `pgai env add
|
21
|
+
Before usage `pgai config` must be executed and at least an environment must be configured with `pgai env add`.
|
22
22
|
|
23
|
-
|
23
|
+
An access token will be required and it can be obtained from: https://console.postgres.ai/gitlab/tokens
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
Configuring the user and identity file for the proxy must be done using the `~/.ssh/config` file. Example:
|
26
|
+
|
27
|
+
```
|
28
|
+
Host <subdomain>.postgres.ai
|
29
|
+
IdentityFile ~/.ssh/id_ed25519
|
30
|
+
User <username>
|
31
|
+
```
|
32
|
+
|
33
|
+
## dblab binary file
|
34
|
+
|
35
|
+
This CLI is built around around the [`dblab`](https://postgres.ai/docs/how-to-guides/cli/cli-install-init) CLI and it looks for it at the following locations:
|
36
|
+
|
37
|
+
- at the path specified in the config file if specified when running the `pgai config` command
|
38
|
+
- in `$PATH`
|
39
|
+
- at `~/.dblab/dblab`
|
40
|
+
|
41
|
+
If it's not found at any of the specified locations, a copy will be downloaded to `~/.dblab/dblab`.
|
30
42
|
|
31
43
|
## Usage
|
32
44
|
|
data/lib/pgai/cli/main.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Pgai::Cli
|
2
2
|
class Main < Base
|
3
3
|
desc "config", "Configure CLI options"
|
4
|
-
method_option :prefix, aliases: "-p", desc: "Specify prefix to be used for clones", required: true
|
5
|
-
method_option :dbname, aliases: "-n", desc: "Specify database name to connect to", required: true
|
4
|
+
method_option :prefix, aliases: "-p", desc: "Specify prefix name to be used for clones", required: true
|
5
|
+
method_option :dbname, aliases: "-n", desc: "Specify database name to connect to by default", required: true
|
6
6
|
method_option :proxy, aliases: "-x", desc: "Specify proxy host name", required: true
|
7
|
-
method_option :exe, aliases: "-e", desc: "dblab binary
|
7
|
+
method_option :exe, aliases: "-e", desc: "dblab binary path"
|
8
8
|
def config
|
9
9
|
token = ask("Access token:", echo: false)
|
10
10
|
|
data/lib/pgai/clone_manager.rb
CHANGED
@@ -4,10 +4,15 @@ require "shellwords"
|
|
4
4
|
require "socket"
|
5
5
|
require "json"
|
6
6
|
require "securerandom"
|
7
|
+
require "net/http"
|
8
|
+
require "pathname"
|
9
|
+
require "fileutils"
|
7
10
|
|
8
11
|
module Pgai
|
9
12
|
class CloneManager
|
10
13
|
HOSTNAME = "127.0.0.1"
|
14
|
+
DEFAULT_DBLAB = Pathname.new("~/.dblab/dblab").expand_path
|
15
|
+
DBLAB_BINARY_URL = "https://gitlab.com/api/v4/projects/45068363/jobs/4092515399/artifacts/engine/bin/cli/dblab-%{os}-%{cpu}"
|
11
16
|
|
12
17
|
def initialize(environment, config:)
|
13
18
|
@environment = environment
|
@@ -105,14 +110,37 @@ module Pgai
|
|
105
110
|
end
|
106
111
|
|
107
112
|
def dblab(*args, raw: false)
|
108
|
-
|
109
|
-
|
110
|
-
output = `#{args.unshift(executable).shelljoin}`
|
113
|
+
output = `#{args.unshift(dblab_path).shelljoin}`
|
111
114
|
return output if raw
|
112
115
|
|
113
116
|
JSON.parse(output) unless output.empty?
|
114
117
|
end
|
115
118
|
|
119
|
+
def dblab_path
|
120
|
+
return config.path unless config.path.to_s.empty?
|
121
|
+
return "dblab" unless `which dblab`.to_s.empty?
|
122
|
+
return DEFAULT_DBLAB.to_s if DEFAULT_DBLAB.exist?
|
123
|
+
|
124
|
+
download_dblab_to(DEFAULT_DBLAB)
|
125
|
+
File.chmod(0o755, DEFAULT_DBLAB)
|
126
|
+
|
127
|
+
DEFAULT_DBLAB
|
128
|
+
end
|
129
|
+
|
130
|
+
def download_dblab_to(location)
|
131
|
+
platform = Gem::Platform.local
|
132
|
+
uri = URI(DBLAB_BINARY_URL % {os: platform.os, cpu: platform.cpu})
|
133
|
+
|
134
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
135
|
+
http.request Net::HTTP::Get.new(uri) do |response|
|
136
|
+
FileUtils.mkdir_p File.dirname(location)
|
137
|
+
File.open(location, "w") do |io|
|
138
|
+
response.read_body { |chunk| io.write chunk }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
116
144
|
def start_port_forward(port)
|
117
145
|
return if port_open?(port)
|
118
146
|
|
data/lib/pgai/version.rb
CHANGED