diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b56d745..07c725d 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.150.0" + ".": "0.151.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index a4bdf76..ffd2a69 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 189 +configured_endpoints: 206 diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c2743..9d1c343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.151.0](https://github.com/kernel/kernel-go-sdk/compare/v0.150.0...v0.151.0) (2026-11-19) + + +### Features + +* Add service account, workload identity issuer, federation rule and authentication event resources. They require a signed-in session; API keys get 403 ([10f570a](https://github.com/kernel/kernel-go-sdk/commit/10f570a40039088d872b17ffb1a59f7e341931db)) +* Add `service_account_id`, `principal_type`, `created_by` and `project_id` filters and the `expired` status to API key listing. `status=active`, the default, no longer returns expired keys ([10f570a](https://github.com/kernel/kernel-go-sdk/commit/10f570a40039088d872b17ffb1a59f7e341931db)) +* Change `APIKeyPrincipal.Type`, which 0.150.0 introduced as a `string`, to the new `APIKeyPrincipalType` ([10f570a](https://github.com/kernel/kernel-go-sdk/commit/10f570a40039088d872b17ffb1a59f7e341931db)) + ## [0.150.0](https://github.com/kernel/kernel-go-sdk/compare/v0.149.0...v0.150.0) (2026-11-19) diff --git a/README.md b/README.md index 1e431ca..24e21f0 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.150.0' +go get -u 'github.com/kernel/kernel-go-sdk@v0.151.0' ``` diff --git a/api.md b/api.md index 214e2b5..03614ad 100644 --- a/api.md +++ b/api.md @@ -481,6 +481,7 @@ Methods: Response Types: - kernel.AuthContext +- kernel.AuthContextWorkloadIdentity Methods: @@ -869,6 +870,7 @@ Methods: Response Types: - kernel.APIKey +- kernel.APIKeyPrincipal - kernel.CreatedAPIKey Methods: @@ -880,6 +882,84 @@ Methods: - client.APIKeys.Delete(ctx context.Context, id string) error - client.APIKeys.Rotate(ctx context.Context, id string, body kernel.APIKeyRotateParams) (\*kernel.CreatedAPIKey, error) +# ServiceAccounts + +Params Types: + +- kernel.ServiceAccountConfigParam + +Response Types: + +- kernel.ServiceAccount + +Methods: + +- client.ServiceAccounts.New(ctx context.Context, body kernel.ServiceAccountNewParams) (\*kernel.ServiceAccount, error) +- client.ServiceAccounts.Get(ctx context.Context, id string) (\*kernel.ServiceAccount, error) +- client.ServiceAccounts.Update(ctx context.Context, id string, body kernel.ServiceAccountUpdateParams) (\*kernel.ServiceAccount, error) +- client.ServiceAccounts.List(ctx context.Context, query kernel.ServiceAccountListParams) (\*pagination.OffsetPagination[kernel.ServiceAccount], error) +- client.ServiceAccounts.Delete(ctx context.Context, id string) error + +# WorkloadIdentityIssuers + +Params Types: + +- kernel.WorkloadIdentityIssuerConfigParam +- kernel.WorkloadIdentityKeySourceParam +- kernel.WorkloadIdentityPresetType +- kernel.WorkloadIdentityTokenValidationParam + +Response Types: + +- kernel.WorkloadIdentityIssuer +- kernel.WorkloadIdentityIssuerKeyCheck +- kernel.WorkloadIdentityKeySource +- kernel.WorkloadIdentityPresetType +- kernel.WorkloadIdentityTokenValidation + +Methods: + +- client.WorkloadIdentityIssuers.New(ctx context.Context, body kernel.WorkloadIdentityIssuerNewParams) (\*kernel.WorkloadIdentityIssuer, error) +- client.WorkloadIdentityIssuers.Get(ctx context.Context, id string) (\*kernel.WorkloadIdentityIssuer, error) +- client.WorkloadIdentityIssuers.Update(ctx context.Context, id string, body kernel.WorkloadIdentityIssuerUpdateParams) (\*kernel.WorkloadIdentityIssuer, error) +- client.WorkloadIdentityIssuers.List(ctx context.Context, query kernel.WorkloadIdentityIssuerListParams) (\*pagination.OffsetPagination[kernel.WorkloadIdentityIssuer], error) +- client.WorkloadIdentityIssuers.Delete(ctx context.Context, id string) error +- client.WorkloadIdentityIssuers.Verify(ctx context.Context, id string) (\*kernel.WorkloadIdentityIssuerKeyCheck, error) + +# WorkloadIdentityFederationRules + +Params Types: + +- kernel.WorkloadIdentityAuthorizationParam +- kernel.WorkloadIdentityFederationRuleConfigParam +- kernel.WorkloadIdentityMatchParam +- kernel.WorkloadIdentityTargetParam + +Response Types: + +- kernel.WorkloadIdentityAuthorization +- kernel.WorkloadIdentityFederationRule +- kernel.WorkloadIdentityMatch +- kernel.WorkloadIdentityTarget + +Methods: + +- client.WorkloadIdentityFederationRules.New(ctx context.Context, body kernel.WorkloadIdentityFederationRuleNewParams) (\*kernel.WorkloadIdentityFederationRule, error) +- client.WorkloadIdentityFederationRules.Get(ctx context.Context, id string) (\*kernel.WorkloadIdentityFederationRule, error) +- client.WorkloadIdentityFederationRules.Update(ctx context.Context, id string, body kernel.WorkloadIdentityFederationRuleUpdateParams) (\*kernel.WorkloadIdentityFederationRule, error) +- client.WorkloadIdentityFederationRules.List(ctx context.Context, query kernel.WorkloadIdentityFederationRuleListParams) (\*pagination.OffsetPagination[kernel.WorkloadIdentityFederationRule], error) +- client.WorkloadIdentityFederationRules.Delete(ctx context.Context, id string) error + +# WorkloadIdentityAuthenticationEvents + +Response Types: + +- kernel.WorkloadIdentityAuthenticationEvent + +Methods: + +- client.WorkloadIdentityAuthenticationEvents.List(ctx context.Context, query kernel.WorkloadIdentityAuthenticationEventListParams) (\*pagination.OffsetPagination[kernel.WorkloadIdentityAuthenticationEvent], error) + # CredentialProviders Params Types: diff --git a/apikey.go b/apikey.go index 15f93ad..611c4ee 100644 --- a/apikey.go +++ b/apikey.go @@ -307,7 +307,7 @@ func (r *APIKeyPolicyStatementCondition) UnmarshalJSON(data []byte) error { type APIKeyPrincipal struct { ID string `json:"id" api:"required"` // Any of "user", "service_account". - Type string `json:"type" api:"required"` + Type APIKeyPrincipalType `json:"type" api:"required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { ID respjson.Field @@ -323,6 +323,13 @@ func (r *APIKeyPrincipal) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } +type APIKeyPrincipalType string + +const ( + APIKeyPrincipalTypeUser APIKeyPrincipalType = "user" + APIKeyPrincipalTypeServiceAccount APIKeyPrincipalType = "service_account" +) + // API key returned immediately after creation. Includes the plaintext key once. type CreatedAPIKey struct { // Plaintext API key. Only returned once when the key is created. @@ -567,6 +574,9 @@ func init() { } type APIKeyListParams struct { + // Return only keys created by this user ID. This is the same person the key's + // created_by field describes. + CreatedBy param.Opt[string] `query:"created_by,omitzero" json:"-"` // Deprecated: use status=all instead. When true, include deleted (soft-deleted) // API keys in the results for audit purposes. IncludeDeleted param.Opt[bool] `query:"include_deleted,omitzero" json:"-"` @@ -579,9 +589,18 @@ type APIKeyListParams struct { Name param.Opt[string] `query:"name,omitzero" json:"-"` // Number of results to skip Offset param.Opt[int64] `query:"offset,omitzero" json:"-"` + // Return only keys scoped to this project ID. The value "org" returns keys that + // are not scoped to a project. + ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"` // Case-insensitive substring match against API key name, creator, and project. API // key identifiers and masked keys match by exact value or prefix. Query param.Opt[string] `query:"query,omitzero" json:"-"` + // Return only keys that belong to this service account. + ServiceAccountID param.Opt[string] `query:"service_account_id,omitzero" json:"-"` + // Return only keys that act as a user, or only keys that act as a service account. + // + // Any of "user", "service_account". + PrincipalType APIKeyListParamsPrincipalType `query:"principal_type,omitzero" json:"-"` // Field to sort API keys by. Keys with no expiry or no recorded use sort last for // expires_at and last_used_at in either direction. // @@ -591,11 +610,11 @@ type APIKeyListParams struct { // // Any of "asc", "desc". SortDirection APIKeyListParamsSortDirection `query:"sort_direction,omitzero" json:"-"` - // Filter API keys by status. "active" returns keys that are not deleted (default; - // expired-but-not-deleted keys are still included), "deleted" returns only - // soft-deleted keys, "all" returns both. + // Filter API keys by status. "active" returns keys that are neither deleted nor + // expired (default), "expired" returns keys that are not deleted and whose expiry + // has passed, "deleted" returns only soft-deleted keys, "all" returns every key. // - // Any of "active", "deleted", "all". + // Any of "active", "expired", "deleted", "all". Status APIKeyListParamsStatus `query:"status,omitzero" json:"-"` paramObj } @@ -608,6 +627,14 @@ func (r APIKeyListParams) URLQuery() (v url.Values, err error) { }) } +// Return only keys that act as a user, or only keys that act as a service account. +type APIKeyListParamsPrincipalType string + +const ( + APIKeyListParamsPrincipalTypeUser APIKeyListParamsPrincipalType = "user" + APIKeyListParamsPrincipalTypeServiceAccount APIKeyListParamsPrincipalType = "service_account" +) + // Field to sort API keys by. Keys with no expiry or no recorded use sort last for // expires_at and last_used_at in either direction. type APIKeyListParamsSortBy string @@ -627,13 +654,14 @@ const ( APIKeyListParamsSortDirectionDesc APIKeyListParamsSortDirection = "desc" ) -// Filter API keys by status. "active" returns keys that are not deleted (default; -// expired-but-not-deleted keys are still included), "deleted" returns only -// soft-deleted keys, "all" returns both. +// Filter API keys by status. "active" returns keys that are neither deleted nor +// expired (default), "expired" returns keys that are not deleted and whose expiry +// has passed, "deleted" returns only soft-deleted keys, "all" returns every key. type APIKeyListParamsStatus string const ( APIKeyListParamsStatusActive APIKeyListParamsStatus = "active" + APIKeyListParamsStatusExpired APIKeyListParamsStatus = "expired" APIKeyListParamsStatusDeleted APIKeyListParamsStatus = "deleted" APIKeyListParamsStatusAll APIKeyListParamsStatus = "all" ) diff --git a/apikey_test.go b/apikey_test.go index 4376cff..06de416 100644 --- a/apikey_test.go +++ b/apikey_test.go @@ -137,14 +137,18 @@ func TestAPIKeyListWithOptionalParams(t *testing.T) { option.WithAPIKey("My API Key"), ) _, err := client.APIKeys.List(context.TODO(), kernel.APIKeyListParams{ - IncludeDeleted: kernel.Bool(true), - Limit: kernel.Int(100), - Name: kernel.String("name"), - Offset: kernel.Int(0), - Query: kernel.String("query"), - SortBy: kernel.APIKeyListParamsSortByCreatedAt, - SortDirection: kernel.APIKeyListParamsSortDirectionAsc, - Status: kernel.APIKeyListParamsStatusActive, + CreatedBy: kernel.String("created_by"), + IncludeDeleted: kernel.Bool(true), + Limit: kernel.Int(100), + Name: kernel.String("name"), + Offset: kernel.Int(0), + PrincipalType: kernel.APIKeyListParamsPrincipalTypeUser, + ProjectID: kernel.String("project_id"), + Query: kernel.String("query"), + ServiceAccountID: kernel.String("service_account_id"), + SortBy: kernel.APIKeyListParamsSortByCreatedAt, + SortDirection: kernel.APIKeyListParamsSortDirectionAsc, + Status: kernel.APIKeyListParamsStatusActive, }) if err != nil { var apierr *kernel.Error diff --git a/client.go b/client.go index 1837381..b34d731 100644 --- a/client.go +++ b/client.go @@ -59,7 +59,11 @@ type Client struct { // Read audit log records for the authenticated organization. AuditLogs AuditLogService // Create and manage API keys for organization and project-scoped access. - APIKeys APIKeyService + APIKeys APIKeyService + ServiceAccounts ServiceAccountService + WorkloadIdentityIssuers WorkloadIdentityIssuerService + WorkloadIdentityFederationRules WorkloadIdentityFederationRuleService + WorkloadIdentityAuthenticationEvents WorkloadIdentityAuthenticationEventService // Configure external credential providers like 1Password. CredentialProviders CredentialProviderService // Search the web and retrieve content for selected results. @@ -124,6 +128,10 @@ func NewClient(opts ...option.RequestOption) (r Client) { r.Organization = NewOrganizationService(opts...) r.AuditLogs = NewAuditLogService(opts...) r.APIKeys = NewAPIKeyService(opts...) + r.ServiceAccounts = NewServiceAccountService(opts...) + r.WorkloadIdentityIssuers = NewWorkloadIdentityIssuerService(opts...) + r.WorkloadIdentityFederationRules = NewWorkloadIdentityFederationRuleService(opts...) + r.WorkloadIdentityAuthenticationEvents = NewWorkloadIdentityAuthenticationEventService(opts...) r.CredentialProviders = NewCredentialProviderService(opts...) r.Search = NewSearchService(opts...) diff --git a/internal/version.go b/internal/version.go index ba65c0f..3aeddb5 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.150.0" // x-release-please-version +const PackageVersion = "0.151.0" // x-release-please-version diff --git a/serviceaccount.go b/serviceaccount.go new file mode 100644 index 0000000..76a2193 --- /dev/null +++ b/serviceaccount.go @@ -0,0 +1,218 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "slices" + "time" + + "github.com/kernel/kernel-go-sdk/internal/apijson" + "github.com/kernel/kernel-go-sdk/internal/apiquery" + shimjson "github.com/kernel/kernel-go-sdk/internal/encoding/json" + "github.com/kernel/kernel-go-sdk/internal/requestconfig" + "github.com/kernel/kernel-go-sdk/option" + "github.com/kernel/kernel-go-sdk/packages/pagination" + "github.com/kernel/kernel-go-sdk/packages/param" + "github.com/kernel/kernel-go-sdk/packages/respjson" +) + +// ServiceAccountService contains methods and other services that help with +// interacting with the kernel API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewServiceAccountService] method instead. +type ServiceAccountService struct { + Options []option.RequestOption +} + +// NewServiceAccountService generates a new service that applies the given options +// to each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewServiceAccountService(opts ...option.RequestOption) (r ServiceAccountService) { + r = ServiceAccountService{} + r.Options = opts + return +} + +// Organization credential administrators only. No external namespace-ownership or +// staff approval is required. New trust resources default disabled. +func (r *ServiceAccountService) New(ctx context.Context, body ServiceAccountNewParams, opts ...option.RequestOption) (res *ServiceAccount, err error) { + opts = slices.Concat(r.Options, opts) + path := "org/service_accounts" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *ServiceAccountService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *ServiceAccount, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/service_accounts/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return res, err +} + +// Update a service account +func (r *ServiceAccountService) Update(ctx context.Context, id string, body ServiceAccountUpdateParams, opts ...option.RequestOption) (res *ServiceAccount, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/service_accounts/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *ServiceAccountService) List(ctx context.Context, query ServiceAccountListParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[ServiceAccount], err error) { + var raw *http.Response + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "org/service_accounts" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *ServiceAccountService) ListAutoPaging(ctx context.Context, query ServiceAccountListParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[ServiceAccount] { + return pagination.NewOffsetPaginationAutoPager(r.List(ctx, query, opts...)) +} + +// Retains history and invalidates associated authority within the documented +// status bound. Does not delete created browser resources. +func (r *ServiceAccountService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error) { + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...) + if id == "" { + err = errors.New("missing required id parameter") + return err + } + path := fmt.Sprintf("org/service_accounts/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...) + return err +} + +type ServiceAccount struct { + ID string `json:"id" api:"required"` + ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"` + CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` + CreatedByUserID string `json:"created_by_user_id" api:"required"` + Description string `json:"description" api:"required"` + // When one of the account's API keys last authenticated or one of its rules last + // issued a token. Recorded at most once every 15 minutes, so it can lag. Null if + // the account has never been used. + LastUsedAt time.Time `json:"last_used_at" api:"required" format:"date-time"` + Name string `json:"name" api:"required"` + OrgID string `json:"org_id" api:"required"` + // Authority revision. Cosmetic updates do not widen permissions. + SecurityVersion int64 `json:"security_version" api:"required"` + UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + ArchivedAt respjson.Field + CreatedAt respjson.Field + CreatedByUserID respjson.Field + Description respjson.Field + LastUsedAt respjson.Field + Name respjson.Field + OrgID respjson.Field + SecurityVersion respjson.Field + UpdatedAt respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ServiceAccount) RawJSON() string { return r.JSON.raw } +func (r *ServiceAccount) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The property Name is required. +type ServiceAccountConfigParam struct { + Name string `json:"name" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + paramObj +} + +func (r ServiceAccountConfigParam) MarshalJSON() (data []byte, err error) { + type shadow ServiceAccountConfigParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *ServiceAccountConfigParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ServiceAccountNewParams struct { + ServiceAccountConfig ServiceAccountConfigParam + paramObj +} + +func (r ServiceAccountNewParams) MarshalJSON() (data []byte, err error) { + return shimjson.Marshal(r.ServiceAccountConfig) +} +func (r *ServiceAccountNewParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ServiceAccountUpdateParams struct { + ExpectedVersion int64 `json:"expected_version" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + Name param.Opt[string] `json:"name,omitzero"` + paramObj +} + +func (r ServiceAccountUpdateParams) MarshalJSON() (data []byte, err error) { + type shadow ServiceAccountUpdateParams + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *ServiceAccountUpdateParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ServiceAccountListParams struct { + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + Offset param.Opt[int64] `query:"offset,omitzero" json:"-"` + // Case-insensitive substring match against name or description; exact ID match. + Query param.Opt[string] `query:"query,omitzero" json:"-"` + // Any of "active", "archived", "all". + Status ServiceAccountListParamsStatus `query:"status,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [ServiceAccountListParams]'s query parameters as +// `url.Values`. +func (r ServiceAccountListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatComma, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +type ServiceAccountListParamsStatus string + +const ( + ServiceAccountListParamsStatusActive ServiceAccountListParamsStatus = "active" + ServiceAccountListParamsStatusArchived ServiceAccountListParamsStatus = "archived" + ServiceAccountListParamsStatusAll ServiceAccountListParamsStatus = "all" +) diff --git a/serviceaccount_test.go b/serviceaccount_test.go new file mode 100644 index 0000000..2d1bb92 --- /dev/null +++ b/serviceaccount_test.go @@ -0,0 +1,147 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/kernel/kernel-go-sdk" + "github.com/kernel/kernel-go-sdk/internal/testutil" + "github.com/kernel/kernel-go-sdk/option" +) + +func TestServiceAccountNewWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.ServiceAccounts.New(context.TODO(), kernel.ServiceAccountNewParams{ + ServiceAccountConfig: kernel.ServiceAccountConfigParam{ + Name: "name", + Description: kernel.String("description"), + }, + }) + 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()) + } +} + +func TestServiceAccountGet(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.ServiceAccounts.Get(context.TODO(), "id") + 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()) + } +} + +func TestServiceAccountUpdateWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.ServiceAccounts.Update( + context.TODO(), + "id", + kernel.ServiceAccountUpdateParams{ + ExpectedVersion: 1, + Description: kernel.String("description"), + Name: kernel.String("name"), + }, + ) + 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()) + } +} + +func TestServiceAccountListWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.ServiceAccounts.List(context.TODO(), kernel.ServiceAccountListParams{ + Limit: kernel.Int(1), + Offset: kernel.Int(0), + Query: kernel.String("query"), + Status: kernel.ServiceAccountListParamsStatusActive, + }) + 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()) + } +} + +func TestServiceAccountDelete(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.ServiceAccounts.Delete(context.TODO(), "id") + 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()) + } +} diff --git a/workloadidentityauthenticationevent.go b/workloadidentityauthenticationevent.go new file mode 100644 index 0000000..e3f8b87 --- /dev/null +++ b/workloadidentityauthenticationevent.go @@ -0,0 +1,136 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel + +import ( + "context" + "net/http" + "net/url" + "slices" + "time" + + "github.com/kernel/kernel-go-sdk/internal/apijson" + "github.com/kernel/kernel-go-sdk/internal/apiquery" + "github.com/kernel/kernel-go-sdk/internal/requestconfig" + "github.com/kernel/kernel-go-sdk/option" + "github.com/kernel/kernel-go-sdk/packages/pagination" + "github.com/kernel/kernel-go-sdk/packages/param" + "github.com/kernel/kernel-go-sdk/packages/respjson" +) + +// WorkloadIdentityAuthenticationEventService contains methods and other services +// that help with interacting with the kernel API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewWorkloadIdentityAuthenticationEventService] method instead. +type WorkloadIdentityAuthenticationEventService struct { + Options []option.RequestOption +} + +// NewWorkloadIdentityAuthenticationEventService generates a new service that +// applies the given options to each request. These options are applied after the +// parent client's options (if there is one), and before any request-specific +// options. +func NewWorkloadIdentityAuthenticationEventService(opts ...option.RequestOption) (r WorkloadIdentityAuthenticationEventService) { + r = WorkloadIdentityAuthenticationEventService{} + r.Options = opts + return +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityAuthenticationEventService) List(ctx context.Context, query WorkloadIdentityAuthenticationEventListParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[WorkloadIdentityAuthenticationEvent], err error) { + var raw *http.Response + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "org/workload_identity_authentication_events" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityAuthenticationEventService) ListAutoPaging(ctx context.Context, query WorkloadIdentityAuthenticationEventListParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[WorkloadIdentityAuthenticationEvent] { + return pagination.NewOffsetPaginationAutoPager(r.List(ctx, query, opts...)) +} + +type WorkloadIdentityAuthenticationEvent struct { + ID string `json:"id" api:"required"` + CorrelationID string `json:"correlation_id" api:"required"` + CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` + CredentialID string `json:"credential_id" api:"required"` + FederationRuleID string `json:"federation_rule_id" api:"required"` + IssuerID string `json:"issuer_id" api:"required"` + OrgID string `json:"org_id" api:"required"` + // Any of "success", "failure". + Outcome WorkloadIdentityAuthenticationEventOutcome `json:"outcome" api:"required"` + ProjectID string `json:"project_id" api:"required"` + Reason string `json:"reason" api:"required"` + ServiceAccountID string `json:"service_account_id" api:"required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + CorrelationID respjson.Field + CreatedAt respjson.Field + CredentialID respjson.Field + FederationRuleID respjson.Field + IssuerID respjson.Field + OrgID respjson.Field + Outcome respjson.Field + ProjectID respjson.Field + Reason respjson.Field + ServiceAccountID respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityAuthenticationEvent) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityAuthenticationEvent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityAuthenticationEventOutcome string + +const ( + WorkloadIdentityAuthenticationEventOutcomeSuccess WorkloadIdentityAuthenticationEventOutcome = "success" + WorkloadIdentityAuthenticationEventOutcomeFailure WorkloadIdentityAuthenticationEventOutcome = "failure" +) + +type WorkloadIdentityAuthenticationEventListParams struct { + EndTime param.Opt[time.Time] `query:"end_time,omitzero" format:"date-time" json:"-"` + FederationRuleID param.Opt[string] `query:"federation_rule_id,omitzero" json:"-"` + IssuerID param.Opt[string] `query:"issuer_id,omitzero" json:"-"` + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + Offset param.Opt[int64] `query:"offset,omitzero" json:"-"` + ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"` + ServiceAccountID param.Opt[string] `query:"service_account_id,omitzero" json:"-"` + StartTime param.Opt[time.Time] `query:"start_time,omitzero" format:"date-time" json:"-"` + // Any of "success", "failure". + Outcome WorkloadIdentityAuthenticationEventListParamsOutcome `query:"outcome,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [WorkloadIdentityAuthenticationEventListParams]'s query +// parameters as `url.Values`. +func (r WorkloadIdentityAuthenticationEventListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatComma, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +type WorkloadIdentityAuthenticationEventListParamsOutcome string + +const ( + WorkloadIdentityAuthenticationEventListParamsOutcomeSuccess WorkloadIdentityAuthenticationEventListParamsOutcome = "success" + WorkloadIdentityAuthenticationEventListParamsOutcomeFailure WorkloadIdentityAuthenticationEventListParamsOutcome = "failure" +) diff --git a/workloadidentityauthenticationevent_test.go b/workloadidentityauthenticationevent_test.go new file mode 100644 index 0000000..3cc4b29 --- /dev/null +++ b/workloadidentityauthenticationevent_test.go @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel_test + +import ( + "context" + "errors" + "os" + "testing" + "time" + + "github.com/kernel/kernel-go-sdk" + "github.com/kernel/kernel-go-sdk/internal/testutil" + "github.com/kernel/kernel-go-sdk/option" +) + +func TestWorkloadIdentityAuthenticationEventListWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityAuthenticationEvents.List(context.TODO(), kernel.WorkloadIdentityAuthenticationEventListParams{ + EndTime: kernel.Time(time.Now()), + FederationRuleID: kernel.String("federation_rule_id"), + IssuerID: kernel.String("issuer_id"), + Limit: kernel.Int(1), + Offset: kernel.Int(0), + Outcome: kernel.WorkloadIdentityAuthenticationEventListParamsOutcomeSuccess, + ProjectID: kernel.String("project_id"), + ServiceAccountID: kernel.String("service_account_id"), + StartTime: kernel.Time(time.Now()), + }) + 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()) + } +} diff --git a/workloadidentityfederationrule.go b/workloadidentityfederationrule.go new file mode 100644 index 0000000..b29f549 --- /dev/null +++ b/workloadidentityfederationrule.go @@ -0,0 +1,609 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "slices" + "time" + + "github.com/kernel/kernel-go-sdk/internal/apijson" + "github.com/kernel/kernel-go-sdk/internal/apiquery" + shimjson "github.com/kernel/kernel-go-sdk/internal/encoding/json" + "github.com/kernel/kernel-go-sdk/internal/requestconfig" + "github.com/kernel/kernel-go-sdk/option" + "github.com/kernel/kernel-go-sdk/packages/pagination" + "github.com/kernel/kernel-go-sdk/packages/param" + "github.com/kernel/kernel-go-sdk/packages/respjson" +) + +// WorkloadIdentityFederationRuleService contains methods and other services that +// help with interacting with the kernel API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewWorkloadIdentityFederationRuleService] method instead. +type WorkloadIdentityFederationRuleService struct { + Options []option.RequestOption +} + +// NewWorkloadIdentityFederationRuleService generates a new service that applies +// the given options to each request. These options are applied after the parent +// client's options (if there is one), and before any request-specific options. +func NewWorkloadIdentityFederationRuleService(opts ...option.RequestOption) (r WorkloadIdentityFederationRuleService) { + r = WorkloadIdentityFederationRuleService{} + r.Options = opts + return +} + +// Organization credential administrators only. No external namespace-ownership or +// staff approval is required. New trust resources default disabled. +func (r *WorkloadIdentityFederationRuleService) New(ctx context.Context, body WorkloadIdentityFederationRuleNewParams, opts ...option.RequestOption) (res *WorkloadIdentityFederationRule, err error) { + opts = slices.Concat(r.Options, opts) + path := "org/workload_identity_federation_rules" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityFederationRuleService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *WorkloadIdentityFederationRule, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/workload_identity_federation_rules/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return res, err +} + +// Update a workload identity federation rule +func (r *WorkloadIdentityFederationRuleService) Update(ctx context.Context, id string, body WorkloadIdentityFederationRuleUpdateParams, opts ...option.RequestOption) (res *WorkloadIdentityFederationRule, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/workload_identity_federation_rules/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityFederationRuleService) List(ctx context.Context, query WorkloadIdentityFederationRuleListParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[WorkloadIdentityFederationRule], err error) { + var raw *http.Response + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "org/workload_identity_federation_rules" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityFederationRuleService) ListAutoPaging(ctx context.Context, query WorkloadIdentityFederationRuleListParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[WorkloadIdentityFederationRule] { + return pagination.NewOffsetPaginationAutoPager(r.List(ctx, query, opts...)) +} + +// Retains history and invalidates associated authority within the documented +// status bound. Does not delete created browser resources. +func (r *WorkloadIdentityFederationRuleService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error) { + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...) + if id == "" { + err = errors.New("missing required id parameter") + return err + } + path := fmt.Sprintf("org/workload_identity_federation_rules/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...) + return err +} + +type WorkloadIdentityAuthorization struct { + // Allow statements for resources in this rule's project, in the same format as a + // scoped API key policy. API key actions are not allowed. + Policy WorkloadIdentityAuthorizationPolicy `json:"policy" api:"required"` + // The one project credentials from this rule are limited to. + ProjectID string `json:"project_id" api:"required"` + TokenAudience string `json:"token_audience" api:"required"` + MaxTokenTtlSeconds int64 `json:"max_token_ttl_seconds"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Policy respjson.Field + ProjectID respjson.Field + TokenAudience respjson.Field + MaxTokenTtlSeconds respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityAuthorization) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityAuthorization) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this WorkloadIdentityAuthorization to a +// WorkloadIdentityAuthorizationParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// WorkloadIdentityAuthorizationParam.Overrides() +func (r WorkloadIdentityAuthorization) ToParam() WorkloadIdentityAuthorizationParam { + return param.Override[WorkloadIdentityAuthorizationParam](json.RawMessage(r.RawJSON())) +} + +// Allow statements for resources in this rule's project, in the same format as a +// scoped API key policy. API key actions are not allowed. +type WorkloadIdentityAuthorizationPolicy struct { + // Allow statements. Every action and resource not listed is denied. + Statements []WorkloadIdentityAuthorizationPolicyStatement `json:"statements" api:"required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Statements respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityAuthorizationPolicy) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityAuthorizationPolicy) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityAuthorizationPolicyStatement struct { + // Permitted action, such as browsers:use or vaults:read. + Action string `json:"action" api:"required"` + // Resource the action applies to, in the format projects/{project_id}/{kind}/{id}. + // Wildcards are supported. + Resource string `json:"resource" api:"required"` + // A condition narrows a policy statement to requests matching its constraint: the + // request attribute, a comparison operator, and that operator's values. + Condition WorkloadIdentityAuthorizationPolicyStatementCondition `json:"condition"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Action respjson.Field + Resource respjson.Field + Condition respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityAuthorizationPolicyStatement) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityAuthorizationPolicyStatement) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A condition narrows a policy statement to requests matching its constraint: the +// request attribute, a comparison operator, and that operator's values. +type WorkloadIdentityAuthorizationPolicyStatementCondition struct { + // Request attribute the condition constrains. `source_ip` restricts the statement + // to requests whose client address falls inside one of `values`. + // + // Any of "source_ip". + Key string `json:"key" api:"required"` + // Comparison the condition applies between the request attribute and values. + // + // Any of "in". + Operator string `json:"operator" api:"required"` + // Values the request attribute must match. For `source_ip`, CIDR networks: a bare + // address without a mask is rejected, and so are an entry with host bits set and + // an IPv4 network written in IPv6 notation. + Values []string `json:"values" api:"required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Key respjson.Field + Operator respjson.Field + Values respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityAuthorizationPolicyStatementCondition) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityAuthorizationPolicyStatementCondition) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The properties Policy, ProjectID, TokenAudience are required. +type WorkloadIdentityAuthorizationParam struct { + // Allow statements for resources in this rule's project, in the same format as a + // scoped API key policy. API key actions are not allowed. + Policy WorkloadIdentityAuthorizationPolicyParam `json:"policy,omitzero" api:"required"` + // The one project credentials from this rule are limited to. + ProjectID string `json:"project_id" api:"required"` + TokenAudience string `json:"token_audience" api:"required"` + MaxTokenTtlSeconds param.Opt[int64] `json:"max_token_ttl_seconds,omitzero"` + paramObj +} + +func (r WorkloadIdentityAuthorizationParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityAuthorizationParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityAuthorizationParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Allow statements for resources in this rule's project, in the same format as a +// scoped API key policy. API key actions are not allowed. +// +// The property Statements is required. +type WorkloadIdentityAuthorizationPolicyParam struct { + // Allow statements. Every action and resource not listed is denied. + Statements []WorkloadIdentityAuthorizationPolicyStatementParam `json:"statements,omitzero" api:"required"` + paramObj +} + +func (r WorkloadIdentityAuthorizationPolicyParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityAuthorizationPolicyParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityAuthorizationPolicyParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The properties Action, Resource are required. +type WorkloadIdentityAuthorizationPolicyStatementParam struct { + // Permitted action, such as browsers:use or vaults:read. + Action string `json:"action" api:"required"` + // Resource the action applies to, in the format projects/{project_id}/{kind}/{id}. + // Wildcards are supported. + Resource string `json:"resource" api:"required"` + // A condition narrows a policy statement to requests matching its constraint: the + // request attribute, a comparison operator, and that operator's values. + Condition WorkloadIdentityAuthorizationPolicyStatementConditionParam `json:"condition,omitzero"` + paramObj +} + +func (r WorkloadIdentityAuthorizationPolicyStatementParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityAuthorizationPolicyStatementParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityAuthorizationPolicyStatementParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A condition narrows a policy statement to requests matching its constraint: the +// request attribute, a comparison operator, and that operator's values. +// +// The properties Key, Operator, Values are required. +type WorkloadIdentityAuthorizationPolicyStatementConditionParam struct { + // Request attribute the condition constrains. `source_ip` restricts the statement + // to requests whose client address falls inside one of `values`. + // + // Any of "source_ip". + Key string `json:"key,omitzero" api:"required"` + // Comparison the condition applies between the request attribute and values. + // + // Any of "in". + Operator string `json:"operator,omitzero" api:"required"` + // Values the request attribute must match. For `source_ip`, CIDR networks: a bare + // address without a mask is rejected, and so are an entry with host bits set and + // an IPv4 network written in IPv6 notation. + Values []string `json:"values,omitzero" api:"required"` + paramObj +} + +func (r WorkloadIdentityAuthorizationPolicyStatementConditionParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityAuthorizationPolicyStatementConditionParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityAuthorizationPolicyStatementConditionParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +func init() { + apijson.RegisterFieldValidator[WorkloadIdentityAuthorizationPolicyStatementConditionParam]( + "key", "source_ip", + ) + apijson.RegisterFieldValidator[WorkloadIdentityAuthorizationPolicyStatementConditionParam]( + "operator", "in", + ) +} + +type WorkloadIdentityFederationRule struct { + ID string `json:"id" api:"required"` + ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"` + Authorization WorkloadIdentityAuthorization `json:"authorization" api:"required"` + CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` + CreatedByUserID string `json:"created_by_user_id" api:"required"` + Description string `json:"description" api:"required"` + Enabled bool `json:"enabled" api:"required"` + ExpectedAudience string `json:"expected_audience" api:"required"` + IssuerID string `json:"issuer_id" api:"required"` + LastExchangeAt time.Time `json:"last_exchange_at" api:"required" format:"date-time"` + Match WorkloadIdentityMatch `json:"match" api:"required"` + Name string `json:"name" api:"required"` + OrgID string `json:"org_id" api:"required"` + // Authority revision. Cosmetic updates do not widen permissions. + SecurityVersion int64 `json:"security_version" api:"required"` + Target WorkloadIdentityTarget `json:"target" api:"required"` + UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + ArchivedAt respjson.Field + Authorization respjson.Field + CreatedAt respjson.Field + CreatedByUserID respjson.Field + Description respjson.Field + Enabled respjson.Field + ExpectedAudience respjson.Field + IssuerID respjson.Field + LastExchangeAt respjson.Field + Match respjson.Field + Name respjson.Field + OrgID respjson.Field + SecurityVersion respjson.Field + Target respjson.Field + UpdatedAt respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityFederationRule) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityFederationRule) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The properties Authorization, ExpectedAudience, IssuerID, Match, Name, Target +// are required. +type WorkloadIdentityFederationRuleConfigParam struct { + Authorization WorkloadIdentityAuthorizationParam `json:"authorization,omitzero" api:"required"` + ExpectedAudience string `json:"expected_audience" api:"required"` + IssuerID string `json:"issuer_id" api:"required"` + Match WorkloadIdentityMatchParam `json:"match,omitzero" api:"required"` + Name string `json:"name" api:"required"` + Target WorkloadIdentityTargetParam `json:"target,omitzero" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + Enabled param.Opt[bool] `json:"enabled,omitzero"` + paramObj +} + +func (r WorkloadIdentityFederationRuleConfigParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityFederationRuleConfigParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityFederationRuleConfigParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityMatch struct { + // Must be the issuer's preset_type. + // + // Any of "github_actions", "aws", "google_cloud", "microsoft_entra", "kubernetes", + // "custom_oidc". + Type WorkloadIdentityMatchType `json:"type" api:"required"` + // Exact string conditions keyed by RFC 6901 JSON Pointers. All conditions are + // ANDed. + Claims map[string]string `json:"claims"` + Environment string `json:"environment"` + EventNames []string `json:"event_names"` + JobWorkflowRef string `json:"job_workflow_ref"` + Namespace string `json:"namespace"` + Ref string `json:"ref"` + // Friendly display name. Immutable IDs define the repository identity. + Repository string `json:"repository"` + RepositoryID string `json:"repository_id"` + RepositoryOwnerID string `json:"repository_owner_id"` + ServiceAccount string `json:"service_account"` + Subject string `json:"subject"` + SubjectPrefix string `json:"subject_prefix"` + Workflow string `json:"workflow"` + WorkflowRef string `json:"workflow_ref"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Type respjson.Field + Claims respjson.Field + Environment respjson.Field + EventNames respjson.Field + JobWorkflowRef respjson.Field + Namespace respjson.Field + Ref respjson.Field + Repository respjson.Field + RepositoryID respjson.Field + RepositoryOwnerID respjson.Field + ServiceAccount respjson.Field + Subject respjson.Field + SubjectPrefix respjson.Field + Workflow respjson.Field + WorkflowRef respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityMatch) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityMatch) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this WorkloadIdentityMatch to a WorkloadIdentityMatchParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// WorkloadIdentityMatchParam.Overrides() +func (r WorkloadIdentityMatch) ToParam() WorkloadIdentityMatchParam { + return param.Override[WorkloadIdentityMatchParam](json.RawMessage(r.RawJSON())) +} + +// Must be the issuer's preset_type. +type WorkloadIdentityMatchType string + +const ( + WorkloadIdentityMatchTypeGitHubActions WorkloadIdentityMatchType = "github_actions" + WorkloadIdentityMatchTypeAws WorkloadIdentityMatchType = "aws" + WorkloadIdentityMatchTypeGoogleCloud WorkloadIdentityMatchType = "google_cloud" + WorkloadIdentityMatchTypeMicrosoftEntra WorkloadIdentityMatchType = "microsoft_entra" + WorkloadIdentityMatchTypeKubernetes WorkloadIdentityMatchType = "kubernetes" + WorkloadIdentityMatchTypeCustomOidc WorkloadIdentityMatchType = "custom_oidc" +) + +// The property Type is required. +type WorkloadIdentityMatchParam struct { + // Must be the issuer's preset_type. + // + // Any of "github_actions", "aws", "google_cloud", "microsoft_entra", "kubernetes", + // "custom_oidc". + Type WorkloadIdentityMatchType `json:"type,omitzero" api:"required"` + Environment param.Opt[string] `json:"environment,omitzero"` + JobWorkflowRef param.Opt[string] `json:"job_workflow_ref,omitzero"` + Namespace param.Opt[string] `json:"namespace,omitzero"` + Ref param.Opt[string] `json:"ref,omitzero"` + // Friendly display name. Immutable IDs define the repository identity. + Repository param.Opt[string] `json:"repository,omitzero"` + RepositoryID param.Opt[string] `json:"repository_id,omitzero"` + RepositoryOwnerID param.Opt[string] `json:"repository_owner_id,omitzero"` + ServiceAccount param.Opt[string] `json:"service_account,omitzero"` + Subject param.Opt[string] `json:"subject,omitzero"` + SubjectPrefix param.Opt[string] `json:"subject_prefix,omitzero"` + Workflow param.Opt[string] `json:"workflow,omitzero"` + WorkflowRef param.Opt[string] `json:"workflow_ref,omitzero"` + // Exact string conditions keyed by RFC 6901 JSON Pointers. All conditions are + // ANDed. + Claims map[string]string `json:"claims,omitzero"` + EventNames []string `json:"event_names,omitzero"` + paramObj +} + +func (r WorkloadIdentityMatchParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityMatchParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityMatchParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityTarget struct { + ServiceAccountID string `json:"service_account_id" api:"required"` + // Any of "service_account". + Type WorkloadIdentityTargetType `json:"type" api:"required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ServiceAccountID respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityTarget) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityTarget) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this WorkloadIdentityTarget to a WorkloadIdentityTargetParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// WorkloadIdentityTargetParam.Overrides() +func (r WorkloadIdentityTarget) ToParam() WorkloadIdentityTargetParam { + return param.Override[WorkloadIdentityTargetParam](json.RawMessage(r.RawJSON())) +} + +type WorkloadIdentityTargetType string + +const ( + WorkloadIdentityTargetTypeServiceAccount WorkloadIdentityTargetType = "service_account" +) + +// The properties ServiceAccountID, Type are required. +type WorkloadIdentityTargetParam struct { + ServiceAccountID string `json:"service_account_id" api:"required"` + // Any of "service_account". + Type WorkloadIdentityTargetType `json:"type,omitzero" api:"required"` + paramObj +} + +func (r WorkloadIdentityTargetParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityTargetParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityTargetParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityFederationRuleNewParams struct { + WorkloadIdentityFederationRuleConfig WorkloadIdentityFederationRuleConfigParam + paramObj +} + +func (r WorkloadIdentityFederationRuleNewParams) MarshalJSON() (data []byte, err error) { + return shimjson.Marshal(r.WorkloadIdentityFederationRuleConfig) +} +func (r *WorkloadIdentityFederationRuleNewParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityFederationRuleUpdateParams struct { + ExpectedVersion int64 `json:"expected_version" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + Enabled param.Opt[bool] `json:"enabled,omitzero"` + ExpectedAudience param.Opt[string] `json:"expected_audience,omitzero"` + IssuerID param.Opt[string] `json:"issuer_id,omitzero"` + Name param.Opt[string] `json:"name,omitzero"` + Authorization WorkloadIdentityAuthorizationParam `json:"authorization,omitzero"` + Match WorkloadIdentityMatchParam `json:"match,omitzero"` + Target WorkloadIdentityTargetParam `json:"target,omitzero"` + paramObj +} + +func (r WorkloadIdentityFederationRuleUpdateParams) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityFederationRuleUpdateParams + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityFederationRuleUpdateParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityFederationRuleListParams struct { + IssuerID param.Opt[string] `query:"issuer_id,omitzero" json:"-"` + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + Offset param.Opt[int64] `query:"offset,omitzero" json:"-"` + ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"` + // Case-insensitive substring match against name or description; exact ID match. + Query param.Opt[string] `query:"query,omitzero" json:"-"` + ServiceAccountID param.Opt[string] `query:"service_account_id,omitzero" json:"-"` + // Any of "active", "archived", "all". + Status WorkloadIdentityFederationRuleListParamsStatus `query:"status,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [WorkloadIdentityFederationRuleListParams]'s query +// parameters as `url.Values`. +func (r WorkloadIdentityFederationRuleListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatComma, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +type WorkloadIdentityFederationRuleListParamsStatus string + +const ( + WorkloadIdentityFederationRuleListParamsStatusActive WorkloadIdentityFederationRuleListParamsStatus = "active" + WorkloadIdentityFederationRuleListParamsStatusArchived WorkloadIdentityFederationRuleListParamsStatus = "archived" + WorkloadIdentityFederationRuleListParamsStatusAll WorkloadIdentityFederationRuleListParamsStatus = "all" +) diff --git a/workloadidentityfederationrule_test.go b/workloadidentityfederationrule_test.go new file mode 100644 index 0000000..05e5966 --- /dev/null +++ b/workloadidentityfederationrule_test.go @@ -0,0 +1,234 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/kernel/kernel-go-sdk" + "github.com/kernel/kernel-go-sdk/internal/testutil" + "github.com/kernel/kernel-go-sdk/option" +) + +func TestWorkloadIdentityFederationRuleNewWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityFederationRules.New(context.TODO(), kernel.WorkloadIdentityFederationRuleNewParams{ + WorkloadIdentityFederationRuleConfig: kernel.WorkloadIdentityFederationRuleConfigParam{ + Authorization: kernel.WorkloadIdentityAuthorizationParam{ + Policy: kernel.WorkloadIdentityAuthorizationPolicyParam{ + Statements: []kernel.WorkloadIdentityAuthorizationPolicyStatementParam{{ + Action: "browsers:use", + Resource: "projects/proj_abc123/browsers/br_abc123", + Condition: kernel.WorkloadIdentityAuthorizationPolicyStatementConditionParam{ + Key: "source_ip", + Operator: "in", + Values: []string{"203.0.113.0/24"}, + }, + }}, + }, + ProjectID: "x", + TokenAudience: "x", + MaxTokenTtlSeconds: kernel.Int(1), + }, + ExpectedAudience: "x", + IssuerID: "x", + Match: kernel.WorkloadIdentityMatchParam{ + Type: kernel.WorkloadIdentityMatchTypeGitHubActions, + Claims: map[string]string{ + "foo": "x", + }, + Environment: kernel.String("environment"), + EventNames: []string{"x"}, + JobWorkflowRef: kernel.String("job_workflow_ref"), + Namespace: kernel.String("namespace"), + Ref: kernel.String("ref"), + Repository: kernel.String("repository"), + RepositoryID: kernel.String("269125115713"), + RepositoryOwnerID: kernel.String("269125115713"), + ServiceAccount: kernel.String("service_account"), + Subject: kernel.String("x"), + SubjectPrefix: kernel.String("x"), + Workflow: kernel.String("workflow"), + WorkflowRef: kernel.String("workflow_ref"), + }, + Name: "name", + Target: kernel.WorkloadIdentityTargetParam{ + ServiceAccountID: "x", + Type: kernel.WorkloadIdentityTargetTypeServiceAccount, + }, + Description: kernel.String("description"), + Enabled: kernel.Bool(true), + }, + }) + 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()) + } +} + +func TestWorkloadIdentityFederationRuleGet(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityFederationRules.Get(context.TODO(), "id") + 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()) + } +} + +func TestWorkloadIdentityFederationRuleUpdateWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityFederationRules.Update( + context.TODO(), + "id", + kernel.WorkloadIdentityFederationRuleUpdateParams{ + ExpectedVersion: 1, + Authorization: kernel.WorkloadIdentityAuthorizationParam{ + Policy: kernel.WorkloadIdentityAuthorizationPolicyParam{ + Statements: []kernel.WorkloadIdentityAuthorizationPolicyStatementParam{{ + Action: "browsers:use", + Resource: "projects/proj_abc123/browsers/br_abc123", + Condition: kernel.WorkloadIdentityAuthorizationPolicyStatementConditionParam{ + Key: "source_ip", + Operator: "in", + Values: []string{"203.0.113.0/24"}, + }, + }}, + }, + ProjectID: "x", + TokenAudience: "x", + MaxTokenTtlSeconds: kernel.Int(1), + }, + Description: kernel.String("description"), + Enabled: kernel.Bool(true), + ExpectedAudience: kernel.String("x"), + IssuerID: kernel.String("x"), + Match: kernel.WorkloadIdentityMatchParam{ + Type: kernel.WorkloadIdentityMatchTypeGitHubActions, + Claims: map[string]string{ + "foo": "x", + }, + Environment: kernel.String("environment"), + EventNames: []string{"x"}, + JobWorkflowRef: kernel.String("job_workflow_ref"), + Namespace: kernel.String("namespace"), + Ref: kernel.String("ref"), + Repository: kernel.String("repository"), + RepositoryID: kernel.String("269125115713"), + RepositoryOwnerID: kernel.String("269125115713"), + ServiceAccount: kernel.String("service_account"), + Subject: kernel.String("x"), + SubjectPrefix: kernel.String("x"), + Workflow: kernel.String("workflow"), + WorkflowRef: kernel.String("workflow_ref"), + }, + Name: kernel.String("name"), + Target: kernel.WorkloadIdentityTargetParam{ + ServiceAccountID: "x", + Type: kernel.WorkloadIdentityTargetTypeServiceAccount, + }, + }, + ) + 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()) + } +} + +func TestWorkloadIdentityFederationRuleListWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityFederationRules.List(context.TODO(), kernel.WorkloadIdentityFederationRuleListParams{ + IssuerID: kernel.String("issuer_id"), + Limit: kernel.Int(1), + Offset: kernel.Int(0), + ProjectID: kernel.String("project_id"), + Query: kernel.String("query"), + ServiceAccountID: kernel.String("service_account_id"), + Status: kernel.WorkloadIdentityFederationRuleListParamsStatusActive, + }) + 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()) + } +} + +func TestWorkloadIdentityFederationRuleDelete(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.WorkloadIdentityFederationRules.Delete(context.TODO(), "id") + 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()) + } +} diff --git a/workloadidentityissuer.go b/workloadidentityissuer.go new file mode 100644 index 0000000..41a43b7 --- /dev/null +++ b/workloadidentityissuer.go @@ -0,0 +1,448 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "slices" + "time" + + "github.com/kernel/kernel-go-sdk/internal/apijson" + "github.com/kernel/kernel-go-sdk/internal/apiquery" + shimjson "github.com/kernel/kernel-go-sdk/internal/encoding/json" + "github.com/kernel/kernel-go-sdk/internal/requestconfig" + "github.com/kernel/kernel-go-sdk/option" + "github.com/kernel/kernel-go-sdk/packages/pagination" + "github.com/kernel/kernel-go-sdk/packages/param" + "github.com/kernel/kernel-go-sdk/packages/respjson" +) + +// WorkloadIdentityIssuerService contains methods and other services that help with +// interacting with the kernel API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewWorkloadIdentityIssuerService] method instead. +type WorkloadIdentityIssuerService struct { + Options []option.RequestOption +} + +// NewWorkloadIdentityIssuerService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewWorkloadIdentityIssuerService(opts ...option.RequestOption) (r WorkloadIdentityIssuerService) { + r = WorkloadIdentityIssuerService{} + r.Options = opts + return +} + +// Organization credential administrators only. No external namespace-ownership or +// staff approval is required. New trust resources default disabled. +func (r *WorkloadIdentityIssuerService) New(ctx context.Context, body WorkloadIdentityIssuerNewParams, opts ...option.RequestOption) (res *WorkloadIdentityIssuer, err error) { + opts = slices.Concat(r.Options, opts) + path := "org/workload_identity_issuers" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityIssuerService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *WorkloadIdentityIssuer, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/workload_identity_issuers/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return res, err +} + +// Update a workload identity issuer +func (r *WorkloadIdentityIssuerService) Update(ctx context.Context, id string, body WorkloadIdentityIssuerUpdateParams, opts ...option.RequestOption) (res *WorkloadIdentityIssuer, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/workload_identity_issuers/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...) + return res, err +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityIssuerService) List(ctx context.Context, query WorkloadIdentityIssuerListParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[WorkloadIdentityIssuer], err error) { + var raw *http.Response + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "org/workload_identity_issuers" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Any signed-in member of the organization can read this. API keys cannot. +func (r *WorkloadIdentityIssuerService) ListAutoPaging(ctx context.Context, query WorkloadIdentityIssuerListParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[WorkloadIdentityIssuer] { + return pagination.NewOffsetPaginationAutoPager(r.List(ctx, query, opts...)) +} + +// Retains history and invalidates associated authority within the documented +// status bound. Does not delete created browser resources. +func (r *WorkloadIdentityIssuerService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error) { + opts = slices.Concat(r.Options, opts) + opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...) + if id == "" { + err = errors.New("missing required id parameter") + return err + } + path := fmt.Sprintf("org/workload_identity_issuers/%s", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...) + return err +} + +// Read-only. Does not enable trust, approve namespace ownership, create a grant or +// issue credentials. +func (r *WorkloadIdentityIssuerService) Verify(ctx context.Context, id string, opts ...option.RequestOption) (res *WorkloadIdentityIssuerKeyCheck, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return nil, err + } + path := fmt.Sprintf("org/workload_identity_issuers/%s/verify", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) + return res, err +} + +type WorkloadIdentityIssuer struct { + ID string `json:"id" api:"required"` + ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"` + CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` + CreatedByUserID string `json:"created_by_user_id" api:"required"` + Description string `json:"description" api:"required"` + Enabled bool `json:"enabled" api:"required"` + // Exact expected signed issuer. Optional for github_actions and google_cloud, + // which each have one fixed issuer. + IssuerURL string `json:"issuer_url" api:"required" format:"uri"` + Jwks WorkloadIdentityKeySource `json:"jwks" api:"required"` + Name string `json:"name" api:"required"` + OrgID string `json:"org_id" api:"required"` + // The kind of identity provider. GitHub Actions, Google Cloud and Microsoft Entra + // issuers are recognized by their issuer URL and must use their own type. Defaults + // to the type the issuer URL belongs to, or custom_oidc. + // + // Any of "github_actions", "aws", "google_cloud", "microsoft_entra", "kubernetes", + // "custom_oidc". + PresetType WorkloadIdentityPresetType `json:"preset_type" api:"required"` + // Authority revision. Cosmetic updates do not widen permissions. + SecurityVersion int64 `json:"security_version" api:"required"` + TokenValidation WorkloadIdentityTokenValidation `json:"token_validation" api:"required"` + UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + ArchivedAt respjson.Field + CreatedAt respjson.Field + CreatedByUserID respjson.Field + Description respjson.Field + Enabled respjson.Field + IssuerURL respjson.Field + Jwks respjson.Field + Name respjson.Field + OrgID respjson.Field + PresetType respjson.Field + SecurityVersion respjson.Field + TokenValidation respjson.Field + UpdatedAt respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityIssuer) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityIssuer) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The property Name is required. +type WorkloadIdentityIssuerConfigParam struct { + Name string `json:"name" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + Enabled param.Opt[bool] `json:"enabled,omitzero"` + // Exact expected signed issuer. Optional for github_actions and google_cloud, + // which each have one fixed issuer. + IssuerURL param.Opt[string] `json:"issuer_url,omitzero" format:"uri"` + Jwks WorkloadIdentityKeySourceParam `json:"jwks,omitzero"` + // The kind of identity provider. GitHub Actions, Google Cloud and Microsoft Entra + // issuers are recognized by their issuer URL and must use their own type. Defaults + // to the type the issuer URL belongs to, or custom_oidc. + // + // Any of "github_actions", "aws", "google_cloud", "microsoft_entra", "kubernetes", + // "custom_oidc". + PresetType WorkloadIdentityPresetType `json:"preset_type,omitzero"` + TokenValidation WorkloadIdentityTokenValidationParam `json:"token_validation,omitzero"` + paramObj +} + +func (r WorkloadIdentityIssuerConfigParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityIssuerConfigParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityIssuerConfigParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityIssuerKeyCheck struct { + IssuerID string `json:"issuer_id" api:"required"` + KeyIDs []string `json:"key_ids" api:"required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + IssuerID respjson.Field + KeyIDs respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityIssuerKeyCheck) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityIssuerKeyCheck) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityKeySource struct { + // Any of "discovery", "explicit_url", "inline". + Type WorkloadIdentityKeySourceType `json:"type" api:"required"` + // Optional public CA certificates. When set, only these CAs are trusted for key + // retrieval, in place of the system roots. Private keys and private-network + // retrieval are not supported. + CaCertPem string `json:"ca_cert_pem"` + DiscoveryBaseURL string `json:"discovery_base_url" format:"uri"` + Keys []map[string]any `json:"keys"` + URL string `json:"url" format:"uri"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Type respjson.Field + CaCertPem respjson.Field + DiscoveryBaseURL respjson.Field + Keys respjson.Field + URL respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityKeySource) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityKeySource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this WorkloadIdentityKeySource to a +// WorkloadIdentityKeySourceParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// WorkloadIdentityKeySourceParam.Overrides() +func (r WorkloadIdentityKeySource) ToParam() WorkloadIdentityKeySourceParam { + return param.Override[WorkloadIdentityKeySourceParam](json.RawMessage(r.RawJSON())) +} + +type WorkloadIdentityKeySourceType string + +const ( + WorkloadIdentityKeySourceTypeDiscovery WorkloadIdentityKeySourceType = "discovery" + WorkloadIdentityKeySourceTypeExplicitURL WorkloadIdentityKeySourceType = "explicit_url" + WorkloadIdentityKeySourceTypeInline WorkloadIdentityKeySourceType = "inline" +) + +// The property Type is required. +type WorkloadIdentityKeySourceParam struct { + // Any of "discovery", "explicit_url", "inline". + Type WorkloadIdentityKeySourceType `json:"type,omitzero" api:"required"` + // Optional public CA certificates. When set, only these CAs are trusted for key + // retrieval, in place of the system roots. Private keys and private-network + // retrieval are not supported. + CaCertPem param.Opt[string] `json:"ca_cert_pem,omitzero"` + DiscoveryBaseURL param.Opt[string] `json:"discovery_base_url,omitzero" format:"uri"` + URL param.Opt[string] `json:"url,omitzero" format:"uri"` + Keys []map[string]any `json:"keys,omitzero"` + paramObj +} + +func (r WorkloadIdentityKeySourceParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityKeySourceParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityKeySourceParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The kind of identity provider. GitHub Actions, Google Cloud and Microsoft Entra +// issuers are recognized by their issuer URL and must use their own type. Defaults +// to the type the issuer URL belongs to, or custom_oidc. +type WorkloadIdentityPresetType string + +const ( + WorkloadIdentityPresetTypeGitHubActions WorkloadIdentityPresetType = "github_actions" + WorkloadIdentityPresetTypeAws WorkloadIdentityPresetType = "aws" + WorkloadIdentityPresetTypeGoogleCloud WorkloadIdentityPresetType = "google_cloud" + WorkloadIdentityPresetTypeMicrosoftEntra WorkloadIdentityPresetType = "microsoft_entra" + WorkloadIdentityPresetTypeKubernetes WorkloadIdentityPresetType = "kubernetes" + WorkloadIdentityPresetTypeCustomOidc WorkloadIdentityPresetType = "custom_oidc" +) + +type WorkloadIdentityTokenValidation struct { + // Maximum incoming signed exp minus iat, independent of outgoing token lifetime. + MaxLifetimeSeconds int64 `json:"max_lifetime_seconds"` + // Whether an incoming token can be exchanged more than once before it expires. + // Defaults to single_use for github_actions, aws, microsoft_entra and custom_oidc, + // and to allow_reuse for kubernetes, because a pod reads the same projected token + // until it is rotated. google_cloud is always allow_reuse because Google identity + // tokens carry no token ID. allow_reuse can be set on microsoft_entra and + // custom_oidc, and single_use on kubernetes. github_actions and aws are always + // single_use. + // + // Any of "single_use", "allow_reuse". + ReplayProtection WorkloadIdentityTokenValidationReplayProtection `json:"replay_protection"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + MaxLifetimeSeconds respjson.Field + ReplayProtection respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r WorkloadIdentityTokenValidation) RawJSON() string { return r.JSON.raw } +func (r *WorkloadIdentityTokenValidation) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this WorkloadIdentityTokenValidation to a +// WorkloadIdentityTokenValidationParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// WorkloadIdentityTokenValidationParam.Overrides() +func (r WorkloadIdentityTokenValidation) ToParam() WorkloadIdentityTokenValidationParam { + return param.Override[WorkloadIdentityTokenValidationParam](json.RawMessage(r.RawJSON())) +} + +// Whether an incoming token can be exchanged more than once before it expires. +// Defaults to single_use for github_actions, aws, microsoft_entra and custom_oidc, +// and to allow_reuse for kubernetes, because a pod reads the same projected token +// until it is rotated. google_cloud is always allow_reuse because Google identity +// tokens carry no token ID. allow_reuse can be set on microsoft_entra and +// custom_oidc, and single_use on kubernetes. github_actions and aws are always +// single_use. +type WorkloadIdentityTokenValidationReplayProtection string + +const ( + WorkloadIdentityTokenValidationReplayProtectionSingleUse WorkloadIdentityTokenValidationReplayProtection = "single_use" + WorkloadIdentityTokenValidationReplayProtectionAllowReuse WorkloadIdentityTokenValidationReplayProtection = "allow_reuse" +) + +type WorkloadIdentityTokenValidationParam struct { + // Maximum incoming signed exp minus iat, independent of outgoing token lifetime. + MaxLifetimeSeconds param.Opt[int64] `json:"max_lifetime_seconds,omitzero"` + // Whether an incoming token can be exchanged more than once before it expires. + // Defaults to single_use for github_actions, aws, microsoft_entra and custom_oidc, + // and to allow_reuse for kubernetes, because a pod reads the same projected token + // until it is rotated. google_cloud is always allow_reuse because Google identity + // tokens carry no token ID. allow_reuse can be set on microsoft_entra and + // custom_oidc, and single_use on kubernetes. github_actions and aws are always + // single_use. + // + // Any of "single_use", "allow_reuse". + ReplayProtection WorkloadIdentityTokenValidationReplayProtection `json:"replay_protection,omitzero"` + paramObj +} + +func (r WorkloadIdentityTokenValidationParam) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityTokenValidationParam + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityTokenValidationParam) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityIssuerNewParams struct { + WorkloadIdentityIssuerConfig WorkloadIdentityIssuerConfigParam + paramObj +} + +func (r WorkloadIdentityIssuerNewParams) MarshalJSON() (data []byte, err error) { + return shimjson.Marshal(r.WorkloadIdentityIssuerConfig) +} +func (r *WorkloadIdentityIssuerNewParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityIssuerUpdateParams struct { + ExpectedVersion int64 `json:"expected_version" api:"required"` + Description param.Opt[string] `json:"description,omitzero"` + Enabled param.Opt[bool] `json:"enabled,omitzero"` + // Exact expected signed issuer. Optional for github_actions and google_cloud, + // which each have one fixed issuer. + IssuerURL param.Opt[string] `json:"issuer_url,omitzero" format:"uri"` + Name param.Opt[string] `json:"name,omitzero"` + Jwks WorkloadIdentityKeySourceParam `json:"jwks,omitzero"` + // The kind of identity provider. GitHub Actions, Google Cloud and Microsoft Entra + // issuers are recognized by their issuer URL and must use their own type. Defaults + // to the type the issuer URL belongs to, or custom_oidc. + // + // Any of "github_actions", "aws", "google_cloud", "microsoft_entra", "kubernetes", + // "custom_oidc". + PresetType WorkloadIdentityPresetType `json:"preset_type,omitzero"` + TokenValidation WorkloadIdentityTokenValidationParam `json:"token_validation,omitzero"` + paramObj +} + +func (r WorkloadIdentityIssuerUpdateParams) MarshalJSON() (data []byte, err error) { + type shadow WorkloadIdentityIssuerUpdateParams + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *WorkloadIdentityIssuerUpdateParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type WorkloadIdentityIssuerListParams struct { + Enabled param.Opt[bool] `query:"enabled,omitzero" json:"-"` + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + Offset param.Opt[int64] `query:"offset,omitzero" json:"-"` + // Case-insensitive substring match against name or description; exact ID match. + Query param.Opt[string] `query:"query,omitzero" json:"-"` + // Any of "active", "archived", "all". + Status WorkloadIdentityIssuerListParamsStatus `query:"status,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [WorkloadIdentityIssuerListParams]'s query parameters as +// `url.Values`. +func (r WorkloadIdentityIssuerListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatComma, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +type WorkloadIdentityIssuerListParamsStatus string + +const ( + WorkloadIdentityIssuerListParamsStatusActive WorkloadIdentityIssuerListParamsStatus = "active" + WorkloadIdentityIssuerListParamsStatusArchived WorkloadIdentityIssuerListParamsStatus = "archived" + WorkloadIdentityIssuerListParamsStatusAll WorkloadIdentityIssuerListParamsStatus = "all" +) diff --git a/workloadidentityissuer_test.go b/workloadidentityissuer_test.go new file mode 100644 index 0000000..554b2e3 --- /dev/null +++ b/workloadidentityissuer_test.go @@ -0,0 +1,203 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/kernel/kernel-go-sdk" + "github.com/kernel/kernel-go-sdk/internal/testutil" + "github.com/kernel/kernel-go-sdk/option" +) + +func TestWorkloadIdentityIssuerNewWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityIssuers.New(context.TODO(), kernel.WorkloadIdentityIssuerNewParams{ + WorkloadIdentityIssuerConfig: kernel.WorkloadIdentityIssuerConfigParam{ + Name: "name", + Description: kernel.String("description"), + Enabled: kernel.Bool(true), + IssuerURL: kernel.String("https://example.com"), + Jwks: kernel.WorkloadIdentityKeySourceParam{ + Type: kernel.WorkloadIdentityKeySourceTypeDiscovery, + CaCertPem: kernel.String("ca_cert_pem"), + DiscoveryBaseURL: kernel.String("https://example.com"), + Keys: []map[string]any{{ + "foo": "bar", + }}, + URL: kernel.String("https://example.com"), + }, + PresetType: kernel.WorkloadIdentityPresetTypeGitHubActions, + TokenValidation: kernel.WorkloadIdentityTokenValidationParam{ + MaxLifetimeSeconds: kernel.Int(1), + ReplayProtection: kernel.WorkloadIdentityTokenValidationReplayProtectionSingleUse, + }, + }, + }) + 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()) + } +} + +func TestWorkloadIdentityIssuerGet(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityIssuers.Get(context.TODO(), "id") + 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()) + } +} + +func TestWorkloadIdentityIssuerUpdateWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityIssuers.Update( + context.TODO(), + "id", + kernel.WorkloadIdentityIssuerUpdateParams{ + ExpectedVersion: 1, + Description: kernel.String("description"), + Enabled: kernel.Bool(true), + IssuerURL: kernel.String("https://example.com"), + Jwks: kernel.WorkloadIdentityKeySourceParam{ + Type: kernel.WorkloadIdentityKeySourceTypeDiscovery, + CaCertPem: kernel.String("ca_cert_pem"), + DiscoveryBaseURL: kernel.String("https://example.com"), + Keys: []map[string]any{{ + "foo": "bar", + }}, + URL: kernel.String("https://example.com"), + }, + Name: kernel.String("name"), + PresetType: kernel.WorkloadIdentityPresetTypeGitHubActions, + TokenValidation: kernel.WorkloadIdentityTokenValidationParam{ + MaxLifetimeSeconds: kernel.Int(1), + ReplayProtection: kernel.WorkloadIdentityTokenValidationReplayProtectionSingleUse, + }, + }, + ) + 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()) + } +} + +func TestWorkloadIdentityIssuerListWithOptionalParams(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityIssuers.List(context.TODO(), kernel.WorkloadIdentityIssuerListParams{ + Enabled: kernel.Bool(true), + Limit: kernel.Int(1), + Offset: kernel.Int(0), + Query: kernel.String("query"), + Status: kernel.WorkloadIdentityIssuerListParamsStatusActive, + }) + 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()) + } +} + +func TestWorkloadIdentityIssuerDelete(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.WorkloadIdentityIssuers.Delete(context.TODO(), "id") + 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()) + } +} + +func TestWorkloadIdentityIssuerVerify(t *testing.T) { + t.Skip("Mock server tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.WorkloadIdentityIssuers.Verify(context.TODO(), "id") + 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()) + } +}