Пример #1
0
        private static void Main(string[] args)
        {
            dynamic config = LoadConfiguration("secrets.json");
            dynamic aws    = config.aws;
            dynamic DO     = config.DO;
            dynamic azure  = config.azure;
            dynamic gcp    = config.gcp;

            ICredential awsCred   = new AWSCredential(aws.id.ToString(), aws.key.ToString(), aws.region.ToString());
            ICredential doCred    = new DigitalOceanCredential(DO.id.ToString(), DO.key.ToString(), DO.region.ToString());
            ICredential azureCred = new AzureCredential(azure.id.ToString(), azure.key.ToString());
            ICredential gcpCred   = new GCPCredential(gcp.id.ToString(), JsonConvert.SerializeObject(gcp.secret));

            Factory fac = new Factory(awsCred, doCred, azureCred, gcpCred);

            AsyncMain(args, fac).GetAwaiter().GetResult();
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSecurity();

            string tenantid     = "4346f2c6-6ec4-491d-9a3d-c4b3877e616b";
            string key          = "UPMUIU+kEA7Sc4UwuwcgrEM0iu1bISjRrlsdLvgCSM4=";
            string client       = "b8060a58-e98b-4e58-ba11-22269a084e2c";
            string subscription = "ffecf118-fbde-455a-ad01-8ad9541a9827";

            var credential = new AzureCredential()
            {
                ClientId       = client,
                TenantId       = tenantid,
                Key            = key,
                SubscriptionId = subscription
            };

            var azure = new DefaultAzureManager(credential);

            if (azure.Connected)
            {
                litOutput.Text = string.Format("{0}<br>{1}<hr>", litOutput.Text, "Azure Connected");
            }

            foreach (var resourceGroup in azure.GetResourceGroups())
            {
                litOutput.Text += string.Format("<h2>{0}</h2>", resourceGroup.Name);

                litOutput.Text += "<h3>App Services</h3><ul>";
                foreach (var webApp in azure.GetAppServicePlans(resourceGroup.Name))
                {
                    litOutput.Text += string.Format("<li>{0}: {1}</li>", webApp.Name, webApp.PricingTier);
                }
                litOutput.Text += string.Format("</ul>");

                //litOutput.Text += "<h3>Web Apps</h3><ul>";
                //foreach (var webApp in azure.GetWebApps(resourceGroup.Name))
                //{
                //    litOutput.Text += string.Format("<li>{0}: {1}</li>", webApp.Name, webApp.State);

                //}
                //litOutput.Text += string.Format("</ul>");
            }
        }
Пример #3
0
        public static IBucketClient CreateClient(CloudServiceProvider service, ICredential credential)
        {
            HttpClient httpClient = new HttpClient();

            switch (service)
            {
            case CloudServiceProvider.AWS:
                if (!(credential is AWSCredential))
                {
                    throw new ArgumentException("AWS needs AWSCredential!");
                }
                AWSCredential aws = credential as AWSCredential;
                return(new AWSBucketClient(httpClient, aws.accessKeyID, aws.accessKeySecret, aws.region));

            case CloudServiceProvider.Azure:
                if (!(credential is AzureCredential))
                {
                    throw new ArgumentException("Azure needs AzureCredential!");
                }
                AzureCredential azure = credential as AzureCredential;
                return(new AzureBucketClient(azure.AccountName, azure.Secret));

            case CloudServiceProvider.GCP:
                if (!(credential is GCPCredential))
                {
                    throw new ArgumentException("Google Cloud Platform needs GCPCredential!");
                }
                GCPCredential gcp = credential as GCPCredential;
                return(new GCPBucketClient(gcp.projectID, gcp.secretJSON));

            case CloudServiceProvider.DigitalOcean:
                if (!(credential is DigitalOceanCredential))
                {
                    throw new ArgumentException("Digital Ocean needs DigitalOceanCredential!");
                }
                DigitalOceanCredential DO = credential as DigitalOceanCredential;
                return(new DigitalOceanBucketClient(httpClient, DO.accessKeyID, DO.accessKeySecret, DO.region));

            case CloudServiceProvider.AliCloud:
                throw new NotImplementedException();
            }
            return(null);
        }