Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-53433] Add RecordingID to RecorderConfig #38

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ runuser -l $RECORDER_USER -c \
AUTH_TOKEN=$AUTH_TOKEN \
CALL_ID=$CALL_ID \
THREAD_ID=$THREAD_ID \
RECORDING_ID=$RECORDING_ID \
WIDTH=${WIDTH:-0} \
HEIGHT=${HEIGHT:-0} \
VIDEO_RATE=${VIDEO_RATE:-0} \
Expand Down
8 changes: 4 additions & 4 deletions build/pkgs_list
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ca-certificates=20230311
chromium=115.0.5790.170-1
chromium-driver=115.0.5790.170-1
chromium-sandbox=115.0.5790.170-1
ffmpeg=7:6.0-5
chromium=116.0.5845.110-2
chromium-driver=116.0.5845.110-2
chromium-sandbox=116.0.5845.110-2
ffmpeg=7:6.0-6
fonts-recommended=1
pulseaudio=16.1+dfsg1-2+b1
wget=1.21.3-1+b2
Expand Down
19 changes: 15 additions & 4 deletions cmd/recorder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ const (

type RecorderConfig struct {
// input config
SiteURL string
CallID string
ThreadID string
AuthToken string
SiteURL string
CallID string
ThreadID string
RecordingID string
AuthToken string

// output config
Width int
Expand Down Expand Up @@ -106,6 +107,12 @@ func (cfg RecorderConfig) IsValid() error {
return fmt.Errorf("ThreadID parsing failed")
}

if cfg.RecordingID == "" {
return fmt.Errorf("RecordingID cannot be empty")
} else if !idRE.MatchString(cfg.RecordingID) {
return fmt.Errorf("RecordingID parsing failed")
}

if cfg.AuthToken == "" {
return fmt.Errorf("AuthToken cannot be empty")
} else if !idRE.MatchString(cfg.AuthToken) {
Expand Down Expand Up @@ -172,6 +179,7 @@ func (cfg RecorderConfig) ToEnv() []string {
fmt.Sprintf("SITE_URL=%s", cfg.SiteURL),
fmt.Sprintf("CALL_ID=%s", cfg.CallID),
fmt.Sprintf("THREAD_ID=%s", cfg.ThreadID),
fmt.Sprintf("RECORDING_ID=%s", cfg.RecordingID),
fmt.Sprintf("AUTH_TOKEN=%s", cfg.AuthToken),
fmt.Sprintf("WIDTH=%d", cfg.Width),
fmt.Sprintf("HEIGHT=%d", cfg.Height),
Expand All @@ -188,6 +196,7 @@ func (cfg RecorderConfig) ToMap() map[string]any {
"site_url": cfg.SiteURL,
"call_id": cfg.CallID,
"thread_id": cfg.ThreadID,
"recording_id": cfg.RecordingID,
"auth_token": cfg.AuthToken,
"width": cfg.Width,
"height": cfg.Height,
Expand All @@ -203,6 +212,7 @@ func (cfg *RecorderConfig) FromMap(m map[string]any) *RecorderConfig {
cfg.SiteURL, _ = m["site_url"].(string)
cfg.CallID, _ = m["call_id"].(string)
cfg.ThreadID, _ = m["thread_id"].(string)
cfg.RecordingID, _ = m["recording_id"].(string)
cfg.AuthToken, _ = m["auth_token"].(string)
if width, ok := m["width"].(float64); ok {
cfg.Width = int(width)
Expand Down Expand Up @@ -247,6 +257,7 @@ func LoadFromEnv() (RecorderConfig, error) {
cfg.SiteURL = strings.TrimSuffix(os.Getenv("SITE_URL"), "/")
cfg.CallID = os.Getenv("CALL_ID")
cfg.ThreadID = os.Getenv("THREAD_ID")
cfg.RecordingID = os.Getenv("RECORDING_ID")
cfg.AuthToken = os.Getenv("AUTH_TOKEN")

if val := os.Getenv("WIDTH"); val != "" {
Expand Down
113 changes: 69 additions & 44 deletions cmd/recorder/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,88 @@ func TestConfigIsValid(t *testing.T) {
},
expectedError: "ThreadID cannot be empty",
},
{
name: "missing RecordingID",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
},
expectedError: "RecordingID cannot be empty",
},
{
name: "missing AuthToken",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
},
expectedError: "AuthToken cannot be empty",
},
{
name: "invalid Width",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
},
expectedError: "Width value is not valid",
},
{
name: "invalid Height",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
},
expectedError: "Height value is not valid",
},
{
name: "invalid VideoRate",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
},
expectedError: "VideoRate value is not valid",
},
{
name: "invalid AudioRate",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
},
expectedError: "AudioRate value is not valid",
},
{
name: "invalid FrameRate",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
AudioRate: 64,
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
AudioRate: 64,
},
expectedError: "FrameRate value is not valid",
},
Expand All @@ -116,6 +132,7 @@ func TestConfigIsValid(t *testing.T) {
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
Expand All @@ -129,15 +146,16 @@ func TestConfigIsValid(t *testing.T) {
{
name: "invalid format",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
AudioRate: 64,
FrameRate: 30,
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
VideoRate: 1000,
AudioRate: 64,
FrameRate: 30,
},
expectedError: "OutputFormat value is not valid",
},
Expand All @@ -147,6 +165,7 @@ func TestConfigIsValid(t *testing.T) {
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Height: 720,
Expand Down Expand Up @@ -250,6 +269,8 @@ func TestLoadFromEnv(t *testing.T) {
defer os.Unsetenv("CALL_ID")
os.Setenv("THREAD_ID", "udzdsg7dwidbzcidx5khrf8nee")
defer os.Unsetenv("THREAD_ID")
os.Setenv("RECORDING_ID", "67t5u6cmtfbb7jug739d43xa9e")
defer os.Unsetenv("RECORDING_ID")
os.Setenv("AUTH_TOKEN", "qj75unbsef83ik9p7ueypb6iyw")
defer os.Unsetenv("AUTH_TOKEN")
os.Setenv("WIDTH", "1920")
Expand All @@ -271,6 +292,7 @@ func TestLoadFromEnv(t *testing.T) {
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1920,
Height: 1080,
Expand All @@ -286,13 +308,15 @@ func TestRecorderConfigToEnv(t *testing.T) {
var cfg RecorderConfig
cfg.SiteURL = "http://localhost:8065"
cfg.CallID = "8w8jorhr7j83uqr6y1st894hqe"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.ThreadID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.RecordingID = "67t5u6cmtfbb7jug739d43xa9e"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.SetDefaults()
require.Equal(t, []string{
"SITE_URL=http://localhost:8065",
"CALL_ID=8w8jorhr7j83uqr6y1st894hqe",
"THREAD_ID=udzdsg7dwidbzcidx5khrf8nee",
"RECORDING_ID=67t5u6cmtfbb7jug739d43xa9e",
"AUTH_TOKEN=qj75unbsef83ik9p7ueypb6iyw",
"WIDTH=1920",
"HEIGHT=1080",
Expand All @@ -308,8 +332,9 @@ func TestRecorderConfigMap(t *testing.T) {
var cfg RecorderConfig
cfg.SiteURL = "http://localhost:8065"
cfg.CallID = "8w8jorhr7j83uqr6y1st894hqe"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.ThreadID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.RecordingID = "67t5u6cmtfbb7jug739d43xa9e"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.SetDefaults()

t.Run("default config", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func (rec *Recorder) Start() error {
return fmt.Errorf("failed to marshal data: %s", err)
}

recURL := fmt.Sprintf("%s/plugins/%s/standalone/recording.html?call_id=%s#%s",
rec.cfg.SiteURL, pluginID, rec.cfg.CallID, base64.URLEncoding.EncodeToString(data))
recURL := fmt.Sprintf("%s/plugins/%s/standalone/recording.html?call_id=%s&job_id=%s#%s",
rec.cfg.SiteURL, pluginID, rec.cfg.CallID, rec.cfg.RecordingID, base64.URLEncoding.EncodeToString(data))

go func() {
if err := rec.runBrowser(recURL); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/recorder/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func TestNewRecorder(t *testing.T) {

t.Run("valid config", func(t *testing.T) {
cfg := config.RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
}
cfg.SetDefaults()
rec, err := NewRecorder(cfg)
Expand Down
9 changes: 5 additions & 4 deletions cmd/recorder/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func TestUploadRecording(t *testing.T) {
defer ts.Close()

cfg := config.RecorderConfig{
SiteURL: ts.URL,
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
SiteURL: ts.URL,
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
}
cfg.SetDefaults()
rec, err := NewRecorder(cfg)
Expand Down