CoreService

<back to all web services

CreateAction

Action - CRUD

Create a new action

Requires Authentication
Required role:TenantReader
The following routes are available for this service:
POST/api/actions/Create a new action
POST/actions/Create a new action
import 'package:servicestack/servicestack.dart';

enum ObjectTypes
{
    None,
    ConfigItem,
    Tenant,
    Collection,
    Resource,
    ComputeNode,
    VirtualMachine,
    PhysicalMachine,
    Disk,
    Subnet,
    IPAddress,
    Job,
    JobEvent,
    FreezePeriod,
    ResourceGroup,
    Deployment,
    ResourceGroupTemplate,
    DeploymentTemplate,
    ResourceProvider,
    GenericResource,
    Role,
    Permission,
    User,
    PatchingWindow,
    Update,
    ReportDefinition,
    TimeSeries,
    DataPoint,
    Action,
    ActionAssignment,
    UserNote,
}

class TagDto implements IConvertible
{
    String name = "";
    String? value;
    bool isProtected;

    TagDto({this.name,this.value,this.isProtected});
    TagDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        name = json['name'];
        value = json['value'];
        isProtected = json['isProtected'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'name': name,
        'value': value,
        'isProtected': isProtected
    };

    getTypeName() => "TagDto";
    TypeContext? context = _ctx;
}

class PathItemDto implements IConvertible
{
    String label = "";
    String link = "";
    ObjectTypes objectType;
    String objectId = "";

    PathItemDto({this.label,this.link,this.objectType,this.objectId});
    PathItemDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        label = json['label'];
        link = json['link'];
        objectType = JsonConverters.fromJson(json['objectType'],'ObjectTypes',context!);
        objectId = json['objectId'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'label': label,
        'link': link,
        'objectType': JsonConverters.toJson(objectType,'ObjectTypes',context!),
        'objectId': objectId
    };

    getTypeName() => "PathItemDto";
    TypeContext? context = _ctx;
}

class LinkDto implements IConvertible
{
    String caption = "";
    String rel = "";
    String hRef = "";
    String method = "";

    LinkDto({this.caption,this.rel,this.hRef,this.method});
    LinkDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        caption = json['caption'];
        rel = json['rel'];
        hRef = json['hRef'];
        method = json['method'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'caption': caption,
        'rel': rel,
        'hRef': hRef,
        'method': method
    };

    getTypeName() => "LinkDto";
    TypeContext? context = _ctx;
}

class ConfigItemDto implements IConfigItem, IConvertible
{
    String id = "";
    String name = "";
    String displayName = "";
    String? description;
    ObjectTypes objectType;
    String selfLink = "";
    List<TagDto>? tags;
    List<PathItemDto>? path;
    DateTime created = DateTime(0);
    String createUser = "";
    String createUserId = "";
    DateTime modified = DateTime(0);
    String modifyUser = "";
    String modifyUserId = "";
    bool isDeleted;
    DateTime? deleted;
    String? deleteUser;
    String? deleteUserId;
    List<LinkDto>? links;

    ConfigItemDto({this.id,this.name,this.displayName,this.description,this.objectType,this.selfLink,this.tags,this.path,this.created,this.createUser,this.createUserId,this.modified,this.modifyUser,this.modifyUserId,this.isDeleted,this.deleted,this.deleteUser,this.deleteUserId,this.links});
    ConfigItemDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        id = json['id'];
        name = json['name'];
        displayName = json['displayName'];
        description = json['description'];
        objectType = JsonConverters.fromJson(json['objectType'],'ObjectTypes',context!);
        selfLink = json['selfLink'];
        tags = JsonConverters.fromJson(json['tags'],'List<TagDto>',context!);
        path = JsonConverters.fromJson(json['path'],'List<PathItemDto>',context!);
        created = JsonConverters.fromJson(json['created'],'DateTime',context!);
        createUser = json['createUser'];
        createUserId = json['createUserId'];
        modified = JsonConverters.fromJson(json['modified'],'DateTime',context!);
        modifyUser = json['modifyUser'];
        modifyUserId = json['modifyUserId'];
        isDeleted = json['isDeleted'];
        deleted = JsonConverters.fromJson(json['deleted'],'DateTime',context!);
        deleteUser = json['deleteUser'];
        deleteUserId = json['deleteUserId'];
        links = JsonConverters.fromJson(json['links'],'List<LinkDto>',context!);
        return this;
    }

    Map<String, dynamic> toJson() => {
        'id': id,
        'name': name,
        'displayName': displayName,
        'description': description,
        'objectType': JsonConverters.toJson(objectType,'ObjectTypes',context!),
        'selfLink': selfLink,
        'tags': JsonConverters.toJson(tags,'List<TagDto>',context!),
        'path': JsonConverters.toJson(path,'List<PathItemDto>',context!),
        'created': JsonConverters.toJson(created,'DateTime',context!),
        'createUser': createUser,
        'createUserId': createUserId,
        'modified': JsonConverters.toJson(modified,'DateTime',context!),
        'modifyUser': modifyUser,
        'modifyUserId': modifyUserId,
        'isDeleted': isDeleted,
        'deleted': JsonConverters.toJson(deleted,'DateTime',context!),
        'deleteUser': deleteUser,
        'deleteUserId': deleteUserId,
        'links': JsonConverters.toJson(links,'List<LinkDto>',context!)
    };

    getTypeName() => "ConfigItemDto";
    TypeContext? context = _ctx;
}

enum ParameterValueType
{
    String,
    Number,
    Boolean,
    SecureString,
}

class ParameterDto implements IConvertible
{
    String name = "";
    String? description;
    /**
    * Value in form of a json string (e.g. Number = 1234, String = "foo", Boolean = false). Note: string values need extra quotes
    */
    String? value;
    /**
    * Optional default value for the frontend. Needs to be in the same format as the value
    */
    String? Default;
    /**
    * Optional parameters do not need to have a value. Default -> Optional=false
    */
    bool optional;
    /**
    * The data type of the value and default property
    */
    ParameterValueType type;
    String? validation;

    ParameterDto({this.name,this.description,this.value,this.Default,this.optional,this.type,this.validation});
    ParameterDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        name = json['name'];
        description = json['description'];
        value = json['value'];
        Default = json['default'];
        optional = json['optional'];
        type = JsonConverters.fromJson(json['type'],'ParameterValueType',context!);
        validation = json['validation'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'name': name,
        'description': description,
        'value': value,
        'default': Default,
        'optional': optional,
        'type': JsonConverters.toJson(type,'ParameterValueType',context!),
        'validation': validation
    };

    getTypeName() => "ParameterDto";
    TypeContext? context = _ctx;
}

enum ActionScopes
{
    Deployment,
    ResourceGroup,
    Resource,
}

class ActionStepDto implements IConvertible
{
    String name = "";
    String? displayName;
    /**
    * The variables which are used in the ansible job
    */
    Map<String,dynamic?> variables = {};
    /**
    * Optional credential to be used in awx (credential stored in awx)
    */
    String? credential;
    /**
    * Ansible limit (optional if Scope is Resource)
    */
    String? limit;
    /**
    * Optional type of the awx action to run (job, workflow, etc.)
    */
    String? type;
    /**
    * Optional ansible module to be used
    */
    String? module;
    /**
    * Optional image for the execution environment which runs the action
    */
    String? executionEnvironment;
    /**
    * Optional inventory
    */
    String? inventory;

    ActionStepDto({this.name,this.displayName,this.variables,this.credential,this.limit,this.type,this.module,this.executionEnvironment,this.inventory});
    ActionStepDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        name = json['name'];
        displayName = json['displayName'];
        variables = JsonConverters.fromJson(json['variables'],'Map<String,dynamic?>',context!);
        credential = json['credential'];
        limit = json['limit'];
        type = json['type'];
        module = json['module'];
        executionEnvironment = json['executionEnvironment'];
        inventory = json['inventory'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'name': name,
        'displayName': displayName,
        'variables': JsonConverters.toJson(variables,'Map<String,dynamic?>',context!),
        'credential': credential,
        'limit': limit,
        'type': type,
        'module': module,
        'executionEnvironment': executionEnvironment,
        'inventory': inventory
    };

    getTypeName() => "ActionStepDto";
    TypeContext? context = _ctx;
}

class ActionDto extends ConfigItemDto implements IHasTenantId, IConvertible
{
    String tenantId = "";
    /**
    * The schema version of the attached definition (json/yaml structure)
    */
    int schemaVersion = 0;
    /**
    * The action definition as json/yaml
    */
    String? definition;
    /**
    * Action parameters
    */
    List<ParameterDto>? parameters;
    /**
    * Disabled actions cannot be assigned to a configitem
    */
    bool isDisabled;
    /**
    * This action can anly be assigned to configitems of this type
    */
    ActionScopes scope;
    /**
    * The individual steps of the action
    */
    List<ActionStepDto> steps = [];

    ActionDto({this.tenantId,this.schemaVersion,this.definition,this.parameters,this.isDisabled,this.scope,this.steps});
    ActionDto.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        super.fromMap(json);
        tenantId = json['tenantId'];
        schemaVersion = json['schemaVersion'];
        definition = json['definition'];
        parameters = JsonConverters.fromJson(json['parameters'],'List<ParameterDto>',context!);
        isDisabled = json['isDisabled'];
        scope = JsonConverters.fromJson(json['scope'],'ActionScopes',context!);
        steps = JsonConverters.fromJson(json['steps'],'List<ActionStepDto>',context!);
        return this;
    }

    Map<String, dynamic> toJson() => super.toJson()..addAll({
        'tenantId': tenantId,
        'schemaVersion': schemaVersion,
        'definition': definition,
        'parameters': JsonConverters.toJson(parameters,'List<ParameterDto>',context!),
        'isDisabled': isDisabled,
        'scope': JsonConverters.toJson(scope,'ActionScopes',context!),
        'steps': JsonConverters.toJson(steps,'List<ActionStepDto>',context!)
    });

    getTypeName() => "ActionDto";
    TypeContext? context = _ctx;
}

/**
* Create a new action
*/
// @Api(Description="Create a new action")
// @ApiResponse(Description="Success", IsDefaultResponse=true, ResponseType=typeof(ActionDto), StatusCode=201)
class CreateAction implements IBaseRequest, IHasTenantName, IPost, IConvertible
{
    // @ApiMember(DataType="string", IsRequired=true, ParameterType="header")
    // @Validate(Validator="NotEmpty")
    String tenantName = "";

    /**
    * The version of the action structure
    */
    // @ApiMember(DataType="integer", Description="The version of the action structure", IsRequired=true, ParameterType="body")
    // @Validate(Validator="GreaterThan(0)")
    int schemaVersion = 0;

    /**
    * The definition of the action (YAML)
    */
    // @ApiMember(DataType="string", Description="The definition of the action (YAML)", Format="yaml", IsRequired=true, ParameterType="body")
    // @Validate(Validator="NotEmpty")
    String definition = "";

    CreateAction({this.tenantName,this.schemaVersion,this.definition});
    CreateAction.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        tenantName = json['tenantName'];
        schemaVersion = json['schemaVersion'];
        definition = json['definition'];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'tenantName': tenantName,
        'schemaVersion': schemaVersion,
        'definition': definition
    };

    getTypeName() => "CreateAction";
    TypeContext? context = _ctx;
}

TypeContext _ctx = TypeContext(library: 'duneframework.com', types: <String, TypeInfo> {
    'ObjectTypes': TypeInfo(TypeOf.Enum, enumValues:ObjectTypes.values),
    'TagDto': TypeInfo(TypeOf.Class, create:() => TagDto()),
    'PathItemDto': TypeInfo(TypeOf.Class, create:() => PathItemDto()),
    'LinkDto': TypeInfo(TypeOf.Class, create:() => LinkDto()),
    'ConfigItemDto': TypeInfo(TypeOf.Class, create:() => ConfigItemDto()),
    'List<TagDto>': TypeInfo(TypeOf.Class, create:() => <TagDto>[]),
    'List<PathItemDto>': TypeInfo(TypeOf.Class, create:() => <PathItemDto>[]),
    'List<LinkDto>': TypeInfo(TypeOf.Class, create:() => <LinkDto>[]),
    'ParameterValueType': TypeInfo(TypeOf.Enum, enumValues:ParameterValueType.values),
    'ParameterDto': TypeInfo(TypeOf.Class, create:() => ParameterDto()),
    'ActionScopes': TypeInfo(TypeOf.Enum, enumValues:ActionScopes.values),
    'ActionStepDto': TypeInfo(TypeOf.Class, create:() => ActionStepDto()),
    'Map<String,dynamic?>': TypeInfo(TypeOf.Class, create:() => Map<String,dynamic?>()),
    'ActionDto': TypeInfo(TypeOf.Class, create:() => ActionDto()),
    'List<ParameterDto>': TypeInfo(TypeOf.Class, create:() => <ParameterDto>[]),
    'List<ActionStepDto>': TypeInfo(TypeOf.Class, create:() => <ActionStepDto>[]),
    'CreateAction': TypeInfo(TypeOf.Class, create:() => CreateAction()),
});

Dart CreateAction 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/actions/ HTTP/1.1 
Host: core.starburst.svc 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"tenantName":"String","schemaVersion":0,"definition":"String","txId":"00000000-0000-0000-0000-000000000000"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"tenantId":"00000000-0000-0000-0000-000000000000","schemaVersion":0,"definition":"String","parameters":null,"isDisabled":false,"scope":"Deployment","steps":[{"name":"String","displayName":"String","variables":{"String":{}},"credential":"String","limit":"String","type":"String","module":"String","executionEnvironment":"String","inventory":"String"}],"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","links":null}