Example #1
0
        public async Task <IActionResult> GetServiceConfigurationAsync([FromBody] ExecutionRequestApiModel execRequestApiModel)
        {
            // Validate the execution request API model...

            var errors = execRequestApiModel.ValidateApiModel().ToList();

            // If we ran into any validation errors, respond with [400 Bad Request] + detailed error description...

            if (errors.Any())
            {
                return(BadRequest($"[{errors.Count}] errors occurred while attempting to process your request: {string.Join(' ', errors)}"));
            }

            // Get any service context(s) from the execution service provider...

            var execRequest       = execRequestApiModel.ToCoreModel();
            var execServiceConfig = await execServiceProvider.GetServiceConfigurationAsync(execRequest);

            if (execServiceConfig == null)
            {
                // If there are no available services, respond with [204 No Content]...

                return(NoContent());
            }
            else
            {
                // If there are available services, respond with [200 OK] + service context(s) for execution...

                return(Ok(execServiceConfig));
            }
        }
Example #2
0
        private async Task <DirectExecutionRequestApiModel> CreateDirectExecutionRequestAsync(IExecutionRequestContext erContext)
        {
            // Convert the API request context to a core execution request...

            var execRequest = ToExecutionRequestAsync(erContext);

            // Then, convert the core execution request into a direct execution token...

            var directExecRequest = new DirectExecutionRequestApiModel
            {
                ExecutionId           = execRequest.ExecutionId,
                ExecutionModelName    = execRequest.ExecutionModelName,
                ExecutionProfileName  = execRequest.ExecutionProfileName,
                ExecutionSettings     = execRequest.ExtensionSettings,
                ExtensionId           = execRequest.ExtensionId,
                ExtensionVersionId    = execRequest.ExtensionVersionId,
                GetExecutionStatusUrl = execRequest.GetExecutionStatusUrl,
                ObjectProviderName    = execRequest.ObjectProviderName,
                ExecutorProperties    = execRequest.ExecutorProperties,
                Services = await execServiceProvider.GetServiceConfigurationAsync(execRequest)
            };

            // Based on the selected execution profile, set the expiration date/time (how long the client can use the extension directly for)
            // and digitally sign the execution request using the hub's private key. In this model, we assume that the target execution has the hub's
            // public key and can us it to verify the authenticity of the token and all the information contained therein.
            // For more information, see /doc/architecture/direct-execution.md.

            directExecRequest.ExpirationDateTimeUtc = DateTime.UtcNow.Add(erContext.ExecutionProfile.DirectExecutionTokenDuration.Value);
            directExecRequest.Signature             = await directExecRequestSigner.GenerateSignatureAsync(execRequest.SignatureRsaKeyXml, directExecRequest);

            // Update the execution to indicate that a direct access token is being provided...

            erContext.Execution.ExecutionTimeoutDateTimeUtc = directExecRequest.ExpirationDateTimeUtc;
            erContext.Execution.Status = ExecutionStatus.DirectExecutionTokenProvided;
            erContext.Execution.LastUpdatedDateTimeUtc = DateTime.UtcNow;

            // Persist the execution and return the direct execution token...

            await UpdateExecutionAsync(erContext.Execution);

            return(directExecRequest);
        }
 private async Task <HttpExecutionRequest> ToHttpExecutionRequestAsync(ExecutionRequest execRequest) => new HttpExecutionRequest
 {
     CreatedDateTimeUtc       = execRequest.CreatedDateTimeUtc,
     ExecutionId              = execRequest.ExecutionId,
     Executor                 = execRequest.Executor,
     ExtensionId              = execRequest.ExtensionId,
     ExtensionVersionId       = execRequest.ExtensionVersionId,
     GetExecutionStatusUrl    = execRequest.GetExecutionStatusUrl,
     LastUpdatedDateTimeUtc   = execRequest.LastUpdatedDateTimeUtc,
     Priority                 = execRequest.Priority,
     StatusUpdateKey          = execRequest.StatusUpdateKey,
     UpdateExecutionStatusUrl = execRequest.UpdateExecutionStatusUrl,
     ExpirationDateTimeUtc    = execRequest.ExecutionTimeoutDateTimeUtc,
     Services                 = await execServiceProvider.GetServiceConfigurationAsync(execRequest),
     InputObjects             = await CreateInputObjectAccessorDictionaryAsync(execRequest),
     OutputObjects            = await CreateOutputObjectAccessorDictionaryAsync(execRequest),
     ExecutionProfileName     = execRequest.ExecutionProfileName,
     RequestParameters        = execRequest.ExecutionParameters,
     ExecutorProperties       = execRequest.ExecutorProperties
 };