Class: Kward::Transport::Host
- Inherits:
-
Object
- Object
- Kward::Transport::Host
- Defined in:
- lib/kward/transport/host.rb
Overview
Public dependencies made available to a running transport adapter.
Defined Under Namespace
Classes: AllowAllPolicy, Interactions, PluginChat, PluginChatHandle, PluginChatTurn, PluginChatTurnHandle, PluginChats, PolicyDenied, Session, SessionHandle, Sessions, Turn, TurnHandle, UnavailableGateway
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#execution_profile ⇒ Object
readonly
Returns the value of attribute execution_profile.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#transport_id ⇒ Object
readonly
Returns the value of attribute transport_id.
Instance Method Summary collapse
- #authorize!(action, **attributes) ⇒ Object
- #gateway ⇒ Object
-
#initialize(transport_id:, gateway: nil, plugin_chat_gateway: nil, config: {}, storage: nil, policy: nil, logger: nil, execution_profile: nil) ⇒ Host
constructor
Creates a host for one registered transport instance.
- #interactions ⇒ Object
- #plugin_chat_gateway ⇒ Object
- #plugin_chats ⇒ Object
-
#secret(key, env: nil) ⇒ Object
Reads a transport secret from private config or an explicit environment variable without exposing it through status or logging helpers.
- #sessions ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(transport_id:, gateway: nil, plugin_chat_gateway: nil, config: {}, storage: nil, policy: nil, logger: nil, execution_profile: nil) ⇒ Host
Creates a host for one registered transport instance.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kward/transport/host.rb', line 17 def initialize(transport_id:, gateway: nil, plugin_chat_gateway: nil, config: {}, storage: nil, policy: nil, logger: nil, execution_profile: nil) unless execution_profile.nil? || execution_profile.is_a?(ExecutionProfile) raise ArgumentError, "execution_profile must be a Transport::ExecutionProfile" end @transport_id = transport_id.to_s.freeze @gateway = gateway @plugin_chat_gateway = plugin_chat_gateway @config = freeze_copy(config) @storage = storage || Store.new(@transport_id) @policy = policy || AllowAllPolicy.new @execution_profile = execution_profile @logger = logger || Logger.new($stderr) @sessions = Sessions.new(self) @plugin_chats = PluginChats.new(self) @interactions = Interactions.new(self) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def config @config end |
#execution_profile ⇒ Object (readonly)
Returns the value of attribute execution_profile.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def execution_profile @execution_profile end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def logger @logger end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def policy @policy end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def storage @storage end |
#transport_id ⇒ Object (readonly)
Returns the value of attribute transport_id.
35 36 37 |
# File 'lib/kward/transport/host.rb', line 35 def transport_id @transport_id end |
Instance Method Details
#authorize!(action, **attributes) ⇒ Object
55 56 57 58 59 |
# File 'lib/kward/transport/host.rb', line 55 def (action, **attributes) return true if policy.(action: action, transport_id: @transport_id, **attributes) == true raise PolicyDenied, "Transport policy denied #{action}" end |
#gateway ⇒ Object
49 50 51 52 53 |
# File 'lib/kward/transport/host.rb', line 49 def gateway return @gateway if @gateway raise UnavailableGateway, "transport host has no session gateway" end |
#interactions ⇒ Object
41 42 43 |
# File 'lib/kward/transport/host.rb', line 41 def interactions @interactions end |
#plugin_chat_gateway ⇒ Object
61 62 63 64 65 |
# File 'lib/kward/transport/host.rb', line 61 def plugin_chat_gateway return @plugin_chat_gateway if @plugin_chat_gateway raise UnavailableGateway, "transport host has no plugin chat gateway" end |
#plugin_chats ⇒ Object
45 46 47 |
# File 'lib/kward/transport/host.rb', line 45 def plugin_chats @plugin_chats end |
#secret(key, env: nil) ⇒ Object
Reads a transport secret from private config or an explicit environment variable without exposing it through status or logging helpers.
69 70 71 72 73 74 75 76 77 |
# File 'lib/kward/transport/host.rb', line 69 def secret(key, env: nil) key = key.to_s raise ArgumentError, "secret key is required" if key.empty? value = config[key] value = ENV.fetch(env.to_s) if value.nil? && env value = ENV[default_secret_env_name(key)] if value.nil? value.to_s unless value.nil? end |
#sessions ⇒ Object
37 38 39 |
# File 'lib/kward/transport/host.rb', line 37 def sessions @sessions end |
#shutdown ⇒ Object
79 80 81 82 83 |
# File 'lib/kward/transport/host.rb', line 79 def shutdown @gateway&.shutdown @plugin_chat_gateway&.shutdown nil end |