Class: Vkit::CLI::Commands::DatasourceCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/vkit/cli/commands/datasource_command.rb

Constant Summary collapse

REDACT =
"[REDACTED]"

Instance Method Summary collapse

Instance Method Details

#add(id:, engine:, username:, password:, config:, region:, environment:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vkit/cli/commands/datasource_command.rb', line 11

def add(id:, engine:, username:, password:, config:, region:, environment:)
  with_auth do
    user = require_admin!
    org  = user["organization_slug"]

    config_hash = config ? JSON.parse(config) : {}

    response = authenticated_client.post(
      "/api/v1/orgs/#{org}/datasources",
      body: {
        name: id,
        engine: engine,
        username: username,
        password: password,
        region: region.upcase,
        environment: environment,
        config: config_hash
      }
    )

    puts "✅ Datasource created:"
    print_datasource(response)
  end
end

#get(name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vkit/cli/commands/datasource_command.rb', line 53

def get(name)
  with_auth do
    user = require_admin!
    org  = user["organization_slug"]

    ds = authenticated_client.get(
      "/api/v1/orgs/#{org}/datasources/#{name}"
    )

    print_datasource(ds)
  end
end

#listObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vkit/cli/commands/datasource_command.rb', line 36

def list
  with_auth do
    user = require_admin!
    org  = user["organization_slug"]

    rows = authenticated_client.get(
      "/api/v1/orgs/#{org}/datasources"
    )

    puts "📦 Datasources (#{rows.size}):"
    rows.each do |ds|
      print_datasource(ds)
      puts "-" * 40
    end
  end
end