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

Class Method Details

.check_secret_keyObject



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(options = {})
  raise CRUDJT::Validation.error_message(CRUDJT::Validation::ERROR_ALREADY_STARTED) if was_started

  @settings[:grpc_host] = options[:grpc_host] || GRPC_HOST
  @settings[:grpc_port] = options[: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

Returns:

  • (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

Raises:

  • ()


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(options = {})
  raise CRUDJT::Validation.error_message(CRUDJT::Validation::ERROR_ALREADY_STARTED) if was_started
  raise CRUDJT::Validation.error_message(CRUDJT::Validation::ERROR_SECRET_KEY_NOT_SET) unless options[:secret_key]

  CRUDJT::Validation.validate_secret_key!(options[:secret_key])

  @settings[:store_jt_path] = options[:store_jt_path]
  @settings[:grpc_host] = options[:grpc_host] || GRPC_HOST
  @settings[:grpc_port] = options[:grpc_port] || GRPC_PORT

  result = JSON(start_store_jt(options[: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

.stubObject



80
81
82
# File 'lib/crudjt.rb', line 80

def stub
  @stub
end

.was_startedObject



76
77
78
# File 'lib/crudjt.rb', line 76

def was_started
  @was_started
end