Class: Vkit::CLI::Commands::PolicyDeployCommand

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

Instance Method Summary collapse

Instance Method Details

#call(bundle_path:, org:, activate:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vkit/cli/commands/policy_deploy_command.rb', line 9

def call(bundle_path:, org:, activate:)
  with_auth do
    bundle_path = File.expand_path(bundle_path)
    raise "Bundle not found: #{bundle_path}" unless File.exist?(bundle_path)

    derived_org = credential_store.user["organization_slug"]

    raise "Unable to determine organization from credentials. Please login." \
      if derived_org.nil? || derived_org.empty?

    if org && org != derived_org
      raise <<~MSG
        Organization mismatch detected.

          Authenticated organization: #{derived_org}
          Provided via --org:          #{org}

        Refusing to deploy policy bundle to a different organization.
      MSG
    end

    org_slug = org || derived_org

    bundle = JSON.parse(File.read(bundle_path))

    response = authenticated_client.post(
      "/api/v1/orgs/#{org_slug}/policy_bundles",
      body: {
        bundle: bundle,
        activate: activate
      }
    )

    puts "🚀 Policy bundle deployed"
    puts "   Org:     #{org_slug}"
    puts "   Version: #{response['bundle_version']}"
    puts "   State:   #{response['state']}"
  end
end