Skip to content

Commit

Permalink
Add RedactAutoEncodedOutput to support redacting auto egress types (#712
Browse files Browse the repository at this point in the history
)

Also redact image outputs, and support AliOSS uploads for auto egress

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
biglittlebigben and github-actions[bot] authored May 10, 2024
1 parent dd69a5f commit 93a26f4
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 319 deletions.
8 changes: 8 additions & 0 deletions .changeset/beige-stingrays-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"github.com/livekit/protocol": minor
"@livekit/protocol": minor
---

- Add RedactAutoEncodedOutput to support redacting auto egress types
- Redact image outputs
- Support AliOSS uploads for auto egress
15 changes: 12 additions & 3 deletions egress/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ func RedactUpload(req UploadRequest) {
}
}

func RedactEncodedOutputs(out EncodedOutput) {
func RedactAutoEncodedOutput(out AutoEncodedOutput) {
if files := out.GetFileOutputs(); len(files) == 1 {
RedactUpload(files[0])
}
if segments := out.GetSegmentOutputs(); len(segments) == 1 {
RedactUpload(segments[0])
}
}

func RedactEncodedOutputs(out EncodedOutput) {
RedactAutoEncodedOutput(out)

if streams := out.GetStreamOutputs(); len(streams) == 1 {
RedactStreamKeys(streams[0])
}
if segments := out.GetSegmentOutputs(); len(segments) == 1 {
RedactUpload(segments[0])
if images := out.GetImageOutputs(); len(images) == 1 {
RedactUpload(images[0])
}

if o, ok := out.(EncodedOutputDeprecated); ok {
if file := o.GetFile(); file != nil {
RedactUpload(file)
Expand Down
26 changes: 12 additions & 14 deletions egress/redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
file1 = &livekit.EncodedFileOutput{
file = &livekit.EncodedFileOutput{
Output: &livekit.EncodedFileOutput_S3{
S3: &livekit.S3Upload{
AccessKey: "ACCESS_KEY",
Expand All @@ -19,8 +19,8 @@ var (
},
}

file2 = &livekit.EncodedFileOutput{
Output: &livekit.EncodedFileOutput_AliOSS{
image = &livekit.ImageOutput{
Output: &livekit.ImageOutput_AliOSS{
AliOSS: &livekit.AliOSSUpload{
AccessKey: "ACCESS_KEY",
Secret: "LONG_SECRET_STRING",
Expand All @@ -47,18 +47,17 @@ var (
)

func TestRedactUpload(t *testing.T) {

cl := proto.Clone(file1)
cl := proto.Clone(file)
RedactUpload(cl.(UploadRequest))

require.Equal(t, "{access_key}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.AccessKey)
require.Equal(t, "{secret}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.Secret)

cl = proto.Clone(file2)
cl = proto.Clone(image)
RedactUpload(cl.(UploadRequest))

require.Equal(t, "{access_key}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_AliOSS).AliOSS.AccessKey)
require.Equal(t, "{secret}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_AliOSS).AliOSS.Secret)
require.Equal(t, "{access_key}", cl.(*livekit.ImageOutput).Output.(*livekit.ImageOutput_AliOSS).AliOSS.AccessKey)
require.Equal(t, "{secret}", cl.(*livekit.ImageOutput).Output.(*livekit.ImageOutput_AliOSS).AliOSS.Secret)

cl = proto.Clone(segments)
RedactUpload(cl.(UploadRequest))
Expand All @@ -70,7 +69,6 @@ func TestRedactUpload(t *testing.T) {

require.Equal(t, "{account_name}", cl.(*livekit.DirectFileOutput).Output.(*livekit.DirectFileOutput_Azure).Azure.AccountName)
require.Equal(t, "{account_key}", cl.(*livekit.DirectFileOutput).Output.(*livekit.DirectFileOutput_Azure).Azure.AccountKey)

}

func TestRedactStreamOutput(t *testing.T) {
Expand All @@ -87,7 +85,7 @@ func TestRedactStreamOutput(t *testing.T) {
func TestRedactEncodedOutputs(t *testing.T) {
trackComposite := &livekit.TrackCompositeEgressRequest{
FileOutputs: []*livekit.EncodedFileOutput{
file1,
file,
},
}

Expand All @@ -98,16 +96,16 @@ func TestRedactEncodedOutputs(t *testing.T) {
require.Equal(t, "{secret}", cl.(*livekit.TrackCompositeEgressRequest).FileOutputs[0].Output.(*livekit.EncodedFileOutput_S3).S3.Secret)

roomComposite := &livekit.RoomCompositeEgressRequest{
FileOutputs: []*livekit.EncodedFileOutput{
file2,
ImageOutputs: []*livekit.ImageOutput{
image,
},
}

cl = proto.Clone(roomComposite)
RedactEncodedOutputs(cl.(EncodedOutput))

require.Equal(t, "{access_key}", cl.(*livekit.RoomCompositeEgressRequest).FileOutputs[0].Output.(*livekit.EncodedFileOutput_AliOSS).AliOSS.AccessKey)
require.Equal(t, "{secret}", cl.(*livekit.RoomCompositeEgressRequest).FileOutputs[0].Output.(*livekit.EncodedFileOutput_AliOSS).AliOSS.Secret)
require.Equal(t, "{access_key}", cl.(*livekit.RoomCompositeEgressRequest).ImageOutputs[0].Output.(*livekit.ImageOutput_AliOSS).AliOSS.AccessKey)
require.Equal(t, "{secret}", cl.(*livekit.RoomCompositeEgressRequest).ImageOutputs[0].Output.(*livekit.ImageOutput_AliOSS).AliOSS.Secret)

participant := &livekit.ParticipantEgressRequest{
SegmentOutputs: []*livekit.SegmentedFileOutput{
Expand Down
9 changes: 7 additions & 2 deletions egress/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ const (
Unknown = "unknown"
)

type EncodedOutput interface {
// Outputs that can be used in egress that are started automatically on room creation
type AutoEncodedOutput interface {
GetFileOutputs() []*livekit.EncodedFileOutput
GetStreamOutputs() []*livekit.StreamOutput
GetSegmentOutputs() []*livekit.SegmentedFileOutput
}

type EncodedOutput interface {
AutoEncodedOutput
GetStreamOutputs() []*livekit.StreamOutput
GetImageOutputs() []*livekit.ImageOutput
}

Expand Down
Loading

0 comments on commit 93a26f4

Please sign in to comment.