ronin-db 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.rspec +1 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +1 -0
  8. data/COPYING.txt +165 -0
  9. data/ChangeLog.md +12 -0
  10. data/Gemfile +39 -0
  11. data/README.md +272 -0
  12. data/Rakefile +76 -0
  13. data/bin/ronin-db +35 -0
  14. data/gemspec.yml +46 -0
  15. data/lib/ronin/db/cli/command.rb +37 -0
  16. data/lib/ronin/db/cli/commands/add.rb +206 -0
  17. data/lib/ronin/db/cli/commands/asn.rb +218 -0
  18. data/lib/ronin/db/cli/commands/creds.rb +80 -0
  19. data/lib/ronin/db/cli/commands/edit.rb +58 -0
  20. data/lib/ronin/db/cli/commands/emails.rb +90 -0
  21. data/lib/ronin/db/cli/commands/hosts.rb +100 -0
  22. data/lib/ronin/db/cli/commands/ips.rb +100 -0
  23. data/lib/ronin/db/cli/commands/irb.rb +81 -0
  24. data/lib/ronin/db/cli/commands/list.rb +124 -0
  25. data/lib/ronin/db/cli/commands/migrate.rb +75 -0
  26. data/lib/ronin/db/cli/commands/remove.rb +69 -0
  27. data/lib/ronin/db/cli/commands/urls.rb +170 -0
  28. data/lib/ronin/db/cli/database_command.rb +71 -0
  29. data/lib/ronin/db/cli/model_command.rb +202 -0
  30. data/lib/ronin/db/cli/modifiable.rb +141 -0
  31. data/lib/ronin/db/cli/resources_command.rb +120 -0
  32. data/lib/ronin/db/cli/ruby_shell.rb +51 -0
  33. data/lib/ronin/db/cli/uri_methods.rb +97 -0
  34. data/lib/ronin/db/cli.rb +38 -0
  35. data/lib/ronin/db/config_file.rb +132 -0
  36. data/lib/ronin/db/exceptions.rb +26 -0
  37. data/lib/ronin/db/home.rb +36 -0
  38. data/lib/ronin/db/root.rb +28 -0
  39. data/lib/ronin/db/version.rb +26 -0
  40. data/lib/ronin/db.rb +123 -0
  41. data/man/ronin-db-add.1 +99 -0
  42. data/man/ronin-db-add.1.md +75 -0
  43. data/man/ronin-db-asn.1 +79 -0
  44. data/man/ronin-db-asn.1.md +59 -0
  45. data/man/ronin-db-creds.1 +78 -0
  46. data/man/ronin-db-creds.1.md +58 -0
  47. data/man/ronin-db-edit.1 +48 -0
  48. data/man/ronin-db-edit.1.md +36 -0
  49. data/man/ronin-db-emails.1 +82 -0
  50. data/man/ronin-db-emails.1.md +61 -0
  51. data/man/ronin-db-hosts.1 +86 -0
  52. data/man/ronin-db-hosts.1.md +64 -0
  53. data/man/ronin-db-ips.1 +90 -0
  54. data/man/ronin-db-ips.1.md +67 -0
  55. data/man/ronin-db-irb.1 +61 -0
  56. data/man/ronin-db-irb.1.md +46 -0
  57. data/man/ronin-db-list.1 +58 -0
  58. data/man/ronin-db-list.1.md +44 -0
  59. data/man/ronin-db-migrate.1 +44 -0
  60. data/man/ronin-db-migrate.1.md +32 -0
  61. data/man/ronin-db-remove.1 +55 -0
  62. data/man/ronin-db-remove.1.md +42 -0
  63. data/man/ronin-db-urls.1 +98 -0
  64. data/man/ronin-db-urls.1.md +73 -0
  65. data/ronin-db.gemspec +78 -0
  66. data/spec/cli/commands/add_spec.rb +220 -0
  67. data/spec/cli/commands/edit_spec.rb +12 -0
  68. data/spec/cli/commands/irb_spec.rb +26 -0
  69. data/spec/cli/database_command_spec.rb +53 -0
  70. data/spec/cli/model_command_spec.rb +237 -0
  71. data/spec/cli/ruby_shell_spec.rb +14 -0
  72. data/spec/cli/uri_methods_spec.rb +190 -0
  73. data/spec/spec_helper.rb +15 -0
  74. metadata +200 -0
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/core/cli/ruby_shell'
22
+
23
+ module Ronin
24
+ module DB
25
+ class CLI
26
+ #
27
+ # The interactive Ruby shell for {Ronin::DB}.
28
+ #
29
+ class RubyShell < Core::CLI::RubyShell
30
+
31
+ #
32
+ # Initializes the `ronin-db` Ruby shell.
33
+ #
34
+ # @param [String] name
35
+ # The name of the IRB shell.
36
+ #
37
+ # @param [Object] context
38
+ # Custom context to launch IRB from within.
39
+ #
40
+ # @param [Hash{Symbol => Object}] kwargs
41
+ # Additional keyword arguments for
42
+ # `Ronin::Core::CLI::RubyShell#initialize`.
43
+ #
44
+ def initialize(name: 'ronin-db', context: Ronin::DB, **kwargs)
45
+ super(name: name, context: context, **kwargs)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/cli/command'
22
+ require 'ronin/db'
23
+
24
+ module Ronin
25
+ module DB
26
+ class CLI
27
+ module URIMethods
28
+ # Common database adapter names and their ActiveRecord equivalents.
29
+ ADAPTER_ALIASES = {
30
+ 'sqlite' => 'sqlite3',
31
+ 'mysql' => 'mysql2',
32
+ 'pg' => 'postgresql',
33
+ 'psql' => 'postgresql',
34
+ 'postgres' => 'postgresql'
35
+ }
36
+
37
+ #
38
+ # Normalizes a database adapter name.
39
+ #
40
+ # @param [String] adapter
41
+ # The adapter name to normalize.
42
+ #
43
+ # @return [String]
44
+ # The normalized adapter.
45
+ #
46
+ def normalize_adapter(adapter)
47
+ ADAPTER_ALIASES.fetch(adapter,adapter)
48
+ end
49
+
50
+ #
51
+ # Normalizes a sqlite3 database path.
52
+ #
53
+ # @param [String] path
54
+ # The path to the sqlite3 database.
55
+ #
56
+ # @return [String]
57
+ # The expanded path or `":memory:"` if the path was `":memory:"`.
58
+ #
59
+ def normalize_sqlite3_path(path)
60
+ if path== ':memory:' then path
61
+ else File.expand_path(path)
62
+ end
63
+ end
64
+
65
+ #
66
+ # Parses a database URI.
67
+ #
68
+ # @param [String] uri
69
+ # The database URI to parse.
70
+ #
71
+ # @return [Hash{Symbol => String,Integer,nil}]
72
+ # The database configuration Hash.
73
+ #
74
+ def parse_uri(uri)
75
+ if (match = uri.match(/\Asqlite[3]?:(.+)\z/))
76
+ {
77
+ adapter: 'sqlite3',
78
+ database: normalize_sqlite3_path(match[1])
79
+ }
80
+ else
81
+ uri = URI.parse(uri)
82
+ adapter = normalize_adapter(uri.scheme)
83
+
84
+ hash = {adapter: adapter}
85
+ hash[:host] = uri.host if uri.host
86
+ hash[:port] = uri.port if uri.port
87
+ hash[:username] = uri.user if uri.user
88
+ hash[:password] = uri.password if uri.password
89
+ hash[:database] = uri.path[1..]
90
+
91
+ return hash
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'command_kit/commands'
22
+ require 'command_kit/commands/auto_load'
23
+
24
+ module Ronin
25
+ module DB
26
+ class CLI
27
+
28
+ include CommandKit::Commands
29
+ include CommandKit::Commands::AutoLoad.new(
30
+ dir: "#{__dir__}/cli/commands",
31
+ namespace: "#{self}::Commands"
32
+ )
33
+
34
+ command_name 'ronin-db'
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/exceptions'
22
+ require 'ronin/db/home'
23
+
24
+ require 'yaml'
25
+ require 'yaml/store'
26
+
27
+ module Ronin
28
+ module DB
29
+ #
30
+ # Represents the `~/.config/ronin-db/databases.yml` configuration file.
31
+ #
32
+ # @api private
33
+ #
34
+ module ConfigFile
35
+ # Path to the `~/.config/ronin-db/databases.yml` configuration file.
36
+ PATH = File.join(DB::Home::CONFIG_DIR,'databases.yml')
37
+
38
+ # Path to the default sqlite3 database file.
39
+ DEFAULT_DB_FILE = File.join(DB::Home::LOCAL_SHARE_DIR,'default.sqlite3')
40
+
41
+ # Default database configuration.
42
+ DEFAULT_CONFIG = {
43
+ default: {
44
+ adapter: 'sqlite3',
45
+ database: DEFAULT_DB_FILE
46
+ }
47
+ }
48
+
49
+ #
50
+ # Validates the loaded configuration data from the given path.
51
+ #
52
+ # @param [String] path
53
+ # The path the configuration data was loaded from.
54
+ #
55
+ # @param [Object] data
56
+ # The loaded configuration data.
57
+ #
58
+ # @raise [InvalidConfig]
59
+ # The configuration data is not a Hash, does not contain Symbol keys,
60
+ # or does not contain Hashes.
61
+ #
62
+ # @return [true]
63
+ # The configuration data is valid.
64
+ #
65
+ def self.validate(path,data)
66
+ unless data.kind_of?(Hash)
67
+ raise(InvalidConfig)
68
+ end
69
+
70
+ data.each do |key,value|
71
+ unless (key.kind_of?(Symbol) || key.kind_of?(String))
72
+ raise(InvalidConfig)
73
+ end
74
+
75
+ unless value.kind_of?(Hash)
76
+ raise(InvalidConfig)
77
+ end
78
+
79
+ value.each_key do |sub_key|
80
+ unless (sub_key.kind_of?(Symbol) || sub_key.kind_of?(String))
81
+ raise(InvalidConfig)
82
+ end
83
+ end
84
+ end
85
+
86
+ return true
87
+ end
88
+
89
+ #
90
+ # Loads configuration data from the given path.
91
+ #
92
+ # @param [String] path
93
+ # The path to the configuration file.
94
+ #
95
+ # @return [Hash{Symbol => Hash}]
96
+ # The loaded configuration data.
97
+ #
98
+ # @raise [InvalidConfig]
99
+ # The configuration data is not a Hash, does not contain Symbol keys,
100
+ # or does not contain Hashes.
101
+ #
102
+ def self.load(path=PATH)
103
+ if File.file?(path)
104
+ config = YAML.load_file(path, symbolize_names: true).tap do |data|
105
+ validate(path,data)
106
+ end
107
+
108
+ DEFAULT_CONFIG.merge(config)
109
+ else
110
+ DEFAULT_CONFIG
111
+ end
112
+ end
113
+
114
+ #
115
+ # Opens the configuration file and edits it's contents.
116
+ #
117
+ # @yield [yaml]
118
+ # The given block will be given the loaded configuration data.
119
+ # Once the block has returned, the YAML configuration data will be
120
+ # written back to the file.
121
+ #
122
+ # @yieldparam [YAML::Store] yaml
123
+ # The loaded YAML configuration data.
124
+ #
125
+ def self.edit(path=PATH,&block)
126
+ store = YAML::Store.new(path)
127
+
128
+ store.transaction(&block)
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module DB
23
+ class UnknownDatabase < RuntimeError
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/core/home'
22
+
23
+ module Ronin
24
+ module DB
25
+ module Home
26
+ # The path to the `~/.config/ronin-db/` directory.
27
+ CONFIG_DIR = File.join(Core::Home::CONFIG_DIR,'ronin-db')
28
+
29
+ # The path to the `~/.cache/ronin-db/` directory.
30
+ CACHE_DIR = File.join(Core::Home::CACHE_DIR,'ronin-db')
31
+
32
+ # The path to the `~/.local/share/ronin-db/` directory.
33
+ LOCAL_SHARE_DIR = File.join(Core::Home::LOCAL_SHARE_DIR,'ronin-db')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module DB
23
+ # Path to `ronin-db` root directory.
24
+ #
25
+ # @api private
26
+ ROOT = File.expand_path(File.join(__dir__,'..','..','..'))
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module DB
23
+ # ronin-db version
24
+ VERSION = '0.1.0.beta1'
25
+ end
26
+ end
data/lib/ronin/db.rb ADDED
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db - A common database library for managing and querying security data.
4
+ #
5
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/exceptions'
22
+ require 'ronin/db/config_file'
23
+ require 'ronin/db/version'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Sets up the Database logger.
29
+ #
30
+ # @api semipublic
31
+ #
32
+ def self.logger=(new_logger)
33
+ require 'active_record'
34
+ ActiveRecord::Base.logger = new_logger
35
+ end
36
+
37
+ #
38
+ # `ronin-db` database(s) configuration.
39
+ #
40
+ # @return [Hash{Symbol => Hash}]
41
+ #
42
+ # @api private
43
+ #
44
+ def self.config
45
+ @config ||= ConfigFile.load
46
+ end
47
+
48
+ #
49
+ # Migrate the database up and apply any pending migrations.
50
+ #
51
+ def self.migrate!
52
+ require 'ronin/db/migrations'
53
+ Migrations.migrate
54
+ end
55
+
56
+ #
57
+ # Only migrate the database if the database is empty, otherwise warn the
58
+ # user that there are pending migrations.
59
+ #
60
+ def self.migrate
61
+ require 'ronin/db/migrations'
62
+
63
+ if Migrations.current_version == 0
64
+ # auto-run the migrations when the database is empty
65
+ Migrations.migrate
66
+ elsif Migrations.needs_migration?
67
+ # warn the user that there are pending migrations, instead of
68
+ # auto-running migrations each time
69
+ warn "WARNING: Database requires migrating!"
70
+ end
71
+ end
72
+
73
+ #
74
+ # Connects to the Database.
75
+ #
76
+ # @param [Symbol, Hash] uri
77
+ # The optional default repository to setup instead of {repositories}.
78
+ #
79
+ # @param [Boolean] migrate
80
+ # Specifies whether to hard or lazy migrate the database.
81
+ #
82
+ # @param [Boolean] load_models
83
+ # Specifies whether to load all models or just connect to the database.
84
+ #
85
+ # @raise [UnknownDatabase]
86
+ #
87
+ # @raise [ArgumentError]
88
+ #
89
+ # @api semipublic
90
+ #
91
+ def self.connect(database=:default, migrate: nil, load_models: true)
92
+ config = case database
93
+ when Hash
94
+ database
95
+ when Symbol
96
+ self.config.fetch(database) do
97
+ raise(UnknownDatabase,"unknown database: #{database.inspect}")
98
+ end
99
+ else
100
+ raise(ArgumentError,"#{self.class}.#{__method__} only accepts a Symbol or a Hash")
101
+ end
102
+
103
+ # load activerecord
104
+ require 'active_record'
105
+
106
+ # connect to the database
107
+ ActiveRecord::Base.establish_connection(config)
108
+
109
+ # migrate the database if necessary
110
+ if migrate == true then migrate!
111
+ else self.migrate
112
+ end
113
+
114
+ if load_models
115
+ # require and connect all models
116
+ require 'ronin/db/models'
117
+ Models.connect
118
+ end
119
+
120
+ return true
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,99 @@
1
+ .\" Generated by kramdown-man 0.1.8
2
+ .\" https://github.com/postmodern/kramdown-man#readme
3
+ .TH ronin-db-add 1 "2022-01-01" Ronin DB "User Manuals"
4
+ .LP
5
+ .SH SYNOPSIS
6
+ .LP
7
+ .HP
8
+ \fBronin-db add\fR \[lB]\fIoptions\fP\[rB] \fINAME\fP \[lB]\fIURI\fP\[rB]
9
+ .LP
10
+ .SH DESCRIPTION
11
+ .LP
12
+ .PP
13
+ Lists entries in the \fB~/.config/ronin-db/database.yml\fR configuration file\.
14
+ .LP
15
+ .SH ARGUMENTS
16
+ .LP
17
+ .TP
18
+ \fINAME\fP
19
+ The name of the database to add\.
20
+ .LP
21
+ .TP
22
+ \fIURI\fP
23
+ The optional URI to the database to add\.
24
+ .LP
25
+ .SH OPTIONS
26
+ .LP
27
+ .TP
28
+ \fB-A\fR, \fB--adapter\fR \fBsqlite3|mysql2|postgres|...\fR
29
+ The adapter of the database to add\.
30
+ .LP
31
+ .TP
32
+ \fB--sqlite3\fR \fIFILE\fP
33
+ Alias for \fB--adapter sqlite3 --database\fR \fIFILE\fP\.
34
+ .LP
35
+ .TP
36
+ \fB--mysql2\fR
37
+ Alias for \fB--adapter mysql2\fR\.
38
+ .LP
39
+ .TP
40
+ \fB--postgresql\fR
41
+ Alias for \fB--adapter postgresql\fR\.
42
+ .LP
43
+ .TP
44
+ \fB-H\fR, \fB--host\fR \fIHOST\fP
45
+ The host of the database to add\.
46
+ .LP
47
+ .TP
48
+ \fB-p\fR, \fB--port\fR \fIPORT\fP
49
+ The port of the database to add\.
50
+ .LP
51
+ .TP
52
+ \fB-u\fR, \fB--username\fR \fIUSER\fP
53
+ The username to authenticate with for the database\.
54
+ .LP
55
+ .TP
56
+ \fB-P\fR, \fB--password\fR \fIPASSWORD\fP
57
+ The password to authenticate with for the database\.
58
+ .LP
59
+ .TP
60
+ \fB--read-password\fR
61
+ Reads the database password from STDIN\.
62
+ .LP
63
+ .TP
64
+ \fB-D\fR, \fB--database\fR \fINAME\fP\[or]\fIPATH\fP
65
+ The database name to connect to\. If \fB--adapter sqlite3\fR is given then a path
66
+ may be given instead\.
67
+ .LP
68
+ .TP
69
+ \fB-h\fR, \fB--help\fR
70
+ Print help information\.
71
+ .LP
72
+ .SH FILES
73
+ .LP
74
+ .TP
75
+ \fI\[ti]\[sl]\.config\[sl]ronin\-db\[sl]database\.yml\fP
76
+ The \fBronin-db\fR database(s) configuration file\.
77
+ .LP
78
+ .SH ENVIRONMENT
79
+ .LP
80
+ .PP
81
+ HOME
82
+ Specifies the home directory of the user\. Ronin will search for the
83
+ \fI\[ti]\[sl]\.config\[sl]ronin\-db\fP cache directory within the home directory\.
84
+ .LP
85
+ .PP
86
+ XDG\[ru]CONFIG\[ru]HOME
87
+ Specifies the cache directory to use\. Defaults to \fI\[Do]HOME\[sl]\.config\fP\.
88
+ .LP
89
+ .SH AUTHOR
90
+ .LP
91
+ .PP
92
+ Postmodern
93
+ .MT postmodern\.mod3\[at]gmail\.com
94
+ .ME
95
+ .LP
96
+ .SH SEE ALSO
97
+ .LP
98
+ .PP
99
+ ronin\-db(1) ronin\-db\-list(1) ronin\-db\-edit(1) ronin\-db\-remove(1)