Skip to content

Commit d430689

Browse files
committed
fix: logs.go path
Signed-off-by: moabu <47318409+moabu@users.noreply.github.com>
1 parent 833eb44 commit d430689

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

jans/logs.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package jans
33

44
import (
55
"context"
6-
"encoding/json"
76
"fmt"
8-
"net/http"
97
"net/url"
108
"strconv"
119
)
@@ -20,8 +18,9 @@ type LogPagedResult struct {
2018

2119
// GetAuditLogs retrieves audit log entries
2220
func (c *Client) GetAuditLogs(ctx context.Context, pattern string, startIndex, limit int, startDate, endDate string) (*LogPagedResult, error) {
23-
if c.token == nil {
24-
return nil, fmt.Errorf("no token available")
21+
token, err := c.getToken(ctx)
22+
if err != nil {
23+
return nil, fmt.Errorf("failed to get token: %w", err)
2524
}
2625

2726
values := url.Values{}
@@ -41,32 +40,16 @@ func (c *Client) GetAuditLogs(ctx context.Context, pattern string, startIndex, l
4140
values.Set("end_date", endDate)
4241
}
4342

44-
endpoint := "/api/v1/audit"
43+
endpoint := "/jans-config-api/jans-config-api/api/v1/audit"
4544
if len(values) > 0 {
4645
endpoint += "?" + values.Encode()
4746
}
4847

49-
req, err := http.NewRequest(http.MethodGet, c.baseURL+endpoint, nil)
50-
if err != nil {
51-
return nil, err
52-
}
53-
54-
req.Header.Set("Authorization", "Bearer "+c.token.AccessToken)
55-
56-
resp, err := c.httpClient.Do(req)
48+
ret := &LogPagedResult{}
49+
err = c.get(ctx, endpoint, token, ret)
5750
if err != nil {
5851
return nil, err
5952
}
60-
defer resp.Body.Close()
61-
62-
if resp.StatusCode != http.StatusOK {
63-
return nil, createError(resp)
64-
}
65-
66-
var logs LogPagedResult
67-
if err := json.NewDecoder(resp.Body).Decode(&logs); err != nil {
68-
return nil, err
69-
}
7053

71-
return &logs, nil
54+
return ret, nil
7255
}

jans/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func TestClient_GetAuditLogs(t *testing.T) {
4545
for _, tt := range tests {
4646
t.Run(tt.name, func(t *testing.T) {
4747
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
48-
if r.URL.Path != "/api/v1/audit" {
49-
t.Errorf("Expected path '/api/v1/audit', got %s", r.URL.Path)
48+
if r.URL.Path != "/jans-config-api/api/v1/audit" {
49+
t.Errorf("Expected path '/jans-config-api/api/v1/audit', got %s", r.URL.Path)
5050
}
5151

5252
if r.Method != http.MethodGet {

0 commit comments

Comments
 (0)