cloudflare
Version:
The official TypeScript library for the Cloudflare API
533 lines (470 loc) • 14 kB
text/typescript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../core/pagination';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class BaseTargetEnvironments extends APIResource {
static override readonly _key: readonly ['vulnerabilityScanner', 'targetEnvironments'] = Object.freeze([
'vulnerabilityScanner',
'targetEnvironments',
] as const);
/**
* Creates a new target environment for the account.
*
* @example
* ```ts
* const targetEnvironment =
* await client.vulnerabilityScanner.targetEnvironments.create(
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'Production Zone',
* target: {
* type: 'zone',
* zone_tag: 'd8e8fca2dc0f896fd7cb4cb0031ba249',
* },
* },
* );
* ```
*/
create(
params: TargetEnvironmentCreateParams,
options?: RequestOptions,
): APIPromise<TargetEnvironmentCreateResponse> {
const { account_id, ...body } = params;
return (
this._client.post(path`/accounts/${account_id}/vuln_scanner/target_environments`, {
body,
...options,
}) as APIPromise<{ result: TargetEnvironmentCreateResponse }>
)._thenUnwrap((obj) => obj.result);
}
/**
* Replaces a target environment. All fields must be provided.
*
* @example
* ```ts
* const targetEnvironment =
* await client.vulnerabilityScanner.targetEnvironments.update(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'Production Zone',
* target: {
* type: 'zone',
* zone_tag: 'd8e8fca2dc0f896fd7cb4cb0031ba249',
* },
* },
* );
* ```
*/
update(
targetEnvironmentID: string,
params: TargetEnvironmentUpdateParams,
options?: RequestOptions,
): APIPromise<TargetEnvironmentUpdateResponse> {
const { account_id, ...body } = params;
return (
this._client.put(
path`/accounts/${account_id}/vuln_scanner/target_environments/${targetEnvironmentID}`,
{ body, ...options },
) as APIPromise<{ result: TargetEnvironmentUpdateResponse }>
)._thenUnwrap((obj) => obj.result);
}
/**
* Returns all target environments for the account.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const targetEnvironmentListResponse of client.vulnerabilityScanner.targetEnvironments.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(
params: TargetEnvironmentListParams,
options?: RequestOptions,
): PagePromise<TargetEnvironmentListResponsesV4PagePaginationArray, TargetEnvironmentListResponse> {
const { account_id, ...query } = params;
return this._client.getAPIList(
path`/accounts/${account_id}/vuln_scanner/target_environments`,
V4PagePaginationArray<TargetEnvironmentListResponse>,
{ query, ...options },
);
}
/**
* Removes a target environment.
*
* @example
* ```ts
* const targetEnvironment =
* await client.vulnerabilityScanner.targetEnvironments.delete(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(
targetEnvironmentID: string,
params: TargetEnvironmentDeleteParams,
options?: RequestOptions,
): APIPromise<TargetEnvironmentDeleteResponse | null> {
const { account_id } = params;
return (
this._client.delete(
path`/accounts/${account_id}/vuln_scanner/target_environments/${targetEnvironmentID}`,
options,
) as APIPromise<{ result: TargetEnvironmentDeleteResponse | null }>
)._thenUnwrap((obj) => obj.result);
}
/**
* Updates a target environment with only the provided fields; omitted fields
* remain unchanged.
*
* @example
* ```ts
* const response =
* await client.vulnerabilityScanner.targetEnvironments.edit(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
edit(
targetEnvironmentID: string,
params: TargetEnvironmentEditParams,
options?: RequestOptions,
): APIPromise<TargetEnvironmentEditResponse> {
const { account_id, ...body } = params;
return (
this._client.patch(
path`/accounts/${account_id}/vuln_scanner/target_environments/${targetEnvironmentID}`,
{ body, ...options },
) as APIPromise<{ result: TargetEnvironmentEditResponse }>
)._thenUnwrap((obj) => obj.result);
}
/**
* Returns a single target environment by ID.
*
* @example
* ```ts
* const targetEnvironment =
* await client.vulnerabilityScanner.targetEnvironments.get(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(
targetEnvironmentID: string,
params: TargetEnvironmentGetParams,
options?: RequestOptions,
): APIPromise<TargetEnvironmentGetResponse> {
const { account_id } = params;
return (
this._client.get(
path`/accounts/${account_id}/vuln_scanner/target_environments/${targetEnvironmentID}`,
options,
) as APIPromise<{ result: TargetEnvironmentGetResponse }>
)._thenUnwrap((obj) => obj.result);
}
}
export class TargetEnvironments extends BaseTargetEnvironments {}
export type TargetEnvironmentListResponsesV4PagePaginationArray =
V4PagePaginationArray<TargetEnvironmentListResponse>;
export interface TargetEnvironmentCreateResponse {
/**
* Target environment identifier.
*/
id: string;
/**
* Human-readable name.
*/
name: string;
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
target: TargetEnvironmentCreateResponse.Target;
/**
* Optional description providing additional context.
*/
description?: string | null;
}
export namespace TargetEnvironmentCreateResponse {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentUpdateResponse {
/**
* Target environment identifier.
*/
id: string;
/**
* Human-readable name.
*/
name: string;
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
target: TargetEnvironmentUpdateResponse.Target;
/**
* Optional description providing additional context.
*/
description?: string | null;
}
export namespace TargetEnvironmentUpdateResponse {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentListResponse {
/**
* Target environment identifier.
*/
id: string;
/**
* Human-readable name.
*/
name: string;
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
target: TargetEnvironmentListResponse.Target;
/**
* Optional description providing additional context.
*/
description?: string | null;
}
export namespace TargetEnvironmentListResponse {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export type TargetEnvironmentDeleteResponse = unknown;
export interface TargetEnvironmentEditResponse {
/**
* Target environment identifier.
*/
id: string;
/**
* Human-readable name.
*/
name: string;
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
target: TargetEnvironmentEditResponse.Target;
/**
* Optional description providing additional context.
*/
description?: string | null;
}
export namespace TargetEnvironmentEditResponse {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentGetResponse {
/**
* Target environment identifier.
*/
id: string;
/**
* Human-readable name.
*/
name: string;
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
target: TargetEnvironmentGetResponse.Target;
/**
* Optional description providing additional context.
*/
description?: string | null;
}
export namespace TargetEnvironmentGetResponse {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentCreateParams {
/**
* Path param: Account identifier.
*/
account_id: string;
/**
* Body param: Human-readable name.
*/
name: string;
/**
* Body param: Identifies the Cloudflare asset to scan. Uses a `type`
* discriminator. Currently the service supports only `zone` targets.
*/
target: TargetEnvironmentCreateParams.Target;
/**
* Body param: Optional description.
*/
description?: string | null;
}
export namespace TargetEnvironmentCreateParams {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentUpdateParams {
/**
* Path param: Account identifier.
*/
account_id: string;
/**
* Body param: Human-readable name.
*/
name: string;
/**
* Body param: Identifies the Cloudflare asset to scan. Uses a `type`
* discriminator. Currently the service supports only `zone` targets.
*/
target: TargetEnvironmentUpdateParams.Target;
/**
* Body param: Optional description.
*/
description?: string | null;
}
export namespace TargetEnvironmentUpdateParams {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentListParams extends V4PagePaginationArrayParams {
/**
* Path param: Account identifier.
*/
account_id: string;
}
export interface TargetEnvironmentDeleteParams {
/**
* Account identifier.
*/
account_id: string;
}
export interface TargetEnvironmentEditParams {
/**
* Path param: Account identifier.
*/
account_id: string;
/**
* Body param: Optional description. Omit to leave unchanged, set to `null` to
* clear, or provide a string to update.
*/
description?: string | null;
/**
* Body param: Human-readable name.
*/
name?: string;
/**
* Body param: Identifies the Cloudflare asset to scan. Uses a `type`
* discriminator. Currently the service supports only `zone` targets.
*/
target?: TargetEnvironmentEditParams.Target;
}
export namespace TargetEnvironmentEditParams {
/**
* Identifies the Cloudflare asset to scan. Uses a `type` discriminator. Currently
* the service supports only `zone` targets.
*/
export interface Target {
type: 'zone';
/**
* Cloudflare zone tag. The zone must belong to the account.
*/
zone_tag: string;
}
}
export interface TargetEnvironmentGetParams {
/**
* Account identifier.
*/
account_id: string;
}
export declare namespace TargetEnvironments {
export {
type TargetEnvironmentCreateResponse as TargetEnvironmentCreateResponse,
type TargetEnvironmentUpdateResponse as TargetEnvironmentUpdateResponse,
type TargetEnvironmentListResponse as TargetEnvironmentListResponse,
type TargetEnvironmentDeleteResponse as TargetEnvironmentDeleteResponse,
type TargetEnvironmentEditResponse as TargetEnvironmentEditResponse,
type TargetEnvironmentGetResponse as TargetEnvironmentGetResponse,
type TargetEnvironmentListResponsesV4PagePaginationArray as TargetEnvironmentListResponsesV4PagePaginationArray,
type TargetEnvironmentCreateParams as TargetEnvironmentCreateParams,
type TargetEnvironmentUpdateParams as TargetEnvironmentUpdateParams,
type TargetEnvironmentListParams as TargetEnvironmentListParams,
type TargetEnvironmentDeleteParams as TargetEnvironmentDeleteParams,
type TargetEnvironmentEditParams as TargetEnvironmentEditParams,
type TargetEnvironmentGetParams as TargetEnvironmentGetParams,
};
}