NodeServiceHttpApiClient GetNodeClientInstance(string nodeRootUrl, Uri referrer, AuthenticationHeaderValue authHeader) { if (string.IsNullOrWhiteSpace(nodeRootUrl)) { nodeRootUrl = SynapseServer.Config.Controller.NodeUrl; } else { nodeRootUrl = $"{nodeRootUrl}/synapse/node"; } SynapseServer.Logger.Info($"nodeClient.Headers.Referrer: {referrer?.AbsoluteUri}"); NodeServiceHttpApiClient nodeClient = new NodeServiceHttpApiClient(nodeRootUrl); nodeClient.Headers.Referrer = referrer; if (authHeader != null) { if (SynapseServer.Config?.Node?.ControllerAuthenticationScheme != null) { if (SynapseServer.Config.Node.ControllerAuthenticationScheme == System.Net.AuthenticationSchemes.Basic) { nodeClient.Options.Authentication = new BasicAuthentication(authHeader); } } else if (authHeader.Scheme.ToLower() == "basic") { nodeClient.Options.Authentication = new BasicAuthentication(authHeader); } } return(nodeClient); }
public long StartPlan(string securityContext, string planUniqueName, bool dryRun = false, string requestNumber = null, Dictionary <string, string> dynamicParameters = null, bool postDynamicParameters = false, string nodeRootUrl = null, Uri referrer = null, AuthenticationHeaderValue authHeader = null) { _dal.HasAccessOrException(securityContext, planUniqueName); Plan plan = _dal.CreatePlanInstance(planUniqueName); plan.StartInfo = new PlanStartInfo() { RequestUser = securityContext, RequestNumber = requestNumber }; //record "New" status Plan initResultPlan = new Plan() { Name = plan.Name, UniqueName = plan.UniqueName, InstanceId = plan.InstanceId, StartInfo = plan.StartInfo, Result = new ExecuteResult() { Status = StatusType.New, BranchStatus = StatusType.New, Message = $"New Instance of Plan [{plan.UniqueName}/{plan.InstanceId}]." } }; _dal.UpdatePlanStatus(initResultPlan); //sign the plan if (SynapseServer.Config.Controller.SignPlan) { SynapseServer.Logger.Debug($"Signing Plan [{plan.Name}/{plan.InstanceId}]."); if (!File.Exists(SynapseServer.Config.Signature.KeyUri)) { throw new FileNotFoundException(SynapseServer.Config.Signature.KeyUri); } plan.Sign(SynapseServer.Config.Signature.KeyContainerName, SynapseServer.Config.Signature.KeyUri, SynapseServer.Config.Signature.CspProviderFlags); //plan.Name += "foo"; //testing: intentionally crash the sig } //send plan to Node to start the work NodeServiceHttpApiClient nodeClient = GetNodeClientInstance(nodeRootUrl, referrer, authHeader); nodeClient.StartPlan(plan, plan.InstanceId, dryRun, dynamicParameters, postDynamicParameters); return(plan.InstanceId); }