Пример #1
0
        private static string ProcessRecordAsync(string Token, string netid, MalwareSetting mal)
        {
            var task = UpdateMalwareSettings(Token, netid, mal);

            task.Wait();
            var result = task.Result;

            return(result);
        }
Пример #2
0
        // This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
        protected override void ProcessRecord()
        {
            MalwareSetting mal     = new MalwareSetting();
            AllowedUrl     addurl  = new AllowedUrl();
            AllowedFile    addfile = new AllowedFile();

            addurl.url      = url;
            addurl.comment  = urlComment;
            addfile.sha256  = fileSha256;
            addfile.comment = fileComment;
            mal.allowedUrls.Add(addurl);
            mal.allowedFiles.Add(addfile);

            WriteVerbose("Entering Get Orgs call");
            var list = ProcessRecordAsync(Token, netid, mal);

            MalwareSetting result = JsonSerializer.Deserialize <MalwareSetting>(list);

            WriteObject(result, true);

            WriteVerbose("Exiting foreach");
        }
Пример #3
0
        private static async Task <string> UpdateMalwareSettings(string Token, string netid, MalwareSetting mal)
        {
            using (HttpClient client = new HttpClient())
            {
                string jsonString;
                string uri;
                uri        = $"https://dashboard.meraki.com/api/v0/networks/{netid}/security/malwareSettings";
                jsonString = JsonSerializer.Serialize <MalwareSetting>(mal);

                var content = new StringContent(jsonString);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
                client.DefaultRequestHeaders.Add("X-Cisco-Meraki-API-Key", Token);

                var response = await client.PutAsync(uri, content);

                var contents = await response.Content.ReadAsStringAsync();

                return(contents);
            }
        }