Class: Saro::Dat::DatCmsManagerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/saro/dat/dat_cms_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeDatCmsManagerBuilder

Returns a new instance of DatCmsManagerBuilder.



228
229
230
231
232
233
# File 'lib/saro/dat/dat_cms_manager.rb', line 228

def initialize
  @uri = "http://localhost:8088"
  @token = ""
  @verify_only = false
  @interval_seconds = 60
end

Instance Method Details

#buildObject



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/saro/dat/dat_cms_manager.rb', line 260

def build
  parsed =
    begin
      URI.parse(@uri)
    rescue URI::InvalidURIError => e
      raise Saro::Dat::Error.new(Saro::Dat::ErrorCode::CONFIG_URI_INVALID, "cannot be parsed as a uri", cause: e)
    end

  unless %w[http https].include?(parsed.scheme)
    raise Saro::Dat::Error.new(Saro::Dat::ErrorCode::CONFIG_URI_INVALID, "scheme must be http or https")
  end
  if parsed.path && parsed.path != '' && parsed.path != '/'
    raise Saro::Dat::Error.new(Saro::Dat::ErrorCode::CONFIG_URI_INVALID, "must be path-less: #{@uri}")
  end
  if parsed.query
    raise Saro::Dat::Error.new(Saro::Dat::ErrorCode::CONFIG_URI_INVALID, "must be query-less: #{@uri}")
  end

  path = @verify_only ? "/v1/certs/verify-only" : "/v1/certs"
  final_uri = "#{parsed.scheme}://#{parsed.host}:#{parsed.port}#{path}"

  DatCmsManager.new(
    uri: final_uri,
    token: @token,
    interval_seconds: @interval_seconds,
    verify_only: @verify_only
  )
end

#interval_offObject



255
256
257
258
# File 'lib/saro/dat/dat_cms_manager.rb', line 255

def interval_off
  @interval_seconds = 0
  self
end

#interval_seconds(interval_seconds) ⇒ Object



250
251
252
253
# File 'lib/saro/dat/dat_cms_manager.rb', line 250

def interval_seconds(interval_seconds)
  @interval_seconds = interval_seconds
  self
end

#token(token) ⇒ Object



240
241
242
243
# File 'lib/saro/dat/dat_cms_manager.rb', line 240

def token(token)
  @token = token
  self
end

#uri(uri) ⇒ Object



235
236
237
238
# File 'lib/saro/dat/dat_cms_manager.rb', line 235

def uri(uri)
  @uri = uri.delete_suffix('/')
  self
end

#verify_only(verify_only) ⇒ Object



245
246
247
248
# File 'lib/saro/dat/dat_cms_manager.rb', line 245

def verify_only(verify_only)
  @verify_only = verify_only
  self
end