Class: Comet::MongoDBConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/models/mongo_dbconnection.rb

Overview

MongoDBConnection is a typed class wrapper around the underlying Comet Server API data structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMongoDBConnection

Returns a new instance of MongoDBConnection.



78
79
80
# File 'lib/comet/models/mongo_dbconnection.rb', line 78

def initialize
  clear
end

Instance Attribute Details

#allow_invalid_certificateObject

Returns the value of attribute allow_invalid_certificate.



64
65
66
# File 'lib/comet/models/mongo_dbconnection.rb', line 64

def allow_invalid_certificate
  @allow_invalid_certificate
end

#allow_invalid_hostnameObject

Returns the value of attribute allow_invalid_hostname.



67
68
69
# File 'lib/comet/models/mongo_dbconnection.rb', line 67

def allow_invalid_hostname
  @allow_invalid_hostname
end

#authentication_dbObject

Returns the value of attribute authentication_db.



28
29
30
# File 'lib/comet/models/mongo_dbconnection.rb', line 28

def authentication_db
  @authentication_db
end

#client_sslpempathObject

Returns the value of attribute client_sslpempath.



55
56
57
# File 'lib/comet/models/mongo_dbconnection.rb', line 55

def client_sslpempath
  @client_sslpempath
end

#mongo_shell_pathObject

Deprecated.

This member has been deprecated since Comet version 22.12.3

Prior to Comet 22.12.3, must be a filesystem path to ‘mongo` (n.b. not `mongosh`). In Comet >= 22.12.3, not used.



34
35
36
# File 'lib/comet/models/mongo_dbconnection.rb', line 34

def mongo_shell_path
  @mongo_shell_path
end

#mongodump_pathObject

Returns the value of attribute mongodump_path.



37
38
39
# File 'lib/comet/models/mongo_dbconnection.rb', line 37

def mongodump_path
  @mongodump_path
end

#passwordObject

Returns the value of attribute password.



25
26
27
# File 'lib/comet/models/mongo_dbconnection.rb', line 25

def password
  @password
end

#portObject

Returns the value of attribute port.



19
20
21
# File 'lib/comet/models/mongo_dbconnection.rb', line 19

def port
  @port
end

#read_preferenceObject

Returns the value of attribute read_preference.



40
41
42
# File 'lib/comet/models/mongo_dbconnection.rb', line 40

def read_preference
  @read_preference
end

#replica_membersObject

Returns the value of attribute replica_members.



49
50
51
# File 'lib/comet/models/mongo_dbconnection.rb', line 49

def replica_members
  @replica_members
end

#replica_nameObject

Returns the value of attribute replica_name.



46
47
48
# File 'lib/comet/models/mongo_dbconnection.rb', line 46

def replica_name
  @replica_name
end

#serverObject

Returns the value of attribute server.



16
17
18
# File 'lib/comet/models/mongo_dbconnection.rb', line 16

def server
  @server
end

#server_sslpempathObject

Returns the value of attribute server_sslpempath.



58
59
60
# File 'lib/comet/models/mongo_dbconnection.rb', line 58

def server_sslpempath
  @server_sslpempath
end

#sshconnectionObject

Returns the value of attribute sshconnection.



73
74
75
# File 'lib/comet/models/mongo_dbconnection.rb', line 73

def sshconnection
  @sshconnection
end

#sslclient_key_passwordObject

Returns the value of attribute sslclient_key_password.



61
62
63
# File 'lib/comet/models/mongo_dbconnection.rb', line 61

def sslclient_key_password
  @sslclient_key_password
end

#unknown_json_fieldsObject

Returns the value of attribute unknown_json_fields.



76
77
78
# File 'lib/comet/models/mongo_dbconnection.rb', line 76

def unknown_json_fields
  @unknown_json_fields
end

#use_replicaObject

Returns the value of attribute use_replica.



43
44
45
# File 'lib/comet/models/mongo_dbconnection.rb', line 43

def use_replica
  @use_replica
end

#use_sshObject

Returns the value of attribute use_ssh.



70
71
72
# File 'lib/comet/models/mongo_dbconnection.rb', line 70

def use_ssh
  @use_ssh
end

#use_sslObject

Returns the value of attribute use_ssl.



52
53
54
# File 'lib/comet/models/mongo_dbconnection.rb', line 52

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



22
23
24
# File 'lib/comet/models/mongo_dbconnection.rb', line 22

def username
  @username
end

Instance Method Details

#clearObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/comet/models/mongo_dbconnection.rb', line 82

def clear
  @server = ''
  @port = 0
  @username = ''
  @password = ''
  @authentication_db = ''
  @mongo_shell_path = ''
  @mongodump_path = ''
  @read_preference = ''
  @replica_name = ''
  @replica_members = []
  @client_sslpempath = ''
  @server_sslpempath = ''
  @sslclient_key_password = ''
  @sshconnection = Comet::SSHConnection.new
  @unknown_json_fields = {}
end

#from_hash(obj) ⇒ Object

Parameters:

  • obj (Hash)

    The complete object as a Ruby hash

Raises:

  • (TypeError)


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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/comet/models/mongo_dbconnection.rb', line 108

def from_hash(obj)
  raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash

  obj.each do |k, v|
    case k
    when 'Server'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @server = v
    when 'Port'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @port = v
    when 'Username'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @username = v
    when 'Password'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @password = v
    when 'AuthenticationDB'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @authentication_db = v
    when 'MongoShellPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @mongo_shell_path = v
    when 'MongodumpPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @mongodump_path = v
    when 'ReadPreference'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @read_preference = v
    when 'UseReplica'
      @use_replica = v
    when 'ReplicaName'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @replica_name = v
    when 'ReplicaMembers'
      if v.nil?
        @replica_members = []
      else
        @replica_members = Array.new(v.length)
        v.each_with_index do |v1, i1|
          raise TypeError, "'v1' expected String, got #{v1.class}" unless v1.is_a? String

          @replica_members[i1] = v1
        end
      end
    when 'UseSSL'
      @use_ssl = v
    when 'ClientSSLPEMPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @client_sslpempath = v
    when 'ServerSSLPEMPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @server_sslpempath = v
    when 'SSLClientKeyPassword'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @sslclient_key_password = v
    when 'AllowInvalidCertificate'
      @allow_invalid_certificate = v
    when 'AllowInvalidHostname'
      @allow_invalid_hostname = v
    when 'UseSSH'
      @use_ssh = v
    when 'SSHConnection'
      @sshconnection = Comet::SSHConnection.new
      @sshconnection.from_hash(v)
    else
      @unknown_json_fields[k] = v
    end
  end
end

#from_json(json_string) ⇒ Object

Parameters:

  • json_string (String)

    The complete object in JSON format

Raises:

  • (TypeError)


101
102
103
104
105
# File 'lib/comet/models/mongo_dbconnection.rb', line 101

def from_json(json_string)
  raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String

  from_hash(JSON.parse(json_string))
end

#to_hHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



222
223
224
# File 'lib/comet/models/mongo_dbconnection.rb', line 222

def to_h
  to_hash
end

#to_hashHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/comet/models/mongo_dbconnection.rb', line 192

def to_hash
  ret = {}
  ret['Server'] = @server
  ret['Port'] = @port
  ret['Username'] = @username
  ret['Password'] = @password
  ret['AuthenticationDB'] = @authentication_db
  ret['MongoShellPath'] = @mongo_shell_path
  ret['MongodumpPath'] = @mongodump_path
  ret['ReadPreference'] = @read_preference
  ret['UseReplica'] = @use_replica
  ret['ReplicaName'] = @replica_name
  ret['ReplicaMembers'] = @replica_members
  ret['UseSSL'] = @use_ssl
  ret['ClientSSLPEMPath'] = @client_sslpempath
  ret['ServerSSLPEMPath'] = @server_sslpempath
  ret['SSLClientKeyPassword'] = @sslclient_key_password
  ret['AllowInvalidCertificate'] = @allow_invalid_certificate
  ret['AllowInvalidHostname'] = @allow_invalid_hostname
  ret['UseSSH'] = @use_ssh
  unless @sshconnection.nil?
    ret['SSHConnection'] = @sshconnection
  end
  @unknown_json_fields.each do |k, v|
    ret[k] = v
  end
  ret
end

#to_json(options = {}) ⇒ String

Returns The complete object as a JSON string.

Returns:

  • (String)

    The complete object as a JSON string



227
228
229
# File 'lib/comet/models/mongo_dbconnection.rb', line 227

def to_json(options = {})
  to_hash.to_json(options)
end