Exemplo n.º 1
0
        internal CloudFoundryClient InitClient()
        {
            this.CFServerUri = this.CFServerUri.Trim();
            this.CancelToken = new CancellationTokenSource();

            CloudFoundryClient client = new CloudFoundryClient(new Uri(this.CFServerUri), this.CancelToken.Token, null, this.CFSkipSslValidation);

            if (string.IsNullOrWhiteSpace(this.CFUser) == false && (string.IsNullOrWhiteSpace(this.CFPassword) == false || this.CFSavedPassword))
            {
                if (this.CFSkipSslValidation)
                {
                    System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
                }

                this.CFUser = this.CFUser.Trim();

                if (string.IsNullOrWhiteSpace(this.CFPassword))
                {
                    this.CFPassword = CloudCredentialsManager.GetPassword(new Uri(this.CFServerUri), this.CFUser);

                    if (string.IsNullOrWhiteSpace(this.CFPassword))
                    {
                        throw new AuthenticationException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      "Could not find a password for user '{0}' and target '{1}' in your local credentials store. Either make sure the entry exists in your credentials store, or provide CFPassword.",
                                      this.CFUser,
                                      this.CFServerUri));
                    }
                }

                this.CFPassword = this.CFPassword;

                CloudCredentials creds = new CloudCredentials();
                creds.User     = this.CFUser;
                creds.Password = this.CFPassword;
                var authContext = client.Login(creds).Result;
                if (this is LoginTask)
                {
                    if (authContext.Token != null)
                    {
                        ((LoginTask)this).CFRefreshToken = authContext.Token.RefreshToken;
                    }
                }
            }
            else if (string.IsNullOrWhiteSpace(this.CFRefreshToken) == false)
            {
                this.CFRefreshToken = this.CFRefreshToken.Trim();

                client.Login(this.CFRefreshToken).Wait();
            }
            else
            {
                throw new AuthenticationException("Could not authenticate client without refresh token or credentials.");
            }

            return(client);
        }
Exemplo n.º 2
0
        protected override async Task <IEnumerable <CloudItem> > UpdateChildren()
        {
            CloudFoundryClient client = new CloudFoundryClient(this.target.TargetUrl, this.CancellationToken, null, this.target.IgnoreSSLErrors);

            string password = CloudCredentialsManager.GetPassword(this.target.TargetUrl, this.target.Email);

            var authenticationContext = await client.Login(new CloudCredentials()
            {
                User     = this.target.Email,
                Password = password
            });

            List <Organization> result = new List <Organization>();

            PagedResponseCollection <ListAllOrganizationsResponse> orgs = await client.Organizations.ListAllOrganizations();

            while (orgs != null && orgs.Properties.TotalResults != 0)
            {
                foreach (var org in orgs)
                {
                    result.Add(new Organization(org, client));
                }

                orgs = await orgs.GetNextPage();
            }

            return(result);
        }
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            CreateOrganizationRequest org = new CreateOrganizationRequest();

            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;

            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();

            spc.Name             = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;

            spaceGuid = newSpace.EntityMetadata.Guid;

            stackGuid = client.Stacks.ListAllStacks().Result[0].EntityMetadata.Guid;
        }
Exemplo n.º 4
0
        public static void ClassInit(TestContext context)
        {
            Directory.CreateDirectory(tempAppPath);

            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while logging in" + ex.ToString());
            }

            PagedResponseCollection <ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            PagedResponseCollection <ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;

            foreach (ListAllAppsResponse app in apps)
            {
                if (app.Name.StartsWith("logTest"))
                {
                    client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait();
                    break;
                }
            }

            apprequest                 = new CreateAppRequest();
            apprequest.Name            = "logTest" + Guid.NewGuid().ToString();
            apprequest.Memory          = 64;
            apprequest.Instances       = 1;
            apprequest.SpaceGuid       = spaceGuid;
            apprequest.Buildpack       = "https://github.com/ryandotsmith/null-buildpack.git";
            apprequest.EnvironmentJson = new Dictionary <string, string>()
            {
                { "env-test-1234", "env-test-value-1234" }
            };
            apprequest.Command = "export; cat content.txt; sleep 5000;";

            client.Apps.PushProgress += Apps_PushProgress;

            File.WriteAllText(Path.Combine(tempAppPath, "content.txt"), "dummy content");
        }
Exemplo n.º 5
0
        private CloudFoundryClient SetTargetInfoFromFile()
        {
            if (!File.Exists(TOKEN_FILE))
            {
                throw new Exception("Token file not found. Please login first.");
            }

            string[] tokenFileInfo = File.ReadAllLines(TOKEN_FILE);

            this.api     = tokenFileInfo[0];
            this.token   = tokenFileInfo[1];
            this.skipSSL = Convert.ToBoolean(tokenFileInfo[2]);

            if (this.skipSSL)
            {
                new ConsoleString("Ignoring SSL errors.", ConsoleColor.Yellow).WriteLine();
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }

            new ConsoleString(string.Format("Logging in to target {0} ...", this.api), ConsoleColor.DarkCyan).WriteLine();

            CloudFoundryClient client = new CloudFoundryClient(new Uri(this.api), new System.Threading.CancellationToken());

            client.Login(this.token).Wait();

            new ConsoleString(string.Format("Logged in.", this.api), ConsoleColor.Green).WriteLine();

            return(client);
        }
Exemplo n.º 6
0
        public void Login(LoginArgs loginArgs)
        {
            if (loginArgs.SkipSSL)
            {
                new ConsoleString("Ignoring SSL errors.", ConsoleColor.Yellow).WriteLine();
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }

            CloudCredentials credentials = new CloudCredentials()
            {
                User     = loginArgs.User,
                Password = loginArgs.Password.ConvertToNonsecureString()
            };

            Console.WriteLine();

            if (!loginArgs.Api.ToLower().StartsWith("http") && !loginArgs.Api.ToLower().StartsWith("https"))
            {
                loginArgs.Api = "https://" + loginArgs.Api;
            }

            new ConsoleString(string.Format("Connecting to {0} ...", loginArgs.Api), ConsoleColor.DarkCyan).WriteLine();


            CloudFoundryClient client = new CloudFoundryClient(new Uri(loginArgs.Api), new System.Threading.CancellationToken());

            SaveTokenFile(
                loginArgs.Api,
                client.Login(credentials).Result,
                loginArgs.SkipSSL);
        }
Exemplo n.º 7
0
        public void ClientWithCertificateValidation_test()
        {
            var client      = new CloudFoundryClient(new Uri(TestUtil.ServerUrl), new CancellationToken(), null, false);
            var credentials = new CloudCredentials()
            {
                User = TestUtil.User, Password = TestUtil.Password
            };

            System.Net.ServicePointManager.ServerCertificateValidationCallback = null;

            bool   globalValidationInvoked = false;
            object lastSenderValidated     = null;

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
            {
                lastSenderValidated     = sender;
                globalValidationInvoked = true;
                return(true);
            };

            client.Login(credentials).Wait();

            var response = client.Stacks.ListAllStacks().Result;

            Assert.IsNotNull(response);

            Assert.IsNotNull(lastSenderValidated);
            Assert.IsTrue(globalValidationInvoked);
        }
        static void Main(string[] args)
        {
            {
                Console.WriteLine("Hello CF!");

                var cloudFoundryClient = new CloudFoundryClient(new Uri("https://api.system.cf.singel.home"), CancellationToken.None);

                cloudFoundryClient.Login("feken", "***").Wait();

                var createResponse = cloudFoundryClient.AppsExperimental.CreateApp("api-created-app", new Guid("ef1c944d-c7ec-4ceb-8177-317130a005da")).Result;

                var appResponse = cloudFoundryClient.AppsExperimental.GetApp(createResponse.guid).Result;


                cloudFoundryClient.AppsExperimental.PushProgress += AppsExperimental_PushProgress;

                cloudFoundryClient.AppsExperimental.Push(createResponse.guid.Value, @"C:\test\tozip\", null, null, true, 0, 0).Wait();

                //cloudFoundryClient.AppsExperimental.DeleteApp(appResponse.Guid.Value).Wait();

                var rep = cloudFoundryClient.AppsExperimental.GetApp(appResponse.guid.Value).Result;

                var fpa = cloudFoundryClient.AppsExperimental.ListAssociatedProcesses(appResponse.guid).Result;
            }
        }
Exemplo n.º 9
0
        public void TestInit()
        {
            client   = TestUtil.GetClient();
            v3client = TestUtil.GetV3Client();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while logging in" + ex.ToString());
            }

            try
            {
                v3client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while logging in" + ex.ToString());
            }

            PagedResponseCollection <ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            CCV3.PagedResponseCollection <CCV3.Data.ListAllAppsResponse> apps = v3client.AppsExperimental.ListAllApps().Result;

            foreach (CCV3.Data.ListAllAppsResponse app in apps)
            {
                if (app.Name.StartsWith("simplePushTest"))
                {
                    v3client.AppsExperimental.DeleteApp(app.Guid).Wait();
                    break;
                }
            }

            apprequest = new CCV3.Data.CreateAppRequest();
            Dictionary <string, object> s = new Dictionary <string, object>();

            s["guid"] = spaceGuid;
            apprequest.Relationships          = new Dictionary <string, dynamic>();
            apprequest.Relationships["space"] = s;
            client.Apps.PushProgress         += Apps_PushProgress;
        }
Exemplo n.º 10
0
        internal CloudFoundryClient InitClient()
        {
            CloudFoundryClient client = new CloudFoundryClient(new Uri(CFServerUri), new System.Threading.CancellationToken(), null, CFSkipSslValidation);

            if (string.IsNullOrWhiteSpace(CFUser) == false && (string.IsNullOrWhiteSpace(CFPassword) == false || CFSavedPassword))
            {
                if (string.IsNullOrWhiteSpace(CFPassword))
                {
                    this.CFPassword = CloudCredentialsManager.GetPassword(new Uri(this.CFServerUri), this.CFUser);

                    if (string.IsNullOrWhiteSpace(this.CFPassword))
                    {
                        throw new AuthenticationException(
                                  string.Format(CultureInfo.InvariantCulture,
                                                "Could not find a password for user '{0}' and target '{1}' in your local credentials store. Either make sure the entry exists in your credentials store, or provide CFPassword.",
                                                this.CFUser,
                                                this.CFServerUri));
                    }
                }

                CloudCredentials creds = new CloudCredentials();
                creds.User     = CFUser;
                creds.Password = CFPassword;
                var authContext = client.Login(creds).Result;
                if (this is LoginTask)
                {
                    if (authContext.Token != null)
                    {
                        ((LoginTask)this).CFRefreshToken = authContext.Token.RefreshToken;
                    }
                }
            }
            else if (string.IsNullOrWhiteSpace(CFRefreshToken) == false)
            {
                client.Login(CFRefreshToken).Wait();
            }
            else
            {
                throw new AuthenticationException("Could not authenticate client without refresh token or credentials.");
            }

            return(client);
        }
Exemplo n.º 11
0
        public void LoginWithInvlidCertificate_test()
        {
            var client      = new CloudFoundryClient(new Uri(TestUtil.ServerUrl), new CancellationToken(), null, false);
            var credentials = new CloudCredentials()
            {
                User = TestUtil.User, Password = TestUtil.Password
            };

            System.Net.ServicePointManager.ServerCertificateValidationCallback = null;

            client.Login(credentials).Wait();
        }
Exemplo n.º 12
0
        public void TestInit()
        {
            Directory.CreateDirectory(tempAppPath);

            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while logging in" + ex.ToString());
            }

            PagedResponseCollection <ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            PagedResponseCollection <ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;

            foreach (ListAllAppsResponse app in apps)
            {
                if (app.Name.StartsWith("uploadTest"))
                {
                    client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait();
                    break;
                }
            }

            apprequest           = new CreateAppRequest();
            apprequest.Name      = "uploadTest" + Guid.NewGuid().ToString();
            apprequest.SpaceGuid = spaceGuid;

            client.Apps.PushProgress += Apps_PushProgress;
        }
Exemplo n.º 13
0
        private async void BtnFinish_Click(object sender, RoutedEventArgs e)
        {
            this.InfoSpinner.Visibility = System.Windows.Visibility.Visible;
            this.InfoMessage.Text       = "Checking cloud connectivity...";
            var targetUrl = this.tbUrl.Text;

            var errorResource = this.DataContext as ErrorResource;

            if (errorResource == null)
            {
                throw new InvalidOperationException("Invalid DataContext");
            }

            try
            {
                var client = new CloudFoundryClient(new Uri(targetUrl), new CancellationToken(), null, (bool)cbIgnoreSSK.IsChecked);

                CloudCredentials creds = new CloudCredentials();
                creds.User     = this.tbUsername.Text;
                creds.Password = this.pbPassword.Password;

                var authContext = await client.Login(creds);

                var info = await client.Info.GetInfo();

                this.version = info.ApiVersion;

                this.cloudTarget = CloudTarget.CreateV2Target(
                    new Uri(this.tbUrl.Text),
                    this.tbDescription.Text,
                    this.tbUsername.Text,
                    (bool)this.cbIgnoreSSK.IsChecked,
                    this.version);

                this.credentials  = creds;
                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                this.InfoSpinner.Visibility = System.Windows.Visibility.Hidden;
                this.InfoMessage.Text       = string.Empty;
                var errorMessages = new List <string>();
                ErrorFormatter.FormatExceptionMessage(ex, errorMessages);
                errorResource.ErrorMessage = string.Join(Environment.NewLine, errorMessages.ToArray());
                errorResource.HasErrors    = true;
            }
        }
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }
        }
Exemplo n.º 15
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }
            CreateOrganizationRequest org = new CreateOrganizationRequest();

            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;

            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();

            spc.Name             = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;

            spaceGuid = newSpace.EntityMetadata.Guid;

            CreatesSharedDomainDeprecatedRequest r = new CreatesSharedDomainDeprecatedRequest();

            r.Name     = Guid.NewGuid().ToString() + ".com";
            r.Wildcard = true;
            domainGuid = client.DomainsDeprecated.CreatesSharedDomainDeprecated(r).Result.EntityMetadata.Guid;
        }
Exemplo n.º 16
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            PagedResponseCollection <ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result;

            Guid spaceGuid = Guid.Empty;

            foreach (ListAllSpacesResponse space in spaces)
            {
                spaceGuid = space.EntityMetadata.Guid;
                break;
            }

            if (spaceGuid == Guid.Empty)
            {
                throw new Exception("No spaces found");
            }

            PagedResponseCollection <ListAllStacksResponse> stacks = client.Stacks.ListAllStacks().Result;

            var winStack = Guid.Empty;

            foreach (ListAllStacksResponse stack in stacks)
            {
                if (stack.Name == "win2012r2" || stack.Name == "win2012")
                {
                    winStack = stack.EntityMetadata.Guid;
                    break;
                }
            }

            if (winStack == Guid.Empty)
            {
                throw new Exception("Could not test on a deployment without a windows 2012 stack");
            }

            PagedResponseCollection <ListAllAppsResponse> apps = client.Apps.ListAllApps().Result;

            foreach (ListAllAppsResponse app in apps)
            {
                if (app.Name == "simplePushTest")
                {
                    client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait();
                    break;
                }
            }

            apprequest           = new CreateAppRequest();
            apprequest.Name      = "simplePushTest";
            apprequest.Memory    = 512;
            apprequest.Instances = 1;
            apprequest.SpaceGuid = spaceGuid;
            apprequest.StackGuid = winStack;

            client.Apps.PushProgress += Apps_PushProgress;
        }