package dto import ( "time" "browser.local/platform/domain" ) type ServerDeploymentRequest struct { RunEndpointID string `json:"runEndpointId,omitempty"` Mode domain.ServerDeploymentMode `json:"mode"` ProfileKey string `json:"profileKey,omitempty"` RuntimeBindings map[string]string `json:"runtimeBindings,omitempty"` CreateInputs map[string]string `json:"createInputs,omitempty"` ServerRoot string `json:"serverRoot,omitempty"` WorkingDirectory string `json:"workingDirectory,omitempty"` InstallCommand string `json:"installCommand,omitempty"` StartCommand string `json:"startCommand,omitempty"` StopCommand string `json:"stopCommand,omitempty"` StatusCommand string `json:"statusCommand,omitempty"` Shell domain.ServerCommandShell `json:"shell,omitempty"` } type ServerDeploymentResponse struct { ServerInstanceID string `json:"serverInstanceId"` Mode domain.ServerDeploymentMode `json:"mode,omitempty"` ProfileKey string `json:"profileKey,omitempty"` CreateInputs map[string]string `json:"createInputs,omitempty"` ServerRootConfigured bool `json:"serverRootConfigured"` WorkingDirectoryConfigured bool `json:"workingDirectoryConfigured"` InstallCommandConfigured bool `json:"installCommandConfigured"` StartCommandConfigured bool `json:"startCommandConfigured"` StopCommandConfigured bool `json:"stopCommandConfigured"` StatusCommandConfigured bool `json:"statusCommandConfigured"` Shell domain.ServerCommandShell `json:"shell,omitempty"` Revision int `json:"revision"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` Projection ServerDeploymentProjectionBody `json:"projection,omitempty"` } type ServerDeploymentProjectionBody struct { State string `json:"state,omitempty"` Operation string `json:"operation,omitempty"` TemplateKey string `json:"templateKey,omitempty"` TemplateVersion string `json:"templateVersion,omitempty"` PreflightState string `json:"preflightState,omitempty"` DiscoveryState string `json:"discoveryState,omitempty"` MappingState string `json:"mappingState,omitempty"` VerificationState string `json:"verificationState,omitempty"` DiscoveredFacts map[string]string `json:"discoveredFacts,omitempty"` MappingResults map[string]string `json:"mappingResults,omitempty"` VerificationResults map[string]string `json:"verificationResults,omitempty"` FailureCode string `json:"failureCode,omitempty"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` } type ServerLifecycleCreateRequest struct { ID string `json:"id"` PluginID string `json:"pluginId"` DeploymentTargetID string `json:"deploymentTargetId,omitempty"` RunEndpointID string `json:"runEndpointId"` Name string `json:"name"` OwnerUserID string `json:"ownerUserId,omitempty"` IdempotencyKey string `json:"idempotencyKey"` ProfileKey string `json:"profileKey"` Bindings map[string]string `json:"bindings,omitempty"` Deployment ServerDeploymentRequest `json:"deployment,omitempty"` } type ServerLifecycleCommandRequest struct { ExpectedConfigVersion int `json:"expectedConfigVersion"` IdempotencyKey string `json:"idempotencyKey"` } type ServerLifecycleResponse struct { Accepted bool `json:"accepted"` Action domain.ServerLifecycleAction `json:"action"` Instance ServerInstanceResponse `json:"instance"` Job JobResponse `json:"job"` } func (request ServerLifecycleCreateRequest) ToDomain() domain.ServerLifecycleCreate { return domain.ServerLifecycleCreate{ ID: request.ID, PluginID: request.PluginID, DeploymentTargetID: request.DeploymentTargetID, RunEndpointID: request.RunEndpointID, Name: request.Name, OwnerUserID: request.OwnerUserID, IdempotencyKey: request.IdempotencyKey, ProfileKey: request.ProfileKey, Bindings: domain.CopyStringMap(request.Bindings), Deployment: request.Deployment.deploymentDefinition(), } } func (request ServerDeploymentRequest) ToDomain() domain.ServerDeploymentUpdate { return domain.ServerDeploymentUpdate{RunEndpointID: request.RunEndpointID, Mode: request.Mode, ProfileKey: request.ProfileKey, RuntimeBindings: domain.CopyStringMap(request.RuntimeBindings), CreateInputs: domain.CopyStringMap(request.CreateInputs), ServerRoot: request.ServerRoot, WorkingDirectory: request.WorkingDirectory, InstallCommand: request.InstallCommand, StartCommand: request.StartCommand, StopCommand: request.StopCommand, StatusCommand: request.StatusCommand, Shell: request.Shell} } func (request ServerDeploymentRequest) deploymentDefinition() domain.ServerDeploymentDefinition { update := request.ToDomain() return domain.ServerDeploymentDefinition{Mode: update.Mode, ProfileKey: update.ProfileKey, RuntimeBindings: update.RuntimeBindings, CreateInputs: update.CreateInputs, ServerRoot: update.ServerRoot, WorkingDirectory: update.WorkingDirectory, InstallCommand: update.InstallCommand, StartCommand: update.StartCommand, StopCommand: update.StopCommand, StatusCommand: update.StatusCommand, Shell: update.Shell} } func ServerDeploymentFromDomain(view domain.ServerDeploymentView) ServerDeploymentResponse { return ServerDeploymentResponse{ServerInstanceID: view.ServerInstanceID, Mode: view.Mode, ProfileKey: view.ProfileKey, CreateInputs: domain.CopyStringMap(view.CreateInputs), ServerRootConfigured: view.ServerRootConfigured, WorkingDirectoryConfigured: view.WorkingDirectoryConfigured, InstallCommandConfigured: view.InstallCommandConfigured, StartCommandConfigured: view.StartCommandConfigured, StopCommandConfigured: view.StopCommandConfigured, StatusCommandConfigured: view.StatusCommandConfigured, Shell: view.Shell, Revision: view.Revision, UpdatedAt: optionalTime(view.UpdatedAt), Projection: deploymentProjectionFromDomain(view.Projection)} } func deploymentProjectionFromDomain(projection domain.ServerDeploymentProjection) ServerDeploymentProjectionBody { return ServerDeploymentProjectionBody{State: projection.State, Operation: projection.Operation, TemplateKey: projection.TemplateKey, TemplateVersion: projection.TemplateVersion, PreflightState: projection.PreflightState, DiscoveryState: projection.DiscoveryState, MappingState: projection.MappingState, VerificationState: projection.VerificationState, DiscoveredFacts: domain.CopyStringMap(projection.DiscoveredFacts), MappingResults: domain.CopyStringMap(projection.MappingResults), VerificationResults: domain.CopyStringMap(projection.VerificationResults), FailureCode: projection.FailureCode, UpdatedAt: optionalTime(projection.UpdatedAt)} } func (request ServerLifecycleCommandRequest) ToDomain(serverInstanceID string) domain.ServerLifecycleCommand { return domain.ServerLifecycleCommand{ ServerInstanceID: serverInstanceID, ExpectedConfigVersion: request.ExpectedConfigVersion, IdempotencyKey: request.IdempotencyKey, } } func ServerLifecycleFromDomain(result domain.ServerLifecycleResult) ServerLifecycleResponse { result = domain.CopyServerLifecycleResult(result) return ServerLifecycleResponse{ Accepted: result.Accepted, Action: result.Action, Instance: ServerInstanceFromDomain(result.Instance), Job: JobFromDomain(result.Job), } }