Class: RailVerdict::VerificationIdentity

Inherits:
Object
  • Object
show all
Defined in:
lib/rail_verdict/verification_identity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository_state:, environment:, digest: nil, unavailable_reason: nil, available: true) ⇒ VerificationIdentity

Returns a new instance of VerificationIdentity.



12
13
14
15
16
17
18
19
# File 'lib/rail_verdict/verification_identity.rb', line 12

def initialize(repository_state:, environment:, digest: nil, unavailable_reason: nil, available: true)
  @repository_state = repository_state
  @environment = environment
  @digest = digest
  @unavailable_reason = unavailable_reason
  @available = available
  freeze
end

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



10
11
12
# File 'lib/rail_verdict/verification_identity.rb', line 10

def available
  @available
end

#digestObject (readonly)

Returns the value of attribute digest.



10
11
12
# File 'lib/rail_verdict/verification_identity.rb', line 10

def digest
  @digest
end

#environmentObject (readonly)

Returns the value of attribute environment.



10
11
12
# File 'lib/rail_verdict/verification_identity.rb', line 10

def environment
  @environment
end

#repository_stateObject (readonly)

Returns the value of attribute repository_state.



10
11
12
# File 'lib/rail_verdict/verification_identity.rb', line 10

def repository_state
  @repository_state
end

#unavailable_reasonObject (readonly)

Returns the value of attribute unavailable_reason.



10
11
12
# File 'lib/rail_verdict/verification_identity.rb', line 10

def unavailable_reason
  @unavailable_reason
end

Class Method Details

.capture(repository_root:, configuration_paths: nil, configuration: nil, runner: ProcessRunner, timeout_seconds: 5.0, receipt_analyzer_keys: nil) ⇒ Object



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rail_verdict/verification_identity.rb', line 25

def self.capture(repository_root:, configuration_paths: nil, configuration: nil, runner: ProcessRunner, timeout_seconds: 5.0, receipt_analyzer_keys: nil)
  repo_state = RepositoryState.capture(repository_root: repository_root, configuration_paths: configuration_paths)

  unless repo_state.available?
    return new(
      repository_state: repo_state,
      environment: VerificationEnvironment.new(
        railverdict_version: RailVerdict::VERSION.to_s,
        ruby_engine: RUBY_ENGINE.to_s,
        ruby_version: RUBY_VERSION.to_s,
        analyzer_versions: {},
        digest: nil,
        unavailable_reason: repo_state.unavailable_reason,
        available: false
      ),
      digest: nil,
      unavailable_reason: "repository_state_unavailable:#{repo_state.unavailable_reason}",
      available: false
    )
  end

  config = configuration
  if config.nil? && repository_root
    begin
      # Try to load config for environment capture to know enabled analyzers
      paths = configuration_paths || Check.effective_input_paths(root: File.realpath(repository_root), config_path: File.join(File.realpath(repository_root), ".railverdict.yml"))
      config_path = paths[:config]
      config = Configuration.load(config_path) if config_path && File.file?(config_path)
    rescue StandardError
      config = nil
    end
  end

  env = if receipt_analyzer_keys
          VerificationEnvironment.capture_for_receipt(receipt_analyzer_keys, repository_root: repository_root, configuration: config, runner: runner, timeout_seconds: timeout_seconds)
        else
          VerificationEnvironment.capture(repository_root: repository_root, configuration: config, runner: runner, timeout_seconds: timeout_seconds)
        end

  unless env.available?
    return new(
      repository_state: repo_state,
      environment: env,
      digest: nil,
      unavailable_reason: env.unavailable_reason,
      available: false
    )
  end

  # Digest over both repository and environment digests
  payload = {
    "repository_digest" => repo_state.digest,
    "environment_digest" => env.digest
  }
  digest = "sha256:#{Digest::SHA256.hexdigest(CanonicalJSON.generate(payload))}"
  new(repository_state: repo_state, environment: env, digest: digest, available: true)
rescue StandardError => error
  repo_unavailable = RepositoryState.unavailable(:capture_failed)
  env_unavailable = VerificationEnvironment.new(
    railverdict_version: RailVerdict::VERSION.to_s,
    ruby_engine: RUBY_ENGINE.to_s,
    ruby_version: RUBY_VERSION.to_s,
    analyzer_versions: {},
    digest: nil,
    unavailable_reason: error.class.to_s,
    available: false
  )
  new(repository_state: repo_unavailable, environment: env_unavailable, digest: nil, unavailable_reason: "capture_failed:#{error.class}", available: false)
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rail_verdict/verification_identity.rb', line 21

def available?
  @available && @repository_state&.available? && @environment&.available?
end