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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/vkit/cli/commands/policy_bundle_command.rb', line 12
def call(policies_dir:, registry_dir:, out:, org:, version:)
policies_dir = File.expand_path(policies_dir)
registry_dir = File.expand_path(registry_dir)
out = File.expand_path(out)
raise "Policies dir not found: #{policies_dir}" unless Dir.exist?(policies_dir)
raise "Registry dir not found: #{registry_dir}" unless Dir.exist?(registry_dir)
version ||= git_sha
with_auth do
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 " Organization mismatch detected.\n\n Authenticated organization: \#{derived_org}\n Provided via --org: \#{org}\n\n Refusing to continue to prevent cross-organization policy bundles.\n MSG\n end\n\n org_slug = org || derived_org\n\n bundle = Vkit::Policy::BundleCompiler.compile!(\n org_slug: org_slug,\n bundle_version: version,\n policies_dir: policies_dir,\n registry_dir: registry_dir,\n source: {\n repo: git_repo,\n ref: git_ref,\n commit_sha: version\n }\n )\n\n FileUtils.mkdir_p(File.dirname(out))\n File.write(out, JSON.pretty_generate(bundle))\n\n puts \"\u2705 Policy bundle created\"\n puts \" Org: \#{bundle.dig(\"bundle\", \"org_slug\")}\"\n puts \" Version: \#{bundle.dig(\"bundle\", \"bundle_version\")}\"\n puts \" Checksum: \#{bundle.dig(\"bundle\", \"checksum\")}\"\n puts \" Output: \#{out}\"\n end\nrescue Vkit::Policy::ValidationError => e\n puts e.message\n exit 1\nend\n"
|