Sha256: af93b5f9618771e787c29e702c1d64bfb182f6437763989322788f6b7b63ab03

Contents?: true

Size: 1.6 KB

Versions: 62

Compression:

Stored size: 1.6 KB

Contents

module Appsignal
  class CLI
    class Diagnose
      class Utils
        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

        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

        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

        def self.parse_yaml(contents)
          if YAML.respond_to? :safe_load
            if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
              # Use keyword params for Ruby 2.6 and up
              YAML.safe_load(contents, :permitted_classes => [Time])
            else
              YAML.safe_load(contents, [Time])
            end
          else
            # Support for Ruby versions without YAML.safe_load
            YAML.load(contents) # rubocop:disable Security/YAMLLoad
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
appsignal-3.0.18-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.18 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.17-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.17 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.16-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.16 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.15-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.15 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.14-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.14 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.13-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.13 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.12-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.12 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.11-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.11 lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.10-java lib/appsignal/cli/diagnose/utils.rb
appsignal-3.0.10 lib/appsignal/cli/diagnose/utils.rb
appsignal-2.11.10-java lib/appsignal/cli/diagnose/utils.rb
appsignal-2.11.10 lib/appsignal/cli/diagnose/utils.rb