Class: CtRegisterMicroservice::ControlTower
- Inherits:
-
Object
- Object
- CtRegisterMicroservice::ControlTower
- Defined in:
- lib/ct_register_microservice/control_tower.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#ct_url ⇒ Object
readonly
Returns the value of attribute ct_url.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#swagger ⇒ Object
readonly
Returns the value of attribute swagger.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize ⇒ ControlTower
constructor
A new instance of ControlTower.
- #initialize_options ⇒ Object
-
#microservice_request(uri, method, headers = {}, body = nil) ⇒ Object
TODO: make sure it works as intended, add unit tests.
- #register_service(active = true) ⇒ Object
Constructor Details
#initialize ⇒ ControlTower
Returns a new instance of ControlTower.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ct_register_microservice/control_tower.rb', line 5 def initialize if CtRegisterMicroservice.config.ct_url.nil? raise MissingConfigError, 'Could not register microservice - No Control Tower URL defined' end if CtRegisterMicroservice.config.url.nil? raise MissingConfigError, 'Could not register microservice - No self URL defined' end if CtRegisterMicroservice.config.ct_token.nil? raise MissingConfigError, 'Could not register microservice - No Control Tower auth token found' end if CtRegisterMicroservice.config.swagger.nil? raise MissingConfigError, 'Could not register microservice - No swagger file defined' end if !File.exist?(CtRegisterMicroservice.config.swagger) raise MissingConfigError, 'Could not register microservice - Swagger file path ' + File.absolute_path(CtRegisterMicroservice.config.swagger) + 'does not match a file' end if CtRegisterMicroservice.config.name.nil? raise MissingConfigError, 'Could not register microservice - Microservice name not defined' end @options = OpenStruct.new end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def credentials @credentials end |
#ct_url ⇒ Object (readonly)
Returns the value of attribute ct_url.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def ct_url @ct_url end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def response @response end |
#swagger ⇒ Object (readonly)
Returns the value of attribute swagger.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def swagger @swagger end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
28 29 30 |
# File 'lib/ct_register_microservice/control_tower.rb', line 28 def url @url end |
Instance Method Details
#initialize_options ⇒ Object
54 55 56 |
# File 'lib/ct_register_microservice/control_tower.rb', line 54 def @options = OpenStruct.new end |
#microservice_request(uri, method, headers = {}, body = nil) ⇒ Object
TODO: make sure it works as intended, add unit tests
44 45 46 47 48 49 50 51 52 |
# File 'lib/ct_register_microservice/control_tower.rb', line 44 def microservice_request(uri, method, headers = {}, body = nil) .http_method = method .endpoint = uri .headers = headers .headers['authorization'] = 'Bearer '+CtRegisterMicroservice.config.ct_token .body = body result = make_call() result end |
#register_service(active = true) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ct_register_microservice/control_tower.rb', line 30 def register_service(active = true) .http_method = "post" .endpoint = "/api/v1/microservice" .query_string = false .body = { name: CtRegisterMicroservice.config.name, url: CtRegisterMicroservice.config.url, active: !!active }.to_json result = make_call() result end |