[PATCH 1/2] builds: pass Client as argument
Export this patch
It's a bit confusing to define additional Client methods outside
of client.go.
---
builds.go | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/builds.go b/builds.go
index b9ad69078522..fa37b57abff4 100644
--- a/builds.go
@@ -121,12 +121,12 @@ func newBuildsSubmitCommand() *cobra.Command {
if follow {
id := job.Id
- job, err := c.followJob(ctx, job.Id)
+ job, err := followJob(ctx, c, job.Id)
if err != nil {
log.Fatal(err)
}
if job.Status != buildssrht.JobStatusSuccess {
- c.offerSSHConnection(ctx, id)
+ offerSSHConnection(ctx, c, id)
}
}
}
@@ -210,12 +210,12 @@ func newBuildsResubmitCommand() *cobra.Command {
if follow {
id := job.Id
- job, err := c.followJob(ctx, job.Id)
+ job, err := followJob(ctx, c, job.Id)
if err != nil {
log.Fatal(err)
}
if job.Status != buildssrht.JobStatusSuccess {
- c.offerSSHConnection(ctx, id)
+ offerSSHConnection(ctx, c, id)
}
}
}
@@ -305,7 +305,7 @@ func newBuildsShowCommand() *cobra.Command {
)
if follow {
- job, err = c.followJobShow(ctx, id)
+ job, err = followJobShow(ctx, c, id)
if err != nil {
log.Fatal(err)
}
@@ -662,7 +662,7 @@ type buildLog struct {
done bool
}
-func (c *Client) followJob(ctx context.Context, id int32) (*buildssrht.Job, error) {
+func followJob(ctx context.Context, c *Client, id int32) (*buildssrht.Job, error) {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
@@ -841,7 +841,7 @@ func sshConnection(job *buildssrht.Job, user string) error {
return cmd.Run()
}
-func (c *Client) followJobShow(ctx context.Context, id int32) (*buildssrht.Job, error) {
+func followJobShow(ctx context.Context, c *Client, id int32) (*buildssrht.Job, error) {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
@@ -951,7 +951,7 @@ func completeBuildsUserWebhookID(cmd *cobra.Command, args []string, toComplete s
return webhookList, cobra.ShellCompDirectiveNoFileComp
}
-func (c *Client) offerSSHConnection(ctx context.Context, id int32) {
+func offerSSHConnection(ctx context.Context, c *Client, id int32) {
if !termfmt.IsTerminal() {
os.Exit(1)
}
base-commit: 4b38e5d485eb43024fd45fa9fd0bdf6ace2f5cc9
--
2.41.0
[PATCH 2/2] builds: use authenticated client to fetch logs
Export this patch
Upstream has started requiring authentication to fetch builds logs.
Use Client.HTTP instead of http.DefaultClient.
I was about to propose such a patch, since my resubmission command `hut builds resubmit -f XXXX` failed with (job is unlisted)
---
builds.go | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/builds.go b/builds.go
index fa37b57abff4..ffa93172d040 100644
--- a/builds.go
@@ -331,13 +331,13 @@ func newBuildsShowCommand() *cobra.Command {
if job.Status == buildssrht.JobStatusFailed {
if failedTask == -1 {
fmt.Printf("\nSetup log:\n")
- if err := fetchJobLogs(ctx, new(buildLog), job); err != nil {
+ if err := fetchJobLogs(ctx, c, new(buildLog), job); err != nil {
log.Fatalf("failed to fetch job logs: %v", err)
}
} else {
name := job.Tasks[failedTask].Name
fmt.Printf("\n%s log:\n", name)
- if err := fetchTaskLogs(ctx, new(buildLog), job.Tasks[failedTask]); err != nil {
+ if err := fetchTaskLogs(ctx, c, new(buildLog), job.Tasks[failedTask]); err != nil {
log.Fatalf("failed to fetch task logs: %v", err)
}
}
@@ -682,11 +682,11 @@ func followJob(ctx context.Context, c *Client, id int32) (*buildssrht.Job, error
}
}
- if err := fetchJobLogs(ctx, logs[""], job); err != nil {
+ if err := fetchJobLogs(ctx, c, logs[""], job); err != nil {
return nil, fmt.Errorf("failed to fetch job logs: %v", err)
}
for _, task := range job.Tasks {
- if err := fetchTaskLogs(ctx, logs[task.Name], task); err != nil {
+ if err := fetchTaskLogs(ctx, c, logs[task.Name], task); err != nil {
return nil, fmt.Errorf("failed to fetch task %q logs: %v", task.Name, err)
}
}
@@ -705,13 +705,13 @@ func followJob(ctx context.Context, c *Client, id int32) (*buildssrht.Job, error
}
}
-func fetchJobLogs(ctx context.Context, l *buildLog, job *buildssrht.Job) error {
+func fetchJobLogs(ctx context.Context, c *Client, l *buildLog, job *buildssrht.Job) error {
switch job.Status {
case buildssrht.JobStatusPending, buildssrht.JobStatusQueued:
return nil
}
- if err := fetchBuildLogs(ctx, l, job.Log.FullURL); err != nil {
+ if err := fetchBuildLogs(ctx, c, l, job.Log.FullURL); err != nil {
return err
}
@@ -719,13 +719,13 @@ func fetchJobLogs(ctx context.Context, l *buildLog, job *buildssrht.Job) error {
return nil
}
-func fetchTaskLogs(ctx context.Context, l *buildLog, task buildssrht.Task) error {
+func fetchTaskLogs(ctx context.Context, c *Client, l *buildLog, task buildssrht.Task) error {
switch task.Status {
case buildssrht.TaskStatusPending, buildssrht.TaskStatusSkipped:
return nil
}
- if err := fetchBuildLogs(ctx, l, task.Log.FullURL); err != nil {
+ if err := fetchBuildLogs(ctx, c, l, task.Log.FullURL); err != nil {
return err
}
@@ -738,7 +738,7 @@ func fetchTaskLogs(ctx context.Context, l *buildLog, task buildssrht.Task) error
return nil
}
-func fetchBuildLogs(ctx context.Context, l *buildLog, url string) error {
+func fetchBuildLogs(ctx context.Context, c *Client, l *buildLog, url string) error {
if l.done {
return nil
}
@@ -750,7 +750,7 @@ func fetchBuildLogs(ctx context.Context, l *buildLog, url string) error {
req.Header.Set("Range", fmt.Sprintf("bytes=%v-", l.offset))
- resp, err := http.DefaultClient.Do(req)
+ resp, err := c.HTTP.Do(req)
if err != nil {
return fmt.Errorf("HTTP request failed: %v", err)
}
--
2.41.0
Applying this patch, the log is correctly fetched and displayed (so LGTM :).
Both pushed, thanks!