@@ -3,6 +3,7 @@ package client
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "log/slog"
6
7
"time"
7
8
8
9
"github.com/harness/harness-mcp/client/dto"
@@ -19,37 +20,46 @@ type LogService struct {
19
20
}
20
21
21
22
// DownloadLogs fetches a download URL for pipeline execution logs
22
- func (l * LogService ) DownloadLogs (ctx context.Context , scope dto.Scope , planExecutionID string ) (string , error ) {
23
- // First, get the pipeline execution details to determine the prefix format
24
- pipelineService := & PipelineService {Client : l .PipelineClient } // TODO: needs to be changed for internal case, we should move this above
25
- execution , err := pipelineService .GetExecution (ctx , scope , planExecutionID )
26
- if err != nil {
27
- return "" , fmt .Errorf ("failed to get execution details: %w" , err )
28
- }
29
-
30
- // Build the prefix based on the execution details
31
- var prefix string
32
- if execution .Data .ShouldUseSimplifiedBaseKey {
33
- // Simplified key format
34
- prefix = fmt .Sprintf ("%s/pipeline/%s/%d/-%s" ,
35
- scope .AccountID ,
36
- execution .Data .PipelineIdentifier ,
37
- execution .Data .RunSequence ,
38
- planExecutionID )
23
+ // If logKey is not empty, it will use that log key to fetch logs instead of building one from execution details
24
+ func (l * LogService ) DownloadLogs (ctx context.Context , scope dto.Scope , planExecutionID string , logKey string ) (string , error ) {
25
+ // Use custom log key if provided, otherwise build it from execution details
26
+ var finalLogKey string
27
+ var err error
28
+ if logKey != "" {
29
+ slog .Info ("Using custom log key for log download" , "logKey" , logKey )
30
+ finalLogKey = logKey
39
31
} else {
40
- // Standard key format
41
- prefix = fmt .Sprintf ("accountId:%s/orgId:%s/projectId:%s/pipelineId:%s/runSequence:%d/level0:pipeline" ,
42
- scope .AccountID ,
43
- execution .Data .OrgIdentifier ,
44
- execution .Data .ProjectIdentifier ,
45
- execution .Data .PipelineIdentifier ,
46
- execution .Data .RunSequence )
32
+ slog .Info ("Building log key for log download from execution details" )
33
+ // First, get the pipeline execution details to determine the prefix format
34
+ pipelineService := & PipelineService {Client : l .PipelineClient } // TODO: needs to be changed for internal case, we should move this above
35
+ execution , err := pipelineService .GetExecution (ctx , scope , planExecutionID )
36
+ if err != nil {
37
+ return "" , fmt .Errorf ("failed to get execution details: %w" , err )
38
+ }
39
+
40
+ // Build the log key based on the execution details
41
+ if execution .Data .ShouldUseSimplifiedBaseKey {
42
+ // Simplified key format
43
+ finalLogKey = fmt .Sprintf ("%s/pipeline/%s/%d/-%s" ,
44
+ scope .AccountID ,
45
+ execution .Data .PipelineIdentifier ,
46
+ execution .Data .RunSequence ,
47
+ planExecutionID )
48
+ } else {
49
+ // Standard key format
50
+ finalLogKey = fmt .Sprintf ("accountId:%s/orgId:%s/projectId:%s/pipelineId:%s/runSequence:%d/level0:pipeline" ,
51
+ scope .AccountID ,
52
+ execution .Data .OrgIdentifier ,
53
+ execution .Data .ProjectIdentifier ,
54
+ execution .Data .PipelineIdentifier ,
55
+ execution .Data .RunSequence )
56
+ }
47
57
}
48
58
49
59
// Prepare query parameters
50
60
params := make (map [string ]string )
51
61
params ["accountID" ] = scope .AccountID
52
- params ["prefix" ] = prefix
62
+ params ["prefix" ] = finalLogKey
53
63
54
64
// Initialize the response object
55
65
response := & dto.LogDownloadResponse {}
0 commit comments