Beispiel #1
0
        public async Task <IActionResult> AddSettingAsync()
        {
            string jsonBody = "", zmodId = "";

            //read from body
            using (var reader = new StreamReader(Request.Body))
            {
                var body = await reader.ReadToEndAsync();

                jsonBody = body.ToString();
            }
            if (!string.IsNullOrEmpty(jsonBody))
            {
                if (XSSBlackList.CheckString(jsonBody))
                {
                    return(BadRequest(new { message = "Error: Unable to save settings. Invalid input. Please enter correct settings.", errorCode = 400 }));
                }
                zmodId = ZSSettingPayload.GetUserNameOrEmail(HttpContext);
                //parse
                JObject jObj    = JObject.Parse(jsonBody);
                JArray  jArr    = (JArray)jObj["settings"];
                var     setList = jArr.ToObject <List <SettingProperty> >();

                //fetch the original record
                List <SettingProperty> setListOrig = ZSSettingPayload.GetSettingsByUser(zmodId).SelectMany(b => b.Settings).ToList <SettingProperty>();
                foreach (var p in setList)
                {
                    if (p.username.Contains("******"))
                    {
                        p.username = setListOrig.Where(c => c.url == p.url).Select(c => c.username).FirstOrDefault().ToString();
                    }
                    if (p.password.Contains("******"))
                    {
                        p.password = setListOrig.Where(c => c.url == p.url).Select(c => c.password).FirstOrDefault().ToString();
                    }
                }

                //add to payload
                var newRecord = new ZSSettingResponse()
                {
                    ZmodId   = zmodId,
                    Settings = setList
                };
                ZSSettingPayload.CreateOrUpdate(newRecord);
                return(Json(JObject.Parse(jsonBody)));
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #2
0
        public static ZSSettingResponse CreateOrUpdate(ZSSettingResponse newRecord)
        {
            var existingSettings       = GetSettingsByUser(newRecord.ZmodId);
            ZSSettingResponse response = new ZSSettingResponse();

            if (existingSettings.Count > 0)
            {
                bool result = GlobalStorage.ZSSettingStorage.TryRemove(newRecord.ZmodId, out response);
                if (result)
                {
                    GlobalStorage.ZSSettingStorage.TryAdd(newRecord.ZmodId, newRecord);
                }
            }
            else
            {
                //add new
                GlobalStorage.ZSSettingStorage.TryAdd(newRecord.ZmodId, newRecord);
            }

            return(newRecord);
        }
Beispiel #3
0
        public async Task <IActionResult> GetSettingsAsync(string type, bool selected, bool unmask, bool showall)
        {
            //get the zmodId
            string UserEmailId = ZSSettingPayload.GetUserNameOrEmail(HttpContext);
            // string UserEmailId = "*****@*****.**";
            JObject jObj = new JObject();
            await Task.FromResult(0);

            var settings = ZSSettingPayload.GetSettingsByUser(UserEmailId);
            List <SettingProperty> settingProperties;

            if (string.IsNullOrEmpty(type))
            {
                settingProperties = settings.SelectMany(b => b.Settings).ToList <SettingProperty>();
            }
            else
            {
                settingProperties = settings.SelectMany(b => b.Settings).ToList <SettingProperty>();

                if (!string.IsNullOrEmpty(type) && (showall == true))
                {
                    settingProperties = settingProperties.Where(c => c.type == $"{type}").ToList <SettingProperty>();
                }
                else
                {
                    settingProperties = settingProperties.Where(c => c.type == $"{type}" && c.selected == selected).ToList <SettingProperty>();
                }
            }
            // var selectedType = settingProperties.Where(c=>c.type == $"{type}").ToList<SettingProperty>();
            //
            #region seed settings
            if (settings.Count == 0)
            {
                var template = new ZSSettingResponse
                {
                    ZmodId   = UserEmailId,
                    Settings = new List <SettingProperty> {
                        new SettingProperty {
                            name = "Cumulocity", type = "C8Y", tenantID = "ai", username = "******", password = "******", url = "https://ai.eu-latest.cumulocity.com", selected = true
                        },
                        new SettingProperty {
                            name = "Cumulocity", type = "C8Y", tenantID = "ai", username = "******", password = "******", url = "https://ai.cumulocity.com", selected = false
                        },
                        new SettingProperty {
                            name = "Predictive Analytics-PMML", type = "MLE-PMML", tenantID = "zserver", username = "******", password = "******", url = "https://ai.eu-latest.cumulocity.com/", selected = true
                        },
                        new SettingProperty {
                            name = "Repo Server 1", type = "NR", tenantID = "repo", username = "******", password = "******", url = "https://repo.umoya.ai/", selected = false
                        },
                        new SettingProperty {
                            name = "Repo Server 2", type = "NR", tenantID = "hub", username = "******", password = "******", url = "https://hub.umoya.ai/", selected = true
                        },
                        new SettingProperty {
                            name = "DataHub 1", type = "DH", driver = "Dremio", username = "******", password = "******", url = "https://url", port = "0000", selected = true, ssl = "1"
                        },
                        new SettingProperty {
                            name = "Predictive Analytics-ONNX", type = "MLE-ONNX", username = "******", password = "******", url = "https://your-tenent-id/", selected = true
                        }
                    }
                };
                jObj = JObject.Parse(JsonConvert.SerializeObject(template));
                ZSSettingPayload.CreateOrUpdate(template);
            }
            else
            {
                var template = new ZSSettingResponse
                {
                    ZmodId   = UserEmailId,
                    Settings = settingProperties
                };

                jObj = JObject.Parse(JsonConvert.SerializeObject(template));
            }

            #endregion

            jObj.Remove("zmodId");
            //
            foreach (var p in jObj["settings"])
            {
                if (unmask == false)
                {
                    p["username"] = "******";
                    p["password"] = "******";
                }

                if (p["type"].ToString() == "DH")
                {
                    p["tenantID"].Parent.Remove();
                }
                else
                {
                    p["port"].Parent.Remove();
                    p["driver"].Parent.Remove();
                }
                if (p["ssl"].ToString() == "")
                {
                    p["ssl"].Parent.Remove();
                }
            }
            //

            return(Json(jObj));
        }