Пример #1
0
        public void ProbeAseManagement_NoChange()
        {
            var aseName = "testase";
            var mockGetManagementIps = new Mock <IGetManagementIps>();
            var mockPersist          = new Mock <IPersist>();
            var mockNotify           = new Mock <INotify>();
            // setup AseApi Object
            var record = new AseApiRecord()
            {
                description = "App Service management",
                endpoints   = new List <string>()
            };

            record.endpoints.Add("70.37.57.58/32");
            record.endpoints.Add("157.55.208.185/32");
            record.endpoints.Add("23.102.188.65/32");
            mockGetManagementIps.Setup(m => m.GetManagementIps(aseName)).Returns(record);
            mockPersist.Setup(m => m.Get(aseName)).Returns(record);
            mockPersist.Setup(m => m.Save(aseName, record));
            mockNotify.Setup(m => m.Notify(record));
            var agent   = new AseAgent(mockGetManagementIps.Object, mockPersist.Object, mockNotify.Object);
            var missing = agent.ProbeAseManagement(aseName);

            mockGetManagementIps.Verify(v => v.GetManagementIps(aseName));
            mockPersist.Verify(v => v.Get(aseName));
            Assert.IsTrue(missing.Count == 0);
            mockNotify.VerifyNoOtherCalls();
            mockPersist.VerifyNoOtherCalls();
        }
Пример #2
0
        public void ProbeAseManagement_FirstTime()
        {
            var aseName = "testase";
            var mockGetManagementIps = new Mock <IGetManagementIps>();
            var mockPersist          = new Mock <IPersist>();
            var mockNotify           = new Mock <INotify>();
            // setup added 2 IPs
            var record2 = new AseApiRecord()
            {
                description = "App Service management",
                endpoints   = new List <string>()
            };

            record2.endpoints.Add("70.37.57.58/32");
            record2.endpoints.Add("157.55.208.185/32");
            record2.endpoints.Add("23.102.188.65/32");
            record2.endpoints.Add("191.236.154.88/32");
            record2.endpoints.Add("52.174.22.21/32");
            mockPersist.Setup(m => m.Get(aseName)).Returns(null as AseApiRecord);
            mockPersist.Setup(m => m.Save(aseName, record2));
            mockNotify.Setup(m => m.Notify(record2));
            mockGetManagementIps.Setup(m => m.GetManagementIps(aseName)).Returns(record2);
            var agent   = new AseAgent(mockGetManagementIps.Object, mockPersist.Object, mockNotify.Object);
            var missing = agent.ProbeAseManagement(aseName);

            mockGetManagementIps.Verify(v => v.GetManagementIps(aseName));
            mockPersist.Verify(v => v.Get(aseName));
            Assert.IsTrue(missing.Count == 5);
            mockNotify.Verify(v => v.Notify(record2));
            mockPersist.Verify(v => v.Save(aseName, record2));
        }
Пример #3
0
        public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            // get config values
            string subscriptionId       = ConfigurationManager.AppSettings["subscriptionId"];
            string rgName               = ConfigurationManager.AppSettings["rgname"];
            string aseName              = ConfigurationManager.AppSettings["asename"];
            string tenantId             = ConfigurationManager.AppSettings["tenantId"];
            string appid                = ConfigurationManager.AppSettings["appid"];
            string appKey               = ConfigurationManager.AppSettings["appKey"];
            string accountName          = ConfigurationManager.AppSettings["accountName"];
            string storageKey           = ConfigurationManager.AppSettings["storageKey"];
            string containerName        = ConfigurationManager.AppSettings["containerName"];
            string automationWebhookUrl = ConfigurationManager.AppSettings["automationwebhookurl"];
            // Az management API provider
            var azmgmt = new AzureManagementProvider(subscriptionId, rgName, tenantId, appid, appKey);
            // Blob Storage paersistence
            var bpp = new BlobPersistProvider(new StorageCredentials(accountName, storageKey), containerName);
            // Azure Automation webhook notifier
            var webhook = new WebhookNotify(automationWebhookUrl);
            // probe ASE Management
            var agent  = new AseAgent(azmgmt, bpp, webhook);
            var result = agent.ProbeAseManagement(aseName);

            // if there are changes log it
            if (result.Count > 0)
            {
                foreach (string newip in result)
                {
                    log.Info("New ASE Mangement IP " + newip + DateTime.Now.ToString());
                }
            }
            else
            {
                log.Info($"No change ASE Mangement IPs at {DateTime.Now}");
            }
        }