pgai 0.1.2 → 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 +4 -4
- data/README.md +19 -7
- data/lib/pgai/cli/main.rb +3 -3
- data/lib/pgai/clone_manager.rb +32 -3
- data/lib/pgai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e67c364882e415161c298f0463f6e3850a7ea057b8256a3a4e17643d4a8694
|
4
|
+
data.tar.gz: bdcce4986037ace414698eeae62ce3f73f33084ace78e99e778a2b55975f5ad3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a083cc81d4c2b55892f9d1137aefa7dbb7bda601b2a058a42e6011a630eac7e4469ec586363a334a95c795955c7809d4b285937c49ba099e4761f16b7fb6a9
|
7
|
+
data.tar.gz: 0c1dcc4947700235508cd9ea3ffbcececa52f32b98c1d04c3f931ae7d97b72ef334c1409b2fd70c86a0867990445dbd4288b8cb9028ce9a910030d40bc51733c
|
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,16 @@ 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_RELEASE_CHANNEL = "master"
|
16
|
+
DBLAB_BINARY_URL = "https://storage.googleapis.com/database-lab-cli/#{DBLAB_RELEASE_CHANNEL}/dblab-%{os}-%{cpu}"
|
11
17
|
|
12
18
|
def initialize(environment, config:)
|
13
19
|
@environment = environment
|
@@ -105,14 +111,37 @@ module Pgai
|
|
105
111
|
end
|
106
112
|
|
107
113
|
def dblab(*args, raw: false)
|
108
|
-
|
109
|
-
|
110
|
-
output = `#{args.unshift(executable).shelljoin}`
|
114
|
+
output = `#{args.unshift(dblab_path).shelljoin}`
|
111
115
|
return output if raw
|
112
116
|
|
113
117
|
JSON.parse(output) unless output.empty?
|
114
118
|
end
|
115
119
|
|
120
|
+
def dblab_path
|
121
|
+
return config.path unless config.path.to_s.empty?
|
122
|
+
return "dblab" unless `which dblab`.to_s.empty?
|
123
|
+
return DEFAULT_DBLAB.to_s if DEFAULT_DBLAB.exist?
|
124
|
+
|
125
|
+
download_dblab_to(DEFAULT_DBLAB)
|
126
|
+
File.chmod(0o755, DEFAULT_DBLAB)
|
127
|
+
|
128
|
+
DEFAULT_DBLAB
|
129
|
+
end
|
130
|
+
|
131
|
+
def download_dblab_to(location)
|
132
|
+
platform = Gem::Platform.local
|
133
|
+
uri = URI(DBLAB_BINARY_URL % {os: platform.os, cpu: platform.cpu})
|
134
|
+
|
135
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
136
|
+
http.request Net::HTTP::Get.new(uri) do |response|
|
137
|
+
FileUtils.mkdir_p File.dirname(location)
|
138
|
+
File.open(location, "w") do |io|
|
139
|
+
response.read_body { |chunk| io.write chunk }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
116
145
|
def start_port_forward(port)
|
117
146
|
return if port_open?(port)
|
118
147
|
|
data/lib/pgai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marius Bobin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|