Class: Ronin::UI::CLI::Commands::Database

Inherits:
Ronin::UI::CLI::Command show all
Defined in:
lib/ronin/ui/cli/commands/database.rb

Overview

The ronin database command.

Instance Method Summary collapse

Methods inherited from Ronin::UI::CLI::Command

banner, command_name, #indent, inherited, #initialize, #print_array, #print_exception, #print_hash, #print_section, #print_title, #puts, run, #setup

Constructor Details

This class inherits a constructor from Ronin::UI::CLI::Command

Instance Method Details

#add_repositoryObject (protected)

Adds a new Database repository.



105
106
107
108
109
110
111
112
113
# File 'lib/ronin/ui/cli/commands/database.rb', line 105

def add_repository
  name = options[:add].to_sym

  Ronin::Database.save do
    Ronin::Database.repositories[name] = repository_uri
  end

  print_info "Database repository #{name} added."
end

#executeObject

Displays or modifies the Ronin Database configuration.



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
# File 'lib/ronin/ui/cli/commands/database.rb', line 53

def execute
  if options[:clear]
    name = options[:clear].to_sym

    print_info "Clearing the Database repository #{name} ..."

    Ronin::Database.clear(name) do
      print_info "Database repository #{name} cleared."
    end

    return
  end

  if options[:add]
    add_repository
  elsif options[:set]
    set_repository
  elsif options[:delete]
    delete_repository
  else
    Ronin::Database.repositories.each do |name,uri|
      print_hash uri, :title => name
    end
  end
end

#remove_repositoryObject (protected)

Removes an existing Database repository.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ronin/ui/cli/commands/database.rb', line 136

def remove_repository
  name = options[:remove].to_sym

  unless Ronin::Database.repository?(name)
    print_error "Unknown Database repository #{name}"
    return
  end

  Ronin::Database.save do
    Ronin::Database.repositories.delete(name)
  end

  print_info "Database repository #{name} removed."
end

#repository_uriAddressable::URI (protected)

Creates a repository URI from the command options.

Returns:

  • (Addressable::URI)

    The repository URI.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ronin/ui/cli/commands/database.rb', line 87

def repository_uri
  if options[:uri]
    Addressable::URI.parse(options[:uri]).to_hash
  else
    {
      :adapter => options[:adapter],
      :host => options[:host],
      :port => options[:port],
      :user => options[:user],
      :password => options[:password],
      :database => (options[:database] || options[:path])
    }
  end
end

#set_repositoryObject (protected)

Sets the URI for an existing Database repository.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ronin/ui/cli/commands/database.rb', line 118

def set_repository
  name = options[:set].to_sym

  unless Ronin::Database.repository?(name)
    print_error "Unknown Database repository #{name}"
    return
  end

  Ronin::Database.save do
    Ronin::Database.repositories[name] = repository_uri
  end

  print_info "Database repository #{name} updated."
end