pgai 1.0.1 → 1.0.2

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: 123bfba393d6bed50c493b3acd2d934b497c506a09c5680293bc2d68eb942394
4
- data.tar.gz: cc04c9ab11322ba25526b3fef520c72c172e9672d52e04aded6b23e37a28490b
3
+ metadata.gz: 00ac038ff78647c4a3569cb87ebe3ae2dd10b9946be720ccffba5b951fc09f26
4
+ data.tar.gz: b4581834f1c91edfddff07cff3e05bdd658aa8983038a40adc24b3beaaf68158
5
5
  SHA512:
6
- metadata.gz: d746ae9b949706ad27f5aeb8089ff928475188a2e43ab996b8ece041feae63b740d70a3ed165f0af3f022309066cec0bcb6200fca8b1c7c1da4a1e7dec7932e1
7
- data.tar.gz: 43b5d7e409bca1d28cb75c6fff9a3259c34348bc7365035134acff02639e5e8a7753401f83ef3d3dcbbab2fa6089060e91bf4bfb1406dd27b19e102d63b23a9f
6
+ metadata.gz: 572343b7a247938db90162ed94f44aa835f0dd7078ca6366f78b0b4151e8c82218b2aacd47f45f8ecb21c0d381e093642a5e40f0b61da37a28014c0a104d80a4
7
+ data.tar.gz: f7fa39825ffcac44f5130b5e2a98f9348d013928382f8ee5ae73d63417f75c1f6cb2dfc85d4ef627c4828656ede3fccee9eea4dcb9efcbdcde9385b44e238ccf
data/lib/pgai/cli/env.rb CHANGED
@@ -33,10 +33,26 @@ module Pgai::Cli
33
33
  desc "list", "List all configured environments"
34
34
  def list
35
35
  data = Pgai::Resources::Local::Environment.all.map do |env|
36
- env.attributes.slice(:id, :alias, :port, :dbname)
36
+ env.attributes.slice(:id, :alias, :port, :dbname, :snapshot)
37
37
  end
38
38
 
39
39
  say JSON.pretty_generate(data)
40
40
  end
41
+
42
+ desc "dup env", "Duplicate an environment and override the provided attributes"
43
+ method_option :alias, aliases: "-a",
44
+ desc: "This will be used internally for the connect command",
45
+ required: true
46
+ method_option :dbname,
47
+ aliases: "-n",
48
+ desc: "Specify database name to connect to by default"
49
+ method_option :snapshot,
50
+ aliases: "-s",
51
+ desc: "Specify the snapshot id if you want to create a clone from a specific snapshot"
52
+ def dup(env)
53
+ env = Pgai::Resources::Local::Environment.find(env)
54
+ attrs = env.attributes.merge(options.transform_keys(&:to_sym))
55
+ Pgai::Resources::Local::Environment.new(attrs).save
56
+ end
41
57
  end
42
58
  end
data/lib/pgai/client.rb CHANGED
@@ -46,6 +46,7 @@ module Pgai
46
46
  def parse_reponse(data)
47
47
  data = JSON.parse(data)
48
48
  transform!(data)
49
+ handle_unauthorized(data)
49
50
  data
50
51
  end
51
52
 
@@ -65,5 +66,12 @@ module Pgai
65
66
  transform_array!(data)
66
67
  end
67
68
  end
69
+
70
+ def handle_unauthorized(data)
71
+ return unless data.is_a?(Hash)
72
+ return unless data[:code] == "UNAUTHORIZED"
73
+
74
+ raise UnauthorizedError, data[:message]
75
+ end
68
76
  end
69
77
  end
@@ -33,7 +33,7 @@ module Pgai
33
33
  def create_clone_resource
34
34
  @clone_resource = Resources::Remote::Clone.new(id: id).tap do |resource|
35
35
  resource.db_object = Resources::Remote::DbObject.new(db_name: env.dbname)
36
- resource.snapshot = Resources::Remote::Snapshot.latest
36
+ resource.snapshot = find_snapshot
37
37
  resource.save
38
38
  end
39
39
  end
@@ -56,6 +56,14 @@ module Pgai
56
56
  @clone_resource ||= create_clone_resource
57
57
  end
58
58
 
59
+ def find_snapshot
60
+ if env.snapshot
61
+ Resources::Remote::Snapshot.find(env.snapshot)
62
+ else
63
+ Resources::Remote::Snapshot.latest
64
+ end
65
+ end
66
+
59
67
  def wait_for_clone_to_be_ready
60
68
  loop do
61
69
  progress_bar.advance(steps)
@@ -10,6 +10,7 @@ module Pgai
10
10
  attribute :dbname, :string
11
11
  attribute :access_token, :string
12
12
  attribute :clone_prefix, :string
13
+ attribute :snapshot, :string
13
14
 
14
15
  def client
15
16
  @client ||= Pgai::Client.new(
@@ -24,6 +24,12 @@ module Pgai
24
24
  def path
25
25
  "snapshots"
26
26
  end
27
+
28
+ def find(id)
29
+ record = all.find { |snapshot| snapshot.id.to_s == id.to_s }
30
+ raise Pgai::ResourceNotFound unless record
31
+ record
32
+ end
27
33
  end
28
34
  end
29
35
  end
data/lib/pgai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/pgai.rb CHANGED
@@ -5,8 +5,14 @@ require "zeitwerk"
5
5
  loader = Zeitwerk::Loader.for_gem
6
6
  loader.setup
7
7
 
8
+ require "thor"
9
+
8
10
  module Pgai
9
11
  class Error < StandardError; end
10
12
 
13
+ class CliError < ::Thor::Error; end
14
+
11
15
  class ResourceNotFound < Error; end
16
+
17
+ class UnauthorizedError < CliError; end
12
18
  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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Bobin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-14 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor