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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d9d2db36c8d7cae9b66a1ee25b6e5a1215a481919fe31a1c44b8e23a4dcdd02
4
- data.tar.gz: c24d0012961c7520f25d3568bb288435dfd5e1e3d3c03b1b8c33f4390ac0d2be
3
+ metadata.gz: 29e67c364882e415161c298f0463f6e3850a7ea057b8256a3a4e17643d4a8694
4
+ data.tar.gz: bdcce4986037ace414698eeae62ce3f73f33084ace78e99e778a2b55975f5ad3
5
5
  SHA512:
6
- metadata.gz: ceb07e5b9f9c16975fa7a7f59e935f6c195ab7b7e208729e3376e26aa2788e01096d570740a134a809076d69a1cb3824cb757a53f265f4105a010140a153f006
7
- data.tar.gz: 95f8a35085451562058a5a7795aed4c742d2f104ac382bb94386e26ba82b354f1ab5d37d65822ea8e626da79da2f6cf4287bd80530166f736bb8c03143cca14b
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
- Postgres.ai does not provide `dblab` binaries for `ARM` processors(yet?), to work around this:
23
+ An access token will be required and it can be obtained from: https://console.postgres.ai/gitlab/tokens
24
24
 
25
- - clone `https://gitlab.com/postgres-ai/database-lab`
26
- - change [`GOARCH = amd64`](https://gitlab.com/postgres-ai/database-lab/-/blob/0ad2cdd8f1d851e4beda92e0577bb242c6a8dd7f/engine/Makefile#L6) to `GOARCH = arm64`
27
- - execute [`make build`](https://gitlab.com/postgres-ai/database-lab/-/blob/0ad2cdd8f1d851e4beda92e0577bb242c6a8dd7f/engine/Makefile#L44-L47), we're interested only about building `CLI_BINARY`, the others could be removed.
28
- - the `dblab` binary should be available in the `bin` directory
29
- - run `pgai config --exe /path/to/bin/dblab` to set the path if it's not in `$PATH`.
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 executable path", required: true
7
+ method_option :exe, aliases: "-e", desc: "dblab binary path"
8
8
  def config
9
9
  token = ask("Access token:", echo: false)
10
10
 
@@ -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
- executable = config.path || "dblab"
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
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
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.2
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 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor