Class: Ace::Git::Secrets::Models::RevocationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/secrets/models/revocation_result.rb

Overview

Represents the result of a token revocation attempt Immutable value object containing revocation outcome

Constant Summary collapse

STATUSES =

Valid revocation statuses

%w[revoked failed unsupported skipped].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, service:, status:, message: nil, revoked_at: nil) ⇒ RevocationResult

Returns a new instance of RevocationResult.

Parameters:

  • token (DetectedToken)

    The token that was revoked

  • service (String)

    Service name (github, anthropic, openai, aws)

  • status (String)

    Revocation status (revoked, failed, unsupported, skipped)

  • message (String, nil) (defaults to: nil)

    Additional message or error details

  • revoked_at (Time, nil) (defaults to: nil)

    Timestamp of revocation



20
21
22
23
24
25
26
27
28
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 20

def initialize(token:, service:, status:, message: nil, revoked_at: nil)
  @token = token
  @service = service
  @status = validate_status(status)
  @message = message
  @revoked_at = revoked_at || ((status == "revoked") ? Time.now : nil)

  freeze
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 10

def message
  @message
end

#revoked_atObject (readonly)

Returns the value of attribute revoked_at.



10
11
12
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 10

def revoked_at
  @revoked_at
end

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 10

def service
  @service
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 10

def status
  @status
end

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 10

def token
  @token
end

Class Method Details

.failure(token:, service:, message:) ⇒ RevocationResult

Create a failed revocation result

Parameters:

  • token (DetectedToken)

    The token that failed to revoke

  • service (String)

    Service name

  • message (String)

    Error message

Returns:



86
87
88
89
90
91
92
93
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 86

def self.failure(token:, service:, message:)
  new(
    token: token,
    service: service,
    status: "failed",
    message: message
  )
end

.success(token:, service:, message: nil) ⇒ RevocationResult

Create a successful revocation result

Parameters:

  • token (DetectedToken)

    The token that was revoked

  • service (String)

    Service name

  • message (String, nil) (defaults to: nil)

    Success message

Returns:



72
73
74
75
76
77
78
79
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 72

def self.success(token:, service:, message: nil)
  new(
    token: token,
    service: service,
    status: "revoked",
    message: message || "Token successfully revoked"
  )
end

.unsupported(token:, service: nil) ⇒ RevocationResult

Create an unsupported revocation result

Parameters:

  • token (DetectedToken)

    The token that cannot be revoked

  • service (String, nil) (defaults to: nil)

    Service name

Returns:



99
100
101
102
103
104
105
106
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 99

def self.unsupported(token:, service: nil)
  new(
    token: token,
    service: service || "unknown",
    status: "unsupported",
    message: "Token type #{token.token_type} does not support automatic revocation"
  )
end

Instance Method Details

#failed?Boolean

Check if revocation failed

Returns:

  • (Boolean)


38
39
40
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 38

def failed?
  status == "failed"
end

#skipped?Boolean

Check if revocation was skipped

Returns:

  • (Boolean)


50
51
52
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 50

def skipped?
  status == "skipped"
end

#success?Boolean

Check if revocation was successful

Returns:

  • (Boolean)


32
33
34
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 32

def success?
  status == "revoked"
end

#to_hHash

Convert to hash for serialization

Returns:

  • (Hash)


56
57
58
59
60
61
62
63
64
65
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 56

def to_h
  {
    token_type: token.token_type,
    masked_value: token.masked_value,
    service: service,
    status: status,
    message: message,
    revoked_at: revoked_at&.iso8601
  }
end

#unsupported?Boolean

Check if token type is unsupported for revocation

Returns:

  • (Boolean)


44
45
46
# File 'lib/ace/git/secrets/models/revocation_result.rb', line 44

def unsupported?
  status == "unsupported"
end