Ejemplo n.º 1
0
        public long StartPlan(string planUniqueName, bool dryRun = false, string requestNumber = null, string nodeRootUrl = null)
        {
            InitPlanServer();

            if (!string.IsNullOrWhiteSpace(requestNumber))
            {
                requestNumber = System.Web.HttpUtility.UrlDecode(requestNumber);
            }
            if (!string.IsNullOrWhiteSpace(nodeRootUrl))
            {
                requestNumber = System.Web.HttpUtility.UrlDecode(nodeRootUrl);
            }

            Uri    uri     = CurrentUrl.Request.RequestUri;
            string context = GetContext(nameof(StartPlan), nameof(CurrentUserName), CurrentUserName,
                                        nameof(planUniqueName), planUniqueName, nameof(dryRun), dryRun,
                                        nameof(requestNumber), requestNumber, nameof(nodeRootUrl), nodeRootUrl, "QueryString", uri.Query);

            Impersonator runAsUser = null;

            if (SynapseServer.UseImpersonation(CurrentUser?.Identity))
            {
                if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic")
                {
                    runAsUser = new Impersonator(this.AuthenticationHeader);
                }
                else
                {
                    runAsUser = new Impersonator((WindowsIdentity)(CurrentUser?.Identity));
                }
                runAsUser.Start(SynapseServer.Logger);
            }

            try
            {
                SynapseServer.Logger.Debug(context);

                Dictionary <string, string> dynamicParameters = uri.ParseQueryString();
                if (dynamicParameters.ContainsKey(nameof(dryRun)))
                {
                    dynamicParameters.Remove(nameof(dryRun));
                }

                return(_server.StartPlan(CurrentUserName, planUniqueName, dryRun, requestNumber, dynamicParameters, nodeRootUrl: nodeRootUrl,
                                         referrer: CurrentUrl.Request.RequestUri, authHeader: this.AuthenticationHeader));
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
            finally
            {
                runAsUser?.Stop(SynapseServer.Logger);
            }
        }
Ejemplo n.º 2
0
        public void StartPlanAsync(long planInstanceId, bool dryRun, [FromBody] string planString)
        {
            Uri uri = this.Url.Request.RequestUri;

            planString = CryptoHelpers.Decode(planString);
            Plan plan = Plan.FromYaml(new StringReader(planString));

            string context = GetContext(nameof(StartPlanAsync),
                                        nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId, "QueryString", uri.Query);

            Impersonator runAsUser = null;

            if (SynapseServer.UseImpersonation(User?.Identity))
            {
                if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic")
                {
                    runAsUser = new Impersonator(Request.Headers.Authorization);
                }
                else
                {
                    runAsUser = new Impersonator((WindowsIdentity)User.Identity);
                }
                runAsUser.Start(SynapseServer.Logger);
            }

            try
            {
                SynapseServer.Logger.Debug(context);
                plan.InstanceId = planInstanceId;

                ValidatePlanSignature(plan);

                Dictionary <string, string> dynamicParameters = uri.ParseQueryString();
                if (dynamicParameters.ContainsKey(nameof(dryRun)))
                {
                    dynamicParameters.Remove(nameof(dryRun));
                }
                PlanRuntimePod p = new PlanRuntimePod(plan, dryRun, dynamicParameters, plan.InstanceId, this.Url.Request.Headers.Referrer, this.Request?.Headers?.Authorization);
                _scheduler.StartPlan(p);
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
            finally
            {
                runAsUser?.Stop(SynapseServer.Logger);
            }
        }
Ejemplo n.º 3
0
        public void StartPlanAsyncWithParametersAsPost(long planInstanceId, bool dryRun, [FromBody] string planString)
        {
            StartPlanEnvelope planEnvelope = StartPlanEnvelope.FromYaml(planString, isEncoded: true);
            Plan plan = planEnvelope.Plan;

            string context = GetContext(nameof(StartPlanAsyncWithParametersAsPost),
                                        nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId);

            Impersonator runAsUser = null;

            try
            {
                SynapseServer.Logger.Debug(context);
                plan.InstanceId = planInstanceId;

                ValidatePlanSignature(plan);

                if (SynapseServer.UseImpersonation(User?.Identity))
                {
                    if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic")
                    {
                        runAsUser = new Impersonator(Request.Headers.Authorization);
                    }
                    else
                    {
                        runAsUser = new Impersonator((WindowsIdentity)User.Identity);
                    }
                    runAsUser.Start(SynapseServer.Logger);
                }

                PlanRuntimePod p = new PlanRuntimePod(plan, dryRun, planEnvelope.GetCaseInsensitiveDynamicParameters(), plan.InstanceId, this.Url.Request.Headers.Referrer, this.Request?.Headers?.Authorization);
                _scheduler.StartPlan(p);
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
            finally
            {
                runAsUser?.Stop(SynapseServer.Logger);
            }
        }
Ejemplo n.º 4
0
        public long StartPlan([FromBody] StartPlanEnvelope planEnvelope, string planUniqueName, bool dryRun = false, string requestNumber = null, string nodeRootUrl = null)
        {
            InitPlanServer();

            if (!string.IsNullOrWhiteSpace(requestNumber))
            {
                requestNumber = System.Web.HttpUtility.UrlDecode(requestNumber);
            }
            if (!string.IsNullOrWhiteSpace(nodeRootUrl))
            {
                requestNumber = System.Web.HttpUtility.UrlDecode(nodeRootUrl);
            }


            TryGetPlanEnvelopeFromRawBodyIfNull(ref planEnvelope);

            bool failedToDeserialize = false;
            Dictionary <string, string> dynamicParameters = planEnvelope?.TryGetCaseInsensitiveDynamicParameters();
            StringBuilder parms = new StringBuilder();

            if (dynamicParameters != null)
            {
                string s = string.Empty;
                foreach (string key in dynamicParameters.Keys)
                {
                    parms.Append($"{s}{key}: {dynamicParameters[key]}");
                    s = ", ";
                }
            }
            else
            {
                failedToDeserialize = !string.IsNullOrWhiteSpace(RawBody);
                if (failedToDeserialize)
                {
                    parms.Append(RawBody);
                }
            }

            string context = GetContext(nameof(StartPlan), nameof(CurrentUserName), CurrentUserName,
                                        nameof(planUniqueName), planUniqueName, nameof(dryRun), dryRun,
                                        nameof(requestNumber), requestNumber, nameof(nodeRootUrl), nodeRootUrl, "planParameters", parms.ToString());

            Impersonator runAsUser = null;

            if (SynapseServer.UseImpersonation(CurrentUser?.Identity))
            {
                if (Request?.Headers?.Authorization?.Scheme?.ToLower() == "basic")
                {
                    runAsUser = new Impersonator(this.AuthenticationHeader);
                }
                else
                {
                    runAsUser = new Impersonator((WindowsIdentity)(CurrentUser?.Identity));
                }
                runAsUser.Start(SynapseServer.Logger);
            }

            try
            {
                SynapseServer.Logger.Info(context);

                if (failedToDeserialize)
                {
                    throw new Exception($"Failed to deserialize message body:\r\n{parms.ToString()}");
                }

                return(_server.StartPlan(CurrentUserName, planUniqueName, dryRun, requestNumber, dynamicParameters,
                                         postDynamicParameters: true, nodeRootUrl: nodeRootUrl, referrer: CurrentUrl.Request.RequestUri, authHeader: this.AuthenticationHeader));
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
            finally
            {
                runAsUser?.Stop(SynapseServer.Logger);
            }
        }