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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d9d2db36c8d7cae9b66a1ee25b6e5a1215a481919fe31a1c44b8e23a4dcdd02
4
- data.tar.gz: c24d0012961c7520f25d3568bb288435dfd5e1e3d3c03b1b8c33f4390ac0d2be
3
+ metadata.gz: 4ffc13ccc5cc54a852ba48b245a1f4e470696d622fe499aa5fbce8221e77fa5d
4
+ data.tar.gz: 6e78ffd141aed55d189bab7c986c11434b8d22fbe4c40b032ddc2074875909fb
5
5
  SHA512:
6
- metadata.gz: ceb07e5b9f9c16975fa7a7f59e935f6c195ab7b7e208729e3376e26aa2788e01096d570740a134a809076d69a1cb3824cb757a53f265f4105a010140a153f006
7
- data.tar.gz: 95f8a35085451562058a5a7795aed4c742d2f104ac382bb94386e26ba82b354f1ab5d37d65822ea8e626da79da2f6cf4287bd80530166f736bb8c03143cca14b
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
- 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,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
- executable = config.path || "dblab"
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
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Bobin