Skip to content

Commit 8f023dd

Browse files
authored
cloud-agents context-aware client (#801)
1 parent 5ebb052 commit 8f023dd

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pkg/cloudagents/auth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cloudagents
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"io"
2021
"net/http"
@@ -23,9 +24,9 @@ import (
2324
lksdk "github.com/livekit/server-sdk-go/v2"
2425
)
2526

26-
// newRequest creates a new HTTP request with the auth and version headers.
27-
func (c *Client) newRequest(method, url string, body io.Reader) (*http.Request, error) {
28-
req, err := http.NewRequest(method, url, body)
27+
// newRequestWithContext creates a new HTTP request with the auth and version headers.
28+
func (c *Client) newRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) {
29+
req, err := http.NewRequestWithContext(ctx, method, url, body)
2930
if err != nil {
3031
return nil, err
3132
}

pkg/cloudagents/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *Client) build(ctx context.Context, id string, writer io.Writer) error {
3434
params := url.Values{}
3535
params.Add("agent_id", id)
3636
fullUrl := fmt.Sprintf("%s/build?%s", c.agentsURL, params.Encode())
37-
req, err := c.newRequest("POST", fullUrl, nil)
37+
req, err := c.newRequestWithContext(ctx, "POST", fullUrl, nil)
3838
if err != nil {
3939
return err
4040
}

pkg/cloudagents/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (c *Client) StreamLogs(ctx context.Context, logType, agentID string, writer
4040
params.Add("agent_id", agentID)
4141
params.Add("log_type", logType)
4242
fullUrl := fmt.Sprintf("%s/logs?%s", c.getAgentsURL(serverRegion), params.Encode())
43-
req, err := c.newRequest("GET", fullUrl, nil)
43+
req, err := c.newRequestWithContext(ctx, "GET", fullUrl, nil)
4444
if err != nil {
4545
return err
4646
}

0 commit comments

Comments
 (0)