CoreService

<back to all web services

CreateActionAssignment

Action - CRUD

Adds an action to a config item

Requires Authentication
Required role:TenantReader
The following routes are available for this service:
POST/api/action-assignmentsAssigns an action to a config item
POST/action-assignmentsAssigns an action to a config item
import Foundation
import ServiceStack

/**
* Adds an action to a config item
*/
// @Api(Description="Adds an action to a config item")
// @ApiResponse(Description="Success", IsDefaultResponse=true, ResponseType=typeof(ActionAssignmentDto), StatusCode=201)
public class CreateActionAssignment : IPost, ISchedulableRequest, Codable
{
    // @ApiMember(DataType="string", IsRequired=true, ParameterType="header")
    // @Validate(Validator="NotEmpty")
    public var tenantName:String

    /**
    * The unique id of the config item
    */
    // @ApiMember(DataType="string", Description="The unique id of the config item", Format="guid", IsRequired=true, ParameterType="path")
    public var configItemId:String

    /**
    * The type of the config item (either Deployment, ResourceGroup or Resource)
    */
    // @ApiMember(Description="The type of the config item (either Deployment, ResourceGroup or Resource)", IsRequired=true, ParameterType="body")
    // @Validate(Validator="NotNull")
    public var configItemType:ObjectTypes

    // @ApiMember(DataType="string", Format="guid", IsRequired=true, ParameterType="path")
    public var actionId:String

    /**
    * A unique name for the action
    */
    // @ApiMember(DataType="string", Description="A unique name for the action", IsRequired=true, ParameterType="body")
    // @Validate(Validator="NotEmpty")
    public var name:String

    // @ApiMember(DataType="array", ParameterType="body")
    public var parameters:[ParameterDto] = []

    /**
    * The cron expression for scheduling the operation
    */
    // @ApiMember(DataType="string", Description="The cron expression for scheduling the operation", Format="Cron", ParameterType="body")
    public var cronExpression:String

    /**
    * Inform users when the job has finished
    */
    // @ApiMember(DataType="bool", Description="Inform users when the job has finished", ParameterType="body")
    public var sendNotifications:Bool?

    required public init(){}
}

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

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

    required public init(){}
}

public enum ParameterValueType : String, Codable
{
    case String
    case Number
    case Boolean
    case SecureString
}

public class ActionAssignmentDto : Codable
{
    public var id:String
    public var name:String
    public var actionId:String
    public var action:ActionDto
    public var configItemId:String
    public var configItemName:String
    public var configItemType:ObjectTypes
    public var parameters:[ParameterDto] = []
    public var selfLink:String
    public var scope:ActionScopes
    public var cronExpression:String
    public var links:IList<LinkDto>
    public var scheduledTaskAssignmentId:String?
    public var scheduledTaskAssignment:ScheduledTaskAssignmentDto
    public var objectType:ObjectTypes

    required public init(){}
}

public class ActionDto : ConfigItemDto, IHasTenantId
{
    public var tenantId:String
    /**
    * The schema version of the attached definition (json/yaml structure)
    */
    public var schemaVersion:Int
    /**
    * The action definition as json/yaml
    */
    public var definition:String
    /**
    * Action parameters
    */
    public var parameters:IList<ParameterDto>
    /**
    * Disabled actions cannot be assigned to a configitem
    */
    public var isDisabled:Bool
    /**
    * This action can anly be assigned to configitems of this type
    */
    public var scope:ActionScopes
    /**
    * The individual steps of the action
    */
    public var steps:[ActionStepDto] = []

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case tenantId
        case schemaVersion
        case definition
        case parameters
        case isDisabled
        case scope
        case steps
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        tenantId = try container.decodeIfPresent(String.self, forKey: .tenantId)
        schemaVersion = try container.decodeIfPresent(Int.self, forKey: .schemaVersion)
        definition = try container.decodeIfPresent(String.self, forKey: .definition)
        parameters = try container.decodeIfPresent(IList<ParameterDto>.self, forKey: .parameters)
        isDisabled = try container.decodeIfPresent(Bool.self, forKey: .isDisabled)
        scope = try container.decodeIfPresent(ActionScopes.self, forKey: .scope)
        steps = try container.decodeIfPresent([ActionStepDto].self, forKey: .steps) ?? []
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if tenantId != nil { try container.encode(tenantId, forKey: .tenantId) }
        if schemaVersion != nil { try container.encode(schemaVersion, forKey: .schemaVersion) }
        if definition != nil { try container.encode(definition, forKey: .definition) }
        if parameters != nil { try container.encode(parameters, forKey: .parameters) }
        if isDisabled != nil { try container.encode(isDisabled, forKey: .isDisabled) }
        if scope != nil { try container.encode(scope, forKey: .scope) }
        if steps.count > 0 { try container.encode(steps, forKey: .steps) }
    }
}

public class ConfigItemDto : IConfigItem, Codable
{
    public var id:String
    public var name:String
    public var displayName:String
    public var Description:String
    public var objectType:ObjectTypes
    public var selfLink:String
    public var tags:IList<TagDto>
    public var path:IList<PathItemDto>
    public var created:Date
    public var createUser:String
    public var createUserId:String
    public var modified:Date
    public var modifyUser:String
    public var modifyUserId:String
    public var isDeleted:Bool
    public var deleted:Date?
    public var deleteUser:String
    public var deleteUserId:String
    public var links:IList<LinkDto>

    required public init(){}
}

public class TagDto : Codable
{
    public var name:String
    public var value:String
    public var isProtected:Bool

    required public init(){}
}

public class PathItemDto : Codable
{
    public var label:String
    public var link:String
    public var objectType:ObjectTypes
    public var objectId:String

    required public init(){}
}

public class LinkDto : Codable
{
    public var caption:String
    public var rel:String
    public var hRef:String
    public var method:String

    required public init(){}
}

public enum ActionScopes : String, Codable
{
    case Deployment
    case ResourceGroup
    case Resource
}

public class ActionStepDto : Codable
{
    public var name:String
    public var displayName:String
    /**
    * The variables which are used in the ansible job
    */
    public var variables:[String:String] = [:]
    /**
    * Optional credential to be used in awx (credential stored in awx)
    */
    public var credential:String
    /**
    * Ansible limit (optional if Scope is Resource)
    */
    public var limit:String
    /**
    * Optional type of the awx action to run (job, workflow, etc.)
    */
    public var type:String
    /**
    * Optional ansible module to be used
    */
    public var module:String
    /**
    * Optional image for the execution environment which runs the action
    */
    public var executionEnvironment:String
    /**
    * Optional inventory
    */
    public var inventory:String

    required public init(){}
}

public class ScheduledTaskAssignmentDto : Codable
{
    public var id:String
    public var configItemId:String
    public var objectType:ObjectTypes
    public var displayName:String
    public var taskId:Int
    public var taskName:String
    public var cronExpression:String

    required public init(){}
}


Swift CreateActionAssignment 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/action-assignments HTTP/1.1 
Host: core.starburst.svc 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"tenantName":"String","configItemId":"00000000-0000-0000-0000-000000000000","configItemType":"None","actionId":"00000000-0000-0000-0000-000000000000","name":"String","parameters":[{"name":"String","description":"String","value":"String","default":"String","optional":false,"type":"String","validation":"String"}],"cronExpression":"String","sendNotifications":false,"txId":"00000000-0000-0000-0000-000000000000"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"id":"00000000-0000-0000-0000-000000000000","name":"String","actionId":"00000000-0000-0000-0000-000000000000","action":{"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},"configItemId":"00000000-0000-0000-0000-000000000000","configItemName":"String","configItemType":"None","parameters":[{"name":"String","description":"String","value":"String","default":"String","optional":false,"type":"String","validation":"String"}],"selfLink":"String","scope":"Deployment","cronExpression":"String","links":[{"caption":"Start","rel":"start","hRef":"/action-assignments/00000000-0000-0000-0000-000000000000/start","method":"POST"},{"caption":"Completed","rel":"completed","hRef":"/action-assignments/00000000-0000-0000-0000-000000000000/completed","method":"PATCH"}],"scheduledTaskAssignmentId":"00000000-0000-0000-0000-000000000000","scheduledTaskAssignment":{"id":"00000000-0000-0000-0000-000000000000","configItemId":"00000000-0000-0000-0000-000000000000","objectType":"None","displayName":"String","taskId":0,"taskName":"String","cronExpression":"String"},"objectType":"ActionAssignment"}