From 6b7f5ed3d9a39eda1f5a1e78b9e5f2bf947f032d Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Wed, 2 Oct 2024 17:05:35 -0700 Subject: [PATCH] feedback --- lib/livekit/auth_mixin.rb | 6 ++++-- lib/livekit/egress_service_client.rb | 18 +++++++++--------- lib/livekit/ingress_service_client.rb | 8 ++++---- lib/livekit/room_service_client.rb | 22 +++++++++++----------- lib/livekit/sip_service_client.rb | 20 ++++++++++---------- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/lib/livekit/auth_mixin.rb b/lib/livekit/auth_mixin.rb index 2f5a1e8..42e2349 100644 --- a/lib/livekit/auth_mixin.rb +++ b/lib/livekit/auth_mixin.rb @@ -4,12 +4,14 @@ module LiveKit # Create authenticated headers when keys are provided module AuthMixin def auth_header( - video_grant, + video_grant: nil, sip_grant: nil ) headers = {} t = ::LiveKit::AccessToken.new(api_key: @api_key, api_secret: @api_secret) - t.add_grant(video_grant) + if video_grant != nil + t.add_grant(video_grant) + end if sip_grant != nil t.add_sip_grant(sip_grant) end diff --git a/lib/livekit/egress_service_client.rb b/lib/livekit/egress_service_client.rb index fedadcb..47a5efb 100644 --- a/lib/livekit/egress_service_client.rb +++ b/lib/livekit/egress_service_client.rb @@ -46,7 +46,7 @@ def start_room_composite_egress( self.rpc( :StartRoomCompositeEgress, request, - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -73,7 +73,7 @@ def start_participant_egress( self.rpc( :StartParticipantEgress, request, - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -101,7 +101,7 @@ def start_track_composite_egress( self.rpc( :StartTrackCompositeEgress, request, - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -123,7 +123,7 @@ def start_track_egress( self.rpc( :StartTrackEgress, request, - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -154,7 +154,7 @@ def start_web_egress( self.rpc( :StartWebEgress, request, - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -165,7 +165,7 @@ def update_layout(egress_id, layout) egress_id: egress_id, layout: layout, ), - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -180,7 +180,7 @@ def update_stream(egress_id, add_output_urls: add_output_urls, remove_output_urls: remove_output_urls, ), - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -197,7 +197,7 @@ def list_egress( active: active, egress_id: egress_id, ), - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end @@ -205,7 +205,7 @@ def stop_egress(egress_id) self.rpc( :StopEgress, Proto::StopEgressRequest.new(egress_id: egress_id), - headers: auth_header(VideoGrant.new(roomRecord: true)), + headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)), ) end diff --git a/lib/livekit/ingress_service_client.rb b/lib/livekit/ingress_service_client.rb index 051aa3f..2645e7b 100644 --- a/lib/livekit/ingress_service_client.rb +++ b/lib/livekit/ingress_service_client.rb @@ -51,7 +51,7 @@ def create_ingress( self.rpc( :CreateIngress, request, - headers: auth_header(VideoGrant.new(ingressAdmin: true)), + headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)), ) end @@ -89,7 +89,7 @@ def update_ingress( self.rpc( :UpdateIngress, request, - headers: auth_header(VideoGrant.new(ingressAdmin: true)), + headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)), ) end @@ -106,7 +106,7 @@ def list_ingress( self.rpc( :ListIngress, request, - headers: auth_header(VideoGrant.new(ingressAdmin: true)), + headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)), ) end @@ -117,7 +117,7 @@ def delete_ingress(ingress_id) self.rpc( :DeleteIngress, request, - headers: auth_header(VideoGrant.new(ingressAdmin: true)), + headers:auth_header(video_grant: VideoGrant.new(ingressAdmin: true)), ) end end diff --git a/lib/livekit/room_service_client.rb b/lib/livekit/room_service_client.rb index 8689c06..a6f66d1 100644 --- a/lib/livekit/room_service_client.rb +++ b/lib/livekit/room_service_client.rb @@ -39,7 +39,7 @@ def create_room(name, max_playout_delay: max_playout_delay, sync_streams: sync_streams ), - headers: auth_header(VideoGrant.new(roomCreate: true)), + headers:auth_header(video_grant: VideoGrant.new(roomCreate: true)), ) end @@ -47,7 +47,7 @@ def list_rooms(names: nil) self.rpc( :ListRooms, Proto::ListRoomsRequest.new(names: names), - headers: auth_header(VideoGrant.new(roomList: true)), + headers:auth_header(video_grant: VideoGrant.new(roomList: true)), ) end @@ -55,7 +55,7 @@ def delete_room(room:) self.rpc( :DeleteRoom, Proto::DeleteRoomRequest.new(room: room), - headers: auth_header(VideoGrant.new(roomCreate: true)), + headers:auth_header(video_grant: VideoGrant.new(roomCreate: true)), ) end @@ -63,7 +63,7 @@ def update_room_metadata(room:, metadata:) self.rpc( :UpdateRoomMetadata, Proto::UpdateRoomMetadataRequest.new(room: room, metadata: metadata), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -71,7 +71,7 @@ def list_participants(room:) self.rpc( :ListParticipants, Proto::ListParticipantsRequest.new(room: room), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -79,7 +79,7 @@ def get_participant(room:, identity:) self.rpc( :GetParticipant, Proto::RoomParticipantIdentity.new(room: room, identity: identity), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -87,7 +87,7 @@ def remove_participant(room:, identity:) self.rpc( :RemoveParticipant, Proto::RoomParticipantIdentity.new(room: room, identity: identity), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -100,7 +100,7 @@ def mute_published_track(room:, identity:, track_sid:, muted:) track_sid: track_sid, muted: muted, ), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -132,7 +132,7 @@ def update_participant( self.rpc( :UpdateParticipant, req, - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -145,7 +145,7 @@ def update_subscriptions(room:, identity:, track_sids:, subscribe:) track_sids: track_sids, subscribe: subscribe, ), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end @@ -162,7 +162,7 @@ def send_data(room:, data:, kind:, destination_sids: destination_sids, destination_identities: destination_identities, ), - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room)), + headers:auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room)), ) end end diff --git a/lib/livekit/sip_service_client.rb b/lib/livekit/sip_service_client.rb index cc89790..6027475 100644 --- a/lib/livekit/sip_service_client.rb +++ b/lib/livekit/sip_service_client.rb @@ -49,7 +49,7 @@ def create_sip_inbound_trunk( self.rpc( :CreateSIPInboundTrunk, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -88,7 +88,7 @@ def create_sip_outbound_trunk( self.rpc( :CreateSIPOutboundTrunk, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -97,7 +97,7 @@ def list_sip_inbound_trunk self.rpc( :ListSIPInboundTrunk, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -106,7 +106,7 @@ def list_sip_outbound_trunk self.rpc( :ListSIPOutboundTrunk, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -117,7 +117,7 @@ def delete_sip_trunk(sip_trunk_id) self.rpc( :DeleteSIPTrunk, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -142,7 +142,7 @@ def create_sip_dispatch_rule( self.rpc( :CreateSIPDispatchRule, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -151,7 +151,7 @@ def list_sip_dispatch_rule self.rpc( :ListSIPDispatchRule, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -162,7 +162,7 @@ def delete_sip_dispatch_rule(sip_dispatch_rule_id) self.rpc( :DeleteSIPDispatchRule, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(admin: true)), + headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end @@ -191,7 +191,7 @@ def create_sip_participant( self.rpc( :CreateSIPParticipant, request, - headers: auth_header(nil, sip_grant: SIPGrant.new(call: true)), + headers: auth_header(sip_grant: SIPGrant.new(call: true)), ) end @@ -209,7 +209,7 @@ def transfer_sip_participant( self.rpc( :TransferSIPParticipant, request, - headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)), + headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)), ) end end