diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6f257c8..f910f1a 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.72.0" + ".": "0.73.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 10d9022..9118082 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 124 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-4c243ff089133bd49322d98a6943647589972f71ecadc993fe9e5029972b3995.yml -openapi_spec_hash: a2cb637a19a070d07a1a4343c75444ee -config_hash: fb167e754ebb3a14649463725891c9d0 +configured_endpoints: 125 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-55409ab573762d8bc010fb34c885651ca858a97d4353b4776b7aafeaaa313257.yml +openapi_spec_hash: 0cf678d80f2a2b73fb9ec82d05c8cc0a +config_hash: 06186eb40e0058a2a87ac251fc07415d diff --git a/CHANGELOG.md b/CHANGELOG.md index 014bb49..e185c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.73.0 (2026-07-01) + +Full Changelog: [v0.72.0...v0.73.0](https://github.com/kernel/kernel-go-sdk/compare/v0.72.0...v0.73.0) + +### Features + +* Add hidden audit-logs export endpoint ([2afb724](https://github.com/kernel/kernel-go-sdk/commit/2afb72456a09c06411d78a2fd53a27ac8f1ebdc5)) + ## 0.72.0 (2026-06-26) Full Changelog: [v0.71.0...v0.72.0](https://github.com/kernel/kernel-go-sdk/compare/v0.71.0...v0.72.0) diff --git a/README.md b/README.md index 14f9663..c445429 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Or to pin the version: ```sh -go get -u 'github.com/kernel/kernel-go-sdk@v0.72.0' +go get -u 'github.com/kernel/kernel-go-sdk@v0.73.0' ``` diff --git a/api.md b/api.md index c119a4c..43da313 100644 --- a/api.md +++ b/api.md @@ -431,6 +431,7 @@ Response Types: Methods: - client.AuditLogs.List(ctx context.Context, query kernel.AuditLogListParams) (\*pagination.PageTokenPagination[kernel.AuditLogEntry], error) +- client.AuditLogs.ExportChunk(ctx context.Context, query kernel.AuditLogExportChunkParams) (\*http.Response, error) # APIKeys diff --git a/auditlog.go b/auditlog.go index c4517ce..e487a18 100644 --- a/auditlog.go +++ b/auditlog.go @@ -64,6 +64,17 @@ func (r *AuditLogService) ListAutoPaging(ctx context.Context, query AuditLogList return pagination.NewPageTokenPaginationAutoPager(r.List(ctx, query, opts...)) } +// Download an organization's audit log records for a time range as a file, for +// archival, compliance, or offline analysis. For interactive browsing, use GET +// /audit-logs. +func (r *AuditLogService) ExportChunk(ctx context.Context, query AuditLogExportChunkParams, opts ...option.RequestOption) (res *http.Response, err error) { + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithHeader("Accept", "application/octet-stream")}, opts...) + path := "audit-logs/export/chunk" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + return res, err +} + type AuditLogEntry struct { // Authentication strategy used for the request. AuthStrategy string `json:"auth_strategy" api:"required"` @@ -145,3 +156,48 @@ func (r AuditLogListParams) URLQuery() (v url.Values, err error) { NestedFormat: apiquery.NestedQueryFormatBrackets, }) } + +type AuditLogExportChunkParams struct { + // Upper bound (exclusive) for the audit record timestamp. + End time.Time `query:"end" api:"required" format:"date-time" json:"-"` + // Lower bound (inclusive) for the audit record timestamp. + Start time.Time `query:"start" api:"required" format:"date-time" json:"-"` + // Filter by authentication strategy. + AuthStrategy param.Opt[string] `query:"auth_strategy,omitzero" json:"-"` + // Opaque cursor from X-Next-Cursor for the next chunk of older records. + Cursor param.Opt[string] `query:"cursor,omitzero" json:"-"` + // Filter out results by HTTP method. + ExcludeMethod param.Opt[string] `query:"exclude_method,omitzero" json:"-"` + // Maximum number of records to return in this chunk. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Filter by HTTP method. + Method param.Opt[string] `query:"method,omitzero" json:"-"` + // Free-text search over path, user ID, email, client IP, and status. + Search param.Opt[string] `query:"search,omitzero" json:"-"` + // Filter by service name. + Service param.Opt[string] `query:"service,omitzero" json:"-"` + // Encoding for the returned chunk. + // + // Any of "jsonl", "jsonl.gz". + Format AuditLogExportChunkParamsFormat `query:"format,omitzero" json:"-"` + // Additional user IDs to OR into free-text search. + SearchUserID []string `query:"search_user_id,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [AuditLogExportChunkParams]'s query parameters as +// `url.Values`. +func (r AuditLogExportChunkParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatComma, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Encoding for the returned chunk. +type AuditLogExportChunkParamsFormat string + +const ( + AuditLogExportChunkParamsFormatJSONL AuditLogExportChunkParamsFormat = "jsonl" + AuditLogExportChunkParamsFormatJSONLGz AuditLogExportChunkParamsFormat = "jsonl.gz" +) diff --git a/auditlog_test.go b/auditlog_test.go index fff0ab3..a849751 100644 --- a/auditlog_test.go +++ b/auditlog_test.go @@ -3,8 +3,12 @@ package kernel_test import ( + "bytes" "context" "errors" + "io" + "net/http" + "net/http/httptest" "os" "testing" "time" @@ -47,3 +51,49 @@ func TestAuditLogListWithOptionalParams(t *testing.T) { t.Fatalf("err should be nil: %s", err.Error()) } } + +func TestAuditLogExportChunkWithOptionalParams(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + w.Write([]byte("abc")) + })) + defer server.Close() + baseURL := server.URL + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + resp, err := client.AuditLogs.ExportChunk(context.TODO(), kernel.AuditLogExportChunkParams{ + End: time.Now(), + Start: time.Now(), + AuthStrategy: kernel.String("auth_strategy"), + Cursor: kernel.String("cursor"), + ExcludeMethod: kernel.String("exclude_method"), + Format: kernel.AuditLogExportChunkParamsFormatJSONL, + Limit: kernel.Int(1), + Method: kernel.String("method"), + Search: kernel.String("search"), + SearchUserID: []string{"string"}, + Service: kernel.String("service"), + }) + if err != nil { + var apierr *kernel.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } + defer resp.Body.Close() + + b, err := io.ReadAll(resp.Body) + if err != nil { + var apierr *kernel.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } + if !bytes.Equal(b, []byte("abc")) { + t.Fatalf("return value not %s: %s", "abc", b) + } +} diff --git a/internal/version.go b/internal/version.go index 7b8ed86..2b13c16 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.72.0" // x-release-please-version +const PackageVersion = "0.73.0" // x-release-please-version