Sha256: eab4d45f749499c8d4c3c134eb1dd9acd58394a782b6a843f218e1331f49d557

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

module ActiveScripts
  class Base

    # INFO: ActiveScripts::Base contains code that is
    #   shared between all base files.

    private

    def assert_valid_user!
      unless user?
        raise SecurityError,
          "The following commands cannot be executed as root. Switch to a non-root user."
      end
    end

    def user?
      output, error, status = Open3.capture3("whoami")
      output = output.squish
      return(output != "root")
    end

    def notify_command_todo!
      say_warning("   [!] CommandError")
      say_warning("     - TODO: The command is not yet developed.")
    end

    def notify_command_unavailable!
      say_warning("   [!] CommandError")
      say_warning("     - The command is not available.")
    end

    def notify_command_user!
      say_warning("   [!] CommandError")
      say_warning("     - The command cannot be executed as root. Please switch user.")
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_scripts-0.1.0 lib/active_scripts/base.rb