CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/base/persistent_storage.rb
Views: 11780
1
# -*- coding: binary -*-
2
module Msf
3
4
# This class provides a generalized interface to persisting information,
5
# either in whole or in part, about the state of the framework. This can
6
# be used to store data that can later be reinitialized in a new instance
7
# of the framework or to provide a simple mechanism for generating reports
8
# of some form.
9
#
10
# @abstract Subclass and override {#initialize}, {#store}, and {#fetch}.
11
class PersistentStorage
12
13
@@storage_classes = {}
14
15
# Creates an instance of the storage class with the supplied name. The
16
# array supplied as an argument is passed to the constructor of the
17
# associated class as a means of generic initialization.
18
#
19
# @param name [String] the name of the storage class.
20
# @param params [Object] the parameters to give the new class.
21
# @return [PersistentStorage] the newly created class.
22
# @return [nil] if class has not been added through {.add_storage_class}.
23
def self.create(name, *params)
24
if (klass = @@storage_classes[name])
25
klass.new(*params)
26
else
27
nil
28
end
29
end
30
31
# Stub initialization routine that takes the params passed to create.
32
#
33
# @param params [Object] the parameters to initialize with.
34
def initialize(*params)
35
end
36
37
# This methods stores all or part of the current state of the supplied
38
# framework instance to whatever medium the derived class implements.
39
# If the derived class does not implement this method, the
40
# NotImplementedError is raised.
41
#
42
# @param framework [Msf::Framework] framework state to store.
43
# @return [void] no implementation.
44
# @raise [NotImpementedError] raised if not implemented.
45
def store(framework)
46
raise NotImplementedError
47
end
48
49
# This method initializes the supplied framework instance with the state
50
# that is stored in the persisted backing that the derived class
51
# implements. If the derived class does not implement this method, the
52
# NotImplementedError is raised.
53
#
54
# @param framework [Msf::Framework] framework to restore state to.
55
# @return [void] no implementation.
56
# @raise [NotImplementedError] raised if not implemented.
57
def fetch(framework)
58
raise NotImplementedError
59
end
60
61
# This method adds a new storage class to the hash of storage classes that
62
# can be created through create.
63
#
64
# @param name [String] the name of the storage class.
65
# @param klass [PersistentStorage] the storage class to add.
66
# @return [void]
67
def self.add_storage_class(name, klass)
68
@@storage_classes[name] = klass
69
end
70
71
protected
72
73
end
74
75
end
76
77
78