Module: CRUDJT::Config
- Extended by:
- FFI::Library
- Defined in:
- lib/crudjt.rb
Constant Summary collapse
- GRPC_HOST =
'127.0.0.1'- GRPC_PORT =
50051
Class Method Summary collapse
- .check_secret_key ⇒ Object
- .connect_to_master(options = {}) ⇒ Object
- .master? ⇒ Boolean
- .secret_key(value) ⇒ Object
- .start_master(options = {}) ⇒ Object
- .stub ⇒ Object
- .was_started ⇒ Object
Class Method Details
.check_secret_key ⇒ Object
61 62 63 |
# File 'lib/crudjt.rb', line 61 def check_secret_key @settings[:secret_key] end |
.connect_to_master(options = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/crudjt.rb', line 112 def connect_to_master( = {}) raise CRUDJT::Validation.(CRUDJT::Validation::ERROR_ALREADY_STARTED) if was_started @settings[:grpc_host] = [:grpc_host] || GRPC_HOST @settings[:grpc_port] = [:grpc_port] || GRPC_PORT port = "#{@settings[:grpc_host]}:#{@settings[:grpc_port]}" @_channel = GRPC::Core::Channel.new( port, nil, :this_channel_is_insecure ) @stub = Token::TokenService::Stub.new( port, :this_channel_is_insecure ) @settings[:master] = false @was_started = true end |
.master? ⇒ Boolean
72 73 74 |
# File 'lib/crudjt.rb', line 72 def master? @settings[:master] end |
.secret_key(value) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/crudjt.rb', line 65 def secret_key(value) CRUDJT::Validation.validate_secret_key!(value) @settings[:secret_key] = value self end |
.start_master(options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/crudjt.rb', line 84 def start_master( = {}) raise CRUDJT::Validation.(CRUDJT::Validation::ERROR_ALREADY_STARTED) if was_started raise CRUDJT::Validation.(CRUDJT::Validation::ERROR_SECRET_KEY_NOT_SET) unless [:secret_key] CRUDJT::Validation.validate_secret_key!([:secret_key]) @settings[:store_jt_path] = [:store_jt_path] @settings[:grpc_host] = [:grpc_host] || GRPC_HOST @settings[:grpc_port] = [:grpc_port] || GRPC_PORT result = JSON(start_store_jt([:secret_key], @settings[:store_jt_path])) raise CRUDJT::ERRORS[result['code']], result['error_message'] unless result['ok'] port = "#{@settings[:grpc_host]}:#{@settings[:grpc_port]}" grpc_server = TokenServiceImpl.call(port) at_exit do grpc_server.stop end Thread.new do grpc_server.run_till_terminated end @settings[:master] = true @was_started = true end |
.stub ⇒ Object
80 81 82 |
# File 'lib/crudjt.rb', line 80 def stub @stub end |
.was_started ⇒ Object
76 77 78 |
# File 'lib/crudjt.rb', line 76 def was_started @was_started end |