This file is indexed.

/usr/lib/ruby/vendor_ruby/berkshelf/api/application.rb is in berkshelf-api 2.2.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
trap 'INT' do
  Berkshelf::API::Application.shutdown
end

trap 'TERM' do
  Berkshelf::API::Application.shutdown
end

module Berkshelf::API
  class ApplicationSupervisor < Celluloid::SupervisionGroup
    # @option options [Boolean] :disable_http (false)
    #   run the application without the rest gateway
    def initialize(registry, options = {})
      super(registry)
      supervise_as(:cache_manager, Berkshelf::API::CacheManager)
      supervise_as(:cache_builder, Berkshelf::API::CacheBuilder)

      unless options[:disable_http]
        require_relative 'rest_gateway'
        supervise_as(:rest_gateway, Berkshelf::API::RESTGateway, options)
      end
    end
  end

  module Application
    class << self
      extend Forwardable
      include Berkshelf::API::Logging
      include Berkshelf::API::Mixin::Services

      attr_reader :start_time
      def_delegators :registry, :[], :[]=

      # @return [Berkshelf::API::Config]
      def config
        @config ||= begin
          Berkshelf::API::Config.from_file(Berkshelf::API::Config.default_path)
        rescue
          Berkshelf::API::Config.new
        end
      end

      # @param [Berkshelf::API::Config] config
      def set_config(config)
        @config = config
      end

      # Configure the application
      #
      # @option options [String] :config_file
      #   filepath to a configuration file to use
      # @option options [String, Fixnum] :log_location (STDOUT)
      # @option options [String, nil] :log_level ("INFO")
      #   - "DEBUG
      #   - "INFO"
      #   - "WARN"
      #   - "ERROR"
      #   - "FATAL"
      #
      # @raise [Berkshelf::API::ConfigNotFoundError]
      #
      # @return [Berkshelf::API::Config]
      def configure(options = {})
        unless options[:config_file].nil?
          set_config Berkshelf::API::Config.from_file(options[:config_file])
        end

        configure_logger(options)
        config
      rescue Buff::Errors::ConfigNotFound => ex
        raise ConfigNotFoundError, ex
      end

      # @option options [String, Fixnum] :log_location (STDOUT)
      # @option options [String, nil] :log_level ("INFO")
      #   - "DEBUG
      #   - "INFO"
      #   - "WARN"
      #   - "ERROR"
      #   - "FATAL"
      def configure_logger(options = {})
        Logging.init(level: options[:log_level], location: options[:log_location])
      end

      # @return [String]
      def home_path
        ENV['BERKSHELF_API_PATH'] || config.home_path
      end

      # Retrieve the running instance of the Application
      #
      # @raise [Berkshelf::API::NotStartedError]
      #
      # @return [Berkshelf::API::Application]
      def instance
        return @instance if @instance

        raise NotStartedError, "application not running"
      end

      # The Actor registry for Berkshelf::API.
      #
      # @note Berkshelf::API uses it's own registry instead of Celluloid::Registry.root to
      #   avoid conflicts in the larger namespace. Use Berkshelf::API::Application[] to access Berkshelf::API
      #   actors instead of Celluloid::Actor[].
      #
      # @return [Celluloid::Registry]
      def registry
        @registry ||= Celluloid::Registry.new
      end

      # Run the application in the foreground (sleep on main thread)
      #
      # @option options [Boolean] :disable_http (false)
      #   run the application without the rest gateway
      def run(options = {})
        @start_time = Time.now.utc
        loop do
          supervisor = run!(options)

          while supervisor.alive?
            sleep 0.1
            instance.terminate if @shutdown
          end

          break if @shutdown

          log.error "!!! #{self} crashed. Restarting..."
        end
      end

      # Run the application in the background
      #
      # @option options [Boolean] :disable_http (false)
      #   run the application without the rest gateway
      # @option options [Boolean] :eager_build (false)
      #   automatically begin and loop all cache builders
      #
      # @return [Berkshelf::API::Application]
      def run!(options = {})
        options = { disable_http: false, eager_build: false }.merge(options)
        configure(options)
        @instance = ApplicationSupervisor.new(registry, options)
        cache_builder.async(:build_loop) if options[:eager_build]
        @instance
      end

      # @return [Boolean]
      def running?
        instance.alive?
      rescue NotStartedError
        false
      end

      # Shutdown the running instance
      #
      # @raise [Berkshelf::API::NotStartedError]
      #   if there is no running instance
      def shutdown
        @shutdown = true
      end
    end
  end
end