public void SetContext_AppliesHostAssignmentContext() { var context = new HostAssignmentContext { Environment = new Dictionary <string, string>(), SiteName = "TestSite", Secrets = _secrets }; string json = JsonConvert.SerializeObject(context); string encrypted = SimpleWebTokenHelper.Encrypt(json, environment: _environment); var encryptedContext = new EncryptedHostAssignmentContext { EncryptedContext = encrypted }; var result = _startupContextProvider.SetContext(encryptedContext); Assert.Equal(context.SiteName, result.SiteName); Assert.Equal(_secrets.Host.Master, result.Secrets.Host.Master); var secrets = _startupContextProvider.GetHostSecretsOrNull(); Assert.Equal(_secrets.Host.Master, secrets.MasterKey); Assert.Equal(_secrets.Host.Function, secrets.FunctionKeys); Assert.Equal(_secrets.Host.System, secrets.SystemKeys); }
private async Task ApplyStartContextIfPresent() { var startContext = await GetStartContextOrNullAsync(); if (!string.IsNullOrEmpty(startContext)) { _logger.LogInformation("Applying host context"); var encryptedAssignmentContext = JsonConvert.DeserializeObject <EncryptedHostAssignmentContext>(startContext); var assignmentContext = _startupContextProvider.SetContext(encryptedAssignmentContext); var msiError = await _instanceManager.SpecializeMSISidecar(assignmentContext); if (!string.IsNullOrEmpty(msiError)) { // Log and continue specializing even in case of failures. // There will be other mechanisms to recover the container. _logger.LogError("MSI Specialization failed with '{msiError}'", msiError); } bool success = _instanceManager.StartAssignment(assignmentContext); _logger.LogInformation($"StartAssignment invoked (Success={success})"); } else { _logger.LogInformation("No host context specified. Waiting for host assignment"); } }
public async Task <IActionResult> Assign([FromBody] EncryptedHostAssignmentContext encryptedAssignmentContext) { _logger.LogDebug($"Starting container assignment for host : {Request?.Host}. ContextLength is: {encryptedAssignmentContext.EncryptedContext?.Length}"); var assignmentContext = _startupContextProvider.SetContext(encryptedAssignmentContext); // before starting the assignment we want to perform as much // up front validation on the context as possible string error = await _instanceManager.ValidateContext(assignmentContext); if (error != null) { return(StatusCode(StatusCodes.Status400BadRequest, error)); } // Wait for Sidecar specialization to complete before returning ok. // This shouldn't take too long so ok to do this sequentially. error = await _instanceManager.SpecializeMSISidecar(assignmentContext); if (error != null) { return(StatusCode(StatusCodes.Status500InternalServerError, error)); } var succeeded = _instanceManager.StartAssignment(assignmentContext); return(succeeded ? Accepted() : StatusCode(StatusCodes.Status409Conflict, "Instance already assigned")); }
public async Task <IActionResult> Assign([FromBody] EncryptedHostAssignmentContext encryptedAssignmentContext) { _logger.LogDebug($"Starting container assignment for host : {Request?.Host}"); var assignmentContext = _startupContextProvider.SetContext(encryptedAssignmentContext); string error = await _instanceManager.ValidateContext(assignmentContext); if (error != null) { return(StatusCode(StatusCodes.Status400BadRequest, error)); } var succeeded = _instanceManager.StartAssignment(assignmentContext); return(succeeded ? Accepted() : StatusCode(StatusCodes.Status409Conflict, "Instance already assigned")); }
private async Task ApplyStartContextIfPresent() { var startContext = await GetStartContextOrNullAsync(); if (!string.IsNullOrEmpty(startContext)) { _logger.LogInformation("Applying host context"); var encryptedAssignmentContext = JsonConvert.DeserializeObject <EncryptedHostAssignmentContext>(startContext); var assignmentContext = _startupContextProvider.SetContext(encryptedAssignmentContext); bool success = _instanceManager.StartAssignment(assignmentContext); _logger.LogInformation($"StartAssignment invoked (Success={success})"); } else { _logger.LogInformation("No host context specified. Waiting for host assignment"); } }