Class: Vkit::CLI::Commands::GrantRevokeCommand

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

Instance Method Summary collapse

Instance Method Details

#call(grant_ref:, reason:, force:) ⇒ Object



7
8
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
# File 'lib/vkit/cli/commands/grant_revoke_command.rb', line 7

def call(grant_ref:, reason:, force:)
  with_auth do
    user = credential_store.user
    org  = user["organization_slug"]

    raise "Not authenticated. Please login." if org.nil? || org.empty?

    unless force
      puts "⚠️  You are about to revoke grant: #{grant_ref}"
      puts "   Organization: #{org}"
      puts "   Reason: #{reason || 'Grant revoked via CLI'}"
      print "Continue? (y/N): "
      answer = STDIN.gets.strip
      return puts("Aborted.") unless answer.downcase == "y"
    end

    response =
      authenticated_client.post(
        "/api/v1/orgs/#{org}/grants/#{grant_ref}/revoke",
        body: {
          reason: reason
        }
      )

    puts "✅ Grant revoked"
    puts "   Grant:   #{grant_ref}"
    puts "   Revoked: #{response["revoked_at"]}"
  end
end