@@ -25,12 +25,12 @@ type containerLogsRequest struct {
2525func containerLogs () * core.Command {
2626 return & core.Command {
2727 Short : `Show container logs` ,
28- Long : `` , // TODO
28+ Long : `Display the logs of a container from the last 2 hours` ,
2929 Namespace : "container" ,
3030 Resource : "container" ,
3131 Verb : "logs" ,
32- // Groups: []string{"workflow "}, // TODO
33- ArgsType : reflect .TypeOf (containerLogsRequest {}),
32+ Groups : []string {"utility " },
33+ ArgsType : reflect .TypeOf (containerLogsRequest {}),
3434 ArgSpecs : core.ArgSpecs {
3535 {
3636 Name : "container-id" ,
@@ -41,7 +41,6 @@ func containerLogs() *core.Command {
4141 scw .RegionFrPar ,
4242 scw .RegionNlAms ,
4343 scw .RegionPlWaw ,
44- scw .Region (core .AllLocalities ), // TODO: test region=all
4544 ),
4645 },
4746 Run : containerLogsRun ,
@@ -118,10 +117,10 @@ func buildLokiQuery(datasourceURL, containerID string) (*http.Request, error) {
118117 `{resource_type="serverless_container", resource_id="%s"}` ,
119118 containerID ,
120119 )
121- start := time .Now ().Add (- 2 * time .Hour ).Format (time .RFC3339 ) //"2026-01-26T16:00:00Z"
122- end := time .Now ().Format (time .RFC3339 ) //"2026-01-26T16:30:00Z"
120+ start := time .Now ().Add (- 2 * time .Hour ).Format (time .RFC3339 ) // TODO: customize timespan ?
121+ end := time .Now ().Format (time .RFC3339 )
123122
124- reqURL := fmt . Sprintf ( "%s /loki/api/v1/query_range", datasourceURL )
123+ reqURL := datasourceURL + " /loki/api/v1/query_range"
125124
126125 formData := url.Values {}
127126 formData .Set ("query" , query )
@@ -165,8 +164,9 @@ func readLokiResponseBody(requestBody io.ReadCloser) ([]LogEntry, error) {
165164 return nil , fmt .Errorf ("Error parsing JSON: %v\n " , err )
166165 }
167166
168- if len (lokiResp .Data .Result ) == 0 { //|| len(lokiResp.Data.Result[0].Values) == 0 {
169- return nil , fmt .Errorf ("No results found\n " )
167+ if len (lokiResp .Data .Result ) == 0 {
168+ // || len(lokiResp.Data.Result[0].Values) == 0 { TODO: rework no-data case
169+ return nil , errors .New ("No results found\n " )
170170 }
171171
172172 var response []LogEntry
@@ -209,45 +209,9 @@ func deleteToken(
209209func getOrCreateToken (
210210 ctx context.Context ,
211211 cockpitAPI * cockpit.RegionalAPI ,
212- region scw.Region , scope cockpit.TokenScope ,
212+ region scw.Region ,
213+ scope cockpit.TokenScope ,
213214) (* cockpit.Token , bool , error ) {
214- // var tokenToUse *cockpit.Token
215-
216- readOnlyTokens , err := cockpitAPI .ListTokens (& cockpit.RegionalAPIListTokensRequest {
217- Region : region ,
218- // ProjectID: "",
219- TokenScopes : []cockpit.TokenScope {scope },
220- }, scw .WithAllPages (), scw .WithContext (ctx ))
221- if err != nil {
222- return nil , false , err
223- }
224-
225- for _ , roToken := range readOnlyTokens .Tokens {
226- token , err := cockpitAPI .GetToken (& cockpit.RegionalAPIGetTokenRequest {
227- Region : region ,
228- TokenID : roToken .ID ,
229- }, scw .WithContext (ctx ))
230- if err != nil {
231- return nil , false , err
232- }
233-
234- if token .SecretKey != nil {
235- return token , false , nil
236- }
237- }
238-
239- // fullAccessTokens, err := cockpitAPI.ListTokens(&cockpit.RegionalAPIListTokensRequest{
240- // Region: region,
241- // // ProjectID: "",
242- // TokenScopes: []cockpit.TokenScope{cockpit.TokenScopeFullAccessLogsRules},
243- // }, scw.WithAllPages(), scw.WithContext(ctx))
244- // if err != nil {
245- // return nil, err
246- // }
247- //
248- // if len(fullAccessTokens.Tokens) > 0 {
249- // tokenToUse = fullAccessTokens.Tokens[0]
250- // } else {
251215 token , err := cockpitAPI .CreateToken (& cockpit.RegionalAPICreateTokenRequest {
252216 Region : region ,
253217 // ProjectID: "",
0 commit comments