Class: Appsignal::CLI::Diagnose::Utils Private

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/cli/diagnose/utils.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0

Class Method Summary collapse

Class Method Details

.group_for_gid(gid) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0



12
13
14
15
16
17
# File 'lib/appsignal/cli/diagnose/utils.rb', line 12

def self.group_for_gid(gid)
  passwd_struct = Etc.getgrgid(gid)
  return unless passwd_struct
  passwd_struct.name
rescue ArgumentError # rubocop:disable Lint/HandleExceptions
end

.parse_yaml(contents) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/appsignal/cli/diagnose/utils.rb', line 36

def self.parse_yaml(contents)
  arguments = [contents]
  if YAML.respond_to? :safe_load
    method = :safe_load
    arguments << \
      if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
        # Use keyword params for Ruby 2.6 and up
        { :permitted_classes => [Time] }
      else
        [Time]
      end
  else
    method = :load
  end
  YAML.send(method, *arguments)
end

.read_file_content(path, bytes_to_read) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appsignal/cli/diagnose/utils.rb', line 19

def self.read_file_content(path, bytes_to_read)
  file_size = File.size(path)
  if bytes_to_read > file_size
    # When the file is smaller than the bytes_to_read
    # Read the whole file
    offset = 0
    length = file_size
  else
    # When the file is smaller than the bytes_to_read
    # Read the last X bytes_to_read
    length = bytes_to_read
    offset = file_size - bytes_to_read
  end

  IO.binread(path, length, offset)
end

.username_for_uid(uid) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0



5
6
7
8
9
10
# File 'lib/appsignal/cli/diagnose/utils.rb', line 5

def self.username_for_uid(uid)
  passwd_struct = Etc.getpwuid(uid)
  return unless passwd_struct
  passwd_struct.name
rescue ArgumentError # rubocop:disable Lint/HandleExceptions
end