/// <summary> /// Initializes a new instance of the SubscriptionClient class. /// </summary> /// <param name='credentials'> /// Required. Credentials used to authenticate requests. /// </param> public SubscriptionClient(CloudCredentials credentials) : this() { if (credentials == null) { throw new ArgumentNullException("credentials"); } this._credentials = credentials; this._baseUri = new Uri("https://management.core.windows.net"); this.Credentials.InitializeServiceClient(this); }
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)) { 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); }
/// <summary> /// Initializes a new instance of the SubscriptionClient class. /// </summary> /// <param name='credentials'> /// Required. Credentials used to authenticate requests. /// </param> /// <param name='httpClient'> /// The Http client /// </param> public SubscriptionClient(CloudCredentials credentials, HttpClient httpClient) : this(httpClient) { if (credentials == null) { throw new ArgumentNullException("credentials"); } this._credentials = credentials; this._baseUri = new Uri("https://management.azure.com/"); this.Credentials.InitializeServiceClient(this); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // get your app ID and token on: // https://cloud.estimote.com/#/apps/add/your-own-app var creds = new CloudCredentials("app ID", "app token"); observer = new ProximityObserver(creds, (error) => { Debug.WriteLine($"error = {error}"); }); var range = new ProximityRange(1.0); var zone1 = new ProximityZone("lobby", range) { OnEnter = (context) => { Debug.WriteLine($"zone1 enter, context = {context}"); }, OnExit = (context) => { Debug.WriteLine($"zone1 exit, context = {context}"); }, OnContextChange = (contexts) => { Debug.WriteLine($"zone1 contextChange, contexts = {contexts}"); } }; var zone2 = new ProximityZone("conf-room", range) { OnEnter = (context) => { Debug.WriteLine($"zone2 enter, context = {context}"); }, OnExit = (context) => { Debug.WriteLine($"zone2 exit, context = {context}"); }, OnContextChange = (contexts) => { Debug.WriteLine($"zone2 contextChange, contexts = {contexts}"); } }; observer.StartObservingZones(new ProximityZone[] { zone1, zone2 }); Debug.WriteLine("Proximity all ready to go!"); return(true); }
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; }
internal static LogyardLog GetLogyardClient(CancellationToken cancellationToken) { var uaaClient = GetUAAClient(); CloudCredentials credentials = new CloudCredentials(); credentials.User = User; credentials.Password = Password; var context = uaaClient.Login(credentials).Result; var cfClient = GetClient(); var logEndpoint = cfClient.Info.GetV1Info().Result.AppLogEndpoint; LogyardLog logyardClient = new LogyardLog(new Uri(logEndpoint), context.Token.AccessToken); return(logyardClient); }
public static SubscriptionClient Create(IDictionary <string, object> settings) { if (settings == null) { throw new ArgumentNullException("settings"); } CloudCredentials credentials = ConfigurationHelper.GetCredentials <CloudCredentials>(settings); Uri baseUri = ConfigurationHelper.GetUri(settings, "BaseUri", false); return(baseUri != null ? new SubscriptionClient(credentials, baseUri) : new SubscriptionClient(credentials)); }
private static async Task<SubscriptionListOperationResponse.Subscription> GetSubscription( CloudCredentials credentials, string filter) { IEnumerable<SubscriptionListOperationResponse.Subscription> subscriptionList = null; using (var client = new SubscriptionClient(credentials)) { var results = await client.Subscriptions.ListAsync(); subscriptionList = results.Subscriptions; } var selectedSubscription = subscriptionList.First(s => s.SubscriptionName.Contains(filter)); return selectedSubscription; }
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()); } }
public void CloudFoundryClientWithInvlidCertificate_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 = delegate { return(true); }; client.Login(credentials).Wait(); System.Net.ServicePointManager.ServerCertificateValidationCallback = null; client.Stacks.ListAllStacks().Wait(); }
public void Login_test() { var 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()); } }
/// <summary> /// Initializes a new instance of the SubscriptionClient class. /// </summary> /// <param name='credentials'> /// Credentials used to authenticate requests. /// </param> /// <param name='baseUri'> /// The URI used as the base for all Service Management requests. /// </param> public SubscriptionClient(CloudCredentials credentials, Uri baseUri) : this() { if (credentials == null) { throw new ArgumentNullException("credentials"); } if (baseUri == null) { throw new ArgumentNullException("baseUri"); } this._credentials = credentials; this._baseUri = baseUri; this.Credentials.InitializeServiceClient(this); }
public async Task <AuthenticationContext> Login(CloudCredentials credentials) { var info = await this.Info.GetInfo(); var authUrl = info.AuthorizationEndpoint.TrimEnd('/') + "/oauth/token"; this.UAAClient = new UAAClient(new Uri(authUrl), this.HttpProxy, this.SkipCertificateValidation); var context = await this.UAAClient.Login(credentials); if (context.IsLoggedIn) { //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401. //// Calling the CC's /v2/info endpoint will prevent this misbehavior. await this.Info.GetInfo(); } return(context); }
public void Login_incorrect_user_test() { var client = TestUtil.GetClient(); CloudCredentials credentials = new CloudCredentials(); credentials.User = Guid.NewGuid().ToString(); credentials.Password = TestUtil.Password; try { client.Login(credentials).Wait(); } catch (AggregateException aggEx) { Assert.IsInstanceOfType(aggEx.InnerException, typeof(AuthenticationException)); } catch (Exception ex) { Assert.Fail("Expected AuthError but got :" + ex.ToString()); } }
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; }
public void Login_refresh_token_test() { if (TestUtil.IgnoreCertificate) { System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); } CloudCredentials credentials = new CloudCredentials(); credentials.User = TestUtil.User; credentials.Password = TestUtil.Password; var client = TestUtil.GetClient(); var authEndpoint = client.Info.GetInfo().Result.AuthorizationEndpoint; var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token"); UAAClient uaaClient = new UAAClient(authUri); var context = uaaClient.Login(credentials).Result; client.Login(context.Token.RefreshToken).Wait(); client.Buildpacks.ListAllBuildpacks().Wait(); }
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; }
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; }
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("logTest")) { client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); break; } } apprequest = new CreateAppRequest(); apprequest.Name = "logTest" + Guid.NewGuid().ToString(); apprequest.HealthCheckType = "none"; apprequest.Memory = 64; apprequest.Instances = 1; apprequest.SpaceGuid = spaceGuid; apprequest.Buildpack = "https://github.com/ryandotsmith/null-buildpack.git"; apprequest.EnvironmentJson = new Dictionary <string, string>() { { "envtest1234", "envtestvalue1234" } }; apprequest.Command = "printenv; cat content.txt; ping 127.0.0.1;"; client.Apps.PushProgress += Apps_PushProgress; File.WriteAllText(Path.Combine(tempAppPath, "content.txt"), "dummy content"); }
public static SubscriptionClient CreateSubscriptionClient(this CloudClients clients, CloudCredentials credentials) { return(new SubscriptionClient(credentials)); }
public static SubscriptionClient CreateCloudServiceManagementClient(this CloudClients clients, CloudCredentials credentials, Uri baseUri) { return(new SubscriptionClient(credentials, baseUri)); }
public static SubscriptionClient CreateSubscriptionClient(this CloudClients clients, CloudCredentials credentials) { return new SubscriptionClient(credentials); }
// { Token = new UAA.Authentication.Token() { RefreshToken = "mytoken" } } - Token is read-only and cannot be assigned to from shim context without fakeing uaa internal static Task <AuthenticationContext> CustomLogin(CloudController.V2.Client.CloudFoundryClient arg1, CloudCredentials arg2) { return(Task.Factory.StartNew <AuthenticationContext>(() => { return new AuthenticationContext(); })); }
public static SubscriptionClient CreateCloudServiceManagementClient(this CloudClients clients, CloudCredentials credentials, Uri baseUri) { return new SubscriptionClient(credentials, baseUri); }