File: uuid.rb

package info (click to toggle)
ruby-train 3.2.28-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,116 kB
  • sloc: ruby: 9,246; sh: 17; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 901 bytes parent folder | download
1
2
3
4
5
6
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
require "digest/sha1"
require "securerandom"
require "json"

module Train::Platforms::Detect
  class UUID
    include Train::Platforms::Detect::Helpers::OSCommon

    def initialize(platform)
      @platform = platform
      @backend = @platform.backend
    end

    def find_or_create_uuid
      # for api transports uuid is defined on the connection
      if defined?(@backend.unique_identifier)
        uuid_from_string(@backend.unique_identifier)
      elsif @platform.unix?
        unix_uuid
      elsif @platform.windows?
        windows_uuid
      else
        if @platform[:uuid_command]
          result = @backend.run_command(@platform[:uuid_command])
          return uuid_from_string(result.stdout.chomp) if result.exit_status == 0 && !result.stdout.empty?
        end

        raise "Could not find platform uuid! Please set a uuid_command for your platform."
      end
    end
  end
end