CoreService

<back to all web services

CreateCollection

Collection - CRUD

Creates a new collection

Requires Authentication
Required role:TenantReader
The following routes are available for this service:
POST/api/collections/Creates a new collection
POST/collections/Creates a new collection
import datetime
import decimal
from marshmallow.fields import *
from servicestack import *
from typing import *
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, LetterCase, Undefined, config
from enum import Enum, IntEnum
Object = TypeVar('Object')


class ObjectTypes(str, Enum):
    NONE = 'None'
    CONFIG_ITEM = 'ConfigItem'
    TENANT = 'Tenant'
    COLLECTION = 'Collection'
    RESOURCE = 'Resource'
    COMPUTE_NODE = 'ComputeNode'
    VIRTUAL_MACHINE = 'VirtualMachine'
    PHYSICAL_MACHINE = 'PhysicalMachine'
    DISK = 'Disk'
    SUBNET = 'Subnet'
    IP_ADDRESS = 'IPAddress'
    JOB = 'Job'
    JOB_EVENT = 'JobEvent'
    FREEZE_PERIOD = 'FreezePeriod'
    RESOURCE_GROUP = 'ResourceGroup'
    DEPLOYMENT = 'Deployment'
    RESOURCE_GROUP_TEMPLATE = 'ResourceGroupTemplate'
    DEPLOYMENT_TEMPLATE = 'DeploymentTemplate'
    RESOURCE_PROVIDER = 'ResourceProvider'
    GENERIC_RESOURCE = 'GenericResource'
    ROLE = 'Role'
    PERMISSION = 'Permission'
    USER = 'User'
    PATCHING_WINDOW = 'PatchingWindow'
    UPDATE = 'Update'
    REPORT_DEFINITION = 'ReportDefinition'
    TIME_SERIES = 'TimeSeries'
    DATA_POINT = 'DataPoint'
    ACTION = 'Action'
    ACTION_ASSIGNMENT = 'ActionAssignment'
    USER_NOTE = 'UserNote'


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class TagDto:
    name: Optional[str] = None
    value: Optional[str] = None
    is_protected: bool = False


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class PathItemDto:
    label: Optional[str] = None
    link: Optional[str] = None
    object_type: Optional[ObjectTypes] = None
    object_id: Optional[str] = None


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class LinkDto:
    caption: Optional[str] = None
    rel: Optional[str] = None
    h_ref: Optional[str] = None
    method: Optional[str] = None


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class ConfigItemDto(IConfigItem):
    id: Optional[str] = None
    name: Optional[str] = None
    display_name: Optional[str] = None
    description: Optional[str] = None
    object_type: Optional[ObjectTypes] = None
    self_link: Optional[str] = None
    tags: Optional[IList[TagDto]] = None
    path: Optional[IList[PathItemDto]] = None
    created: datetime.datetime = datetime.datetime(1, 1, 1)
    create_user: Optional[str] = None
    create_user_id: Optional[str] = None
    modified: datetime.datetime = datetime.datetime(1, 1, 1)
    modify_user: Optional[str] = None
    modify_user_id: Optional[str] = None
    is_deleted: bool = False
    deleted: Optional[datetime.datetime] = None
    delete_user: Optional[str] = None
    delete_user_id: Optional[str] = None
    links: Optional[IList[LinkDto]] = None


class ValueDataType(str, Enum):
    STRING = 'String'
    NUMBER = 'Number'
    BOOLEAN = 'Boolean'
    LIST = 'List'


class Environments(str, Enum):
    LAB = 'Lab'
    POC = 'Poc'
    DEV = 'Dev'
    TEST = 'Test'
    INT_ = 'Int'
    UAT = 'Uat'
    PROD = 'Prod'


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class VariableDto:
    name: Optional[str] = None
    value: Optional[str] = None
    """
    Value in form of a json string (e.g. Number = 1234, String = "foo", Boolean = false, List = [1,2,3,4]). Note: string values need extra quotes
    """

    type: Optional[ValueDataType] = None
    """
    The data type of the value property
    """

    description: Optional[str] = None
    is_inherited: bool = False
    environment: Optional[Environments] = None


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class TenantDto(ConfigItemDto):
    variables: Optional[IList[VariableDto]] = None
    """
    Variables defined on tenant level
    """

    allowed_mail_domains: Optional[IList[str]] = None
    """
    Allowed email domains used for authentication
    """

    licensed_modules: Optional[IList[str]] = None
    """
    List of licensed modules for this tenant
    """

    default_deployment_lifetime_days: int = 0
    """
    Amount of days until a Deployment expires
    """

    max_deployment_lifetime_days: int = 0
    """
    Max amount of days until a Deployment expires
    """

    system_unpatched_warning_days: int = 0
    """
    Amount of days without patching until a unpatched warning is shown
    """

    system_backup_missing_warning_hours: int = 0
    """
    Amount of hours without backup until a backup missing warning is shown
    """

    stop_vulnerable_resource_after_days: int = 0
    """
    Amount of days until a vulnerable resource is getting stopped
    """

    deployment_expiration_warning_days: int = 0
    """
    Amount of days before deployment expiration, which triggers the expiration warning
    """

    patch_notification_days: int = 0
    """
    Amount of days the patch notification is sent out prior to the patch date
    """

    use_custom_hostnames: bool = False
    """
    Use a pool with your own hostnames (true) or let the hostname be auto generated (false)
    """

    remove_inactive_vulnerabilities_after_days: int = 0
    """
    After how many days inactive vulnerabilities will be purged from database
    """

    links: Optional[IList[LinkDto]] = None


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class DeploymentCollectionDto(ConfigItemDto, IHasTenantId):
    tenant_id: Optional[str] = None
    tenant: Optional[TenantDto] = None
    variables: Optional[IList[VariableDto]] = None
    """
    A collection scoped list of variables
    """

    is_lost_and_found: bool = False
    """
    Defines the collection where scanned but not deployed resources will be stored
    """

    monthly_budget: Optional[Decimal] = None
    """
    The monthly cost budget for the whole collection
    """

    send_budget_notification_mails: Optional[bool] = None
    """
    Whether to send budget information mails to the collection owners
    """

    budget_warning_threshold_percent: Optional[int] = None
    """
    A threshold, when to send the first budget warning mail
    """

    links: Optional[IList[LinkDto]] = None


# @Api(Description="Creates a new collection")
# @ApiResponse(Description="Success", IsDefaultResponse=true, ResponseType=typeof(DeploymentCollectionDto), StatusCode=201)
@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@dataclass
class CreateCollection(ICreateRequest, IHasTenantName, IPost):
    """
    Creates a new collection
    """

    # @ApiMember(DataType="string", IsRequired=true, ParameterType="header")
    # @Validate(Validator="NotEmpty")
    tenant_name: Optional[str] = None

    # @ApiMember(DataType="string", Description="The collections name", IsRequired=true, ParameterType="body")
    # @Validate(Validator="NotEmpty")
    # @Validate(Validator="MaximumLength(50)")
    # @Validate(Validator="RegularExpression(′^[0-9a-z]+[0-9a-z-]*[0-9a-z]+$′)")
    name: Optional[str] = None
    """
    The collections name
    """


    # @ApiMember(DataType="string", Description="The collections display name", ParameterType="body")
    # @Validate(Validator="MaximumLength(250)")
    display_name: Optional[str] = None
    """
    The collections display name
    """


    # @ApiMember(DataType="string", Description="A more detailed description for the collection", ParameterType="body")
    # @Validate(Validator="MaximumLength(8000)")
    description: Optional[str] = None
    """
    A more detailed description for the collection
    """


    # @ApiMember(DataType="bool", Description="Defines the collections where scanned but not deployed resources will be stored")
    is_lost_and_found: Optional[bool] = None
    """
    Defines the collections where scanned but not deployed resources will be stored
    """


    # @ApiMember(DataType="array", ParameterType="body")
    variables: Optional[IList[VariableDto]] = None

    # @ApiMember(DataType="array", ParameterType="body")
    tags: Optional[IList[TagDto]] = None

Python CreateCollection DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /api/collections/ HTTP/1.1 
Host: core.starburst.svc 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"tenantName":"String","name":"String","displayName":"String","description":"String","isLostAndFound":false,"variables":null,"tags":null,"txId":"00000000-0000-0000-0000-000000000000"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"tenantId":"00000000-0000-0000-0000-000000000000","tenant":{"variables":null,"allowedMailDomains":null,"licensedModules":null,"defaultDeploymentLifetimeDays":0,"maxDeploymentLifetimeDays":0,"systemUnpatchedWarningDays":0,"systemBackupMissingWarningHours":0,"stopVulnerableResourceAfterDays":0,"deploymentExpirationWarningDays":0,"patchNotificationDays":0,"useCustomHostnames":false,"removeInactiveVulnerabilitiesAfterDays":0,"links":[{"caption":"Collections","rel":"down","hRef":"/collections/","method":"GET"}],"id":"00000000-0000-0000-0000-000000000000","name":"String","displayName":"String","description":"String","objectType":"None","selfLink":"String","tags":null,"path":null,"created":"0001-01-01T00:00:00.0000000Z","createUser":"String","createUserId":"String","modified":"0001-01-01T00:00:00.0000000Z","modifyUser":"String","modifyUserId":"String","isDeleted":false,"deleted":"0001-01-01T00:00:00.0000000Z","deleteUser":"String","deleteUserId":"String"},"variables":null,"isLostAndFound":false,"monthlyBudget":0,"sendBudgetNotificationMails":false,"budgetWarningThresholdPercent":0,"links":[{"caption":"Index","rel":"up","hRef":"/collections/","method":"GET"},{"caption":"Deployments","rel":"down","hRef":"/deployments?parentId=00000000-0000-0000-0000-000000000000","method":"GET"}],"id":"00000000-0000-0000-0000-000000000000","name":"String","displayName":"String","description":"String","objectType":"None","selfLink":"String","tags":null,"path":null,"created":"0001-01-01T00:00:00.0000000Z","createUser":"String","createUserId":"String","modified":"0001-01-01T00:00:00.0000000Z","modifyUser":"String","modifyUserId":"String","isDeleted":false,"deleted":"0001-01-01T00:00:00.0000000Z","deleteUser":"String","deleteUserId":"String"}