public BuildDockerCommand(RabbitMessage receiver, DockerService service, DiscoveryServiceClient client) : base(receiver) { this.receiver = receiver; this.service = service; this.client = client; }
public async Task GetService_ShouldThrow_WhenMultipleServicesReturnedAsync() { _mockHttpHandler.Setup(httpHandler => httpHandler.Send(It.IsAny <HttpRequestMessage>())) .Returns( (HttpRequestMessage requestMessage) => new HttpResponseMessage { StatusCode = HttpStatusCode.OK, RequestMessage = requestMessage, Content = new StringContent( JsonConvert.SerializeObject( new DiscoveryServiceResponseModel { Context = $"{_discoveryBaseUrl}$metadata#Services", Value = new List <DiscoveryServiceApiModel> { new DiscoveryServiceApiModel(), new DiscoveryServiceApiModel() } })) }); var discoveryServiceClient = new DiscoveryServiceClient("http://localhost/DiscoveryService/v1/", _mockHttpHandler.Object); await Assert.ThrowsAsync <InvalidOperationException>(() => discoveryServiceClient.GetServiceAsync("Identity", 1)); }
private static string DiscoverOrganizationUrl(SecurityToken token, string organizationName, string discoveryServiceUrl, Uri issuerUri) { using (DiscoveryServiceClient client = new DiscoveryServiceClient("CustomBinding_IDiscoveryService", discoveryServiceUrl)) { client.ConfigureCrmOnlineBinding(issuerUri); client.Token = token; RetrieveOrganizationRequest request = new RetrieveOrganizationRequest() { UniqueName = organizationName }; RetrieveOrganizationResponse response; try { response = (RetrieveOrganizationResponse)client.Execute(request); } catch (CommunicationException) { throw; } foreach (KeyValuePair <EndpointType, string> endpoint in response.Detail.Endpoints) { if (EndpointType.OrganizationService == endpoint.Key) { Console.WriteLine("Organization Service URL: {0}", endpoint.Value); return(endpoint.Value); } } throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Organization {0} does not have an OrganizationService endpoint defined.", organizationName)); } }
public ServiceDiscoveryHandler( DiscoveryServiceClient discoveryServiceClient, IMemoryCache cache, IHostService hostService) { _discoveryServiceClient = discoveryServiceClient; _cache = cache; _hostService = hostService; }
public async Task GetService_ShouldThrow_ForNonSuccessCodeAsync() { _mockHttpHandler.Setup(httpHandler => httpHandler.Send(It.IsAny <HttpRequestMessage>())) .Returns((HttpRequestMessage requestMessage) => new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest }); var discoveryServiceClient = new DiscoveryServiceClient("http://localhost/DiscoveryService/v1/", _mockHttpHandler.Object); await Assert.ThrowsAsync <HttpRequestException>(() => discoveryServiceClient.GetServiceAsync("Identity", 1)); }
public NginxController() // DiscoveryServiceClient client) { var discoveryServiceUrl = Environment.GetEnvironmentVariable("DISCOVERY_URL"); var port = Environment.GetEnvironmentVariable("NGINX_EXPOSED_PORT"); this.conatinerNameOfNginx = Environment.GetEnvironmentVariable("NGINX_CONTAINER_NAME"); var dockerContainerName = Environment.GetEnvironmentVariable("DOCKER_CONTAINER_NAME"); var dockerFolderLocation = Environment.GetEnvironmentVariable("DOCKER_LOCATIONS"); if (string.IsNullOrEmpty(dockerFolderLocation)) { this.dockerLocation = "/var/dockerFolder"; } else { this.dockerLocation = dockerFolderLocation; } var nginxFolderLocation = Environment.GetEnvironmentVariable("NGINX_LOCATIONS"); if (string.IsNullOrEmpty(nginxFolderLocation)) { this.nginxLocation = "/var/nginxFolder"; } else { this.nginxLocation = nginxFolderLocation; } InitializeDirectory(nginxLocation); if (string.IsNullOrEmpty(dockerContainerName)) { System.Console.WriteLine("[DEBUG]: DockerContainerName is null. Should be something like api_docker in the discovery service."); } this.discoveryServiceClient = new DiscoveryServiceClient(discoveryServiceUrl); var nginxSite = this.discoveryServiceClient.GetWebsite(dockerContainerName); nginxSite.Wait(); var dockerServiceUrl = nginxSite.Result.DockerUrl; this.dockerServiceClient = new DockerServiceClient(dockerServiceUrl.ToString().TrimEnd('/')); if (string.IsNullOrEmpty(port)) { portExposed = "8080:80"; } else { portExposed = port + ":80"; } }
public async Task GetService_ShouldReturn_ValidServiceAsync() { var expectedIdentityServiceModel = new DiscoveryServiceApiModel { ServiceUrl = "http://localhost/IdentityProviderSearchService", ServiceName = "IdentityProviderSearchService", Version = 1, DiscoveryType = "Service" }; var discoverySearchUrl = $"{_discoveryBaseUrl}Services?$filter=ServiceName eq '{expectedIdentityServiceModel.ServiceName}' and Version eq {expectedIdentityServiceModel.Version}"; _mockHttpHandler.Setup(httpHandler => httpHandler.Send(It.IsAny <HttpRequestMessage>())) .Returns((HttpRequestMessage requestMessage) => { if (requestMessage.RequestUri.ToString() .Equals(discoverySearchUrl, StringComparison.OrdinalIgnoreCase)) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent( JsonConvert.SerializeObject( new DiscoveryServiceResponseModel { Context = $"{_discoveryBaseUrl}$metadata#Services", Value = new List <DiscoveryServiceApiModel> { expectedIdentityServiceModel } })) }); } return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest }); }); var discoveryServiceClient = new DiscoveryServiceClient("http://localhost/DiscoveryService/v1", _mockHttpHandler.Object); var serviceRegistration = await discoveryServiceClient.GetServiceAsync( expectedIdentityServiceModel.ServiceName, expectedIdentityServiceModel.Version); Assert.Equal(expectedIdentityServiceModel.ServiceUrl, serviceRegistration.ServiceUrl); }
public async Task GetService_ShouldThrow_WhenInvalidJsonIsReturnedAsync() { _mockHttpHandler.Setup(httpHandler => httpHandler.Send(It.IsAny <HttpRequestMessage>())) .Returns( (HttpRequestMessage requestMessage) => new HttpResponseMessage { StatusCode = HttpStatusCode.OK, RequestMessage = requestMessage, Content = new StringContent("this is not json") }); var discoveryServiceClient = new DiscoveryServiceClient("http://localhost/DiscoveryService/v1/", _mockHttpHandler.Object); await Assert.ThrowsAsync <InvalidOperationException>(() => discoveryServiceClient.GetServiceAsync("Identity", 1)); }
private static async Task <string> GetBaseUrl(IAppConfiguration appConfig) { if (!appConfig.UseDiscoveryService) { return(appConfig.IdentityProviderSearchSettings.BaseUrl.EnsureTrailingSlash()); } using (var discoveryServiceClient = new DiscoveryServiceClient(appConfig.DiscoveryServiceEndpoint)) { var serviceRegistration = await discoveryServiceClient.GetServiceAsync("IdentityProviderSearchService", 1); return(!string.IsNullOrEmpty(serviceRegistration?.ServiceUrl) ? serviceRegistration.ServiceUrl.EnsureTrailingSlash() : appConfig.IdentityProviderSearchSettings.BaseUrl.EnsureTrailingSlash()); } }
/// <summary> /// Configures the IdentityService Url in IAppConfiguration. /// </summary> /// <param name="appConfig">The <see cref="IAppConfiguration"/> instance to configure.</param> public static void ConfigureIdentityServiceUrl(this IAppConfiguration appConfig) { if (!appConfig.UseDiscoveryService) { return; } using (var discoveryServiceClient = new DiscoveryServiceClient(appConfig.DiscoveryServiceEndpoint)) { var identityServiceRegistration = Task .Run(() => discoveryServiceClient.GetServiceAsync("IdentityService", 1)) .Result; if (!string.IsNullOrEmpty(identityServiceRegistration?.ServiceUrl)) { appConfig.IdentityServerConfidentialClientSettings.Authority = identityServiceRegistration.ServiceUrl; } } }
/// <summary> /// Configures the IdentitySearchProviderService Url in IAppConfiguration. /// </summary> /// <param name="appConfig">The <see cref="IAppConfiguration"/> instance to configure.</param> public static void ConfigureIdentitySearchProviderServiceUrl(this IAppConfiguration appConfig) { if (!appConfig.UseDiscoveryService) { return; } using (var discoveryServiceClient = new DiscoveryServiceClient(appConfig.DiscoveryServiceEndpoint)) { var serviceRegistration = Task .Run(() => discoveryServiceClient.GetServiceAsync("IdentityProviderSearchService", 1)) .Result; if (!string.IsNullOrEmpty(serviceRegistration?.ServiceUrl)) { appConfig.IdentityProviderSearchSettings.BaseUrl = FormatUrl(serviceRegistration.ServiceUrl); } } }
public DockerController() { var dockerHostName = Environment.GetEnvironmentVariable("DOCKER_HOST_NAME"); var discoveryServiceUrl = Environment.GetEnvironmentVariable("DISCOVERY_URL"); bindingAddress = Environment.GetEnvironmentVariable("BINDING_ADDRESS"); this.client = new DiscoveryServiceClient(discoveryServiceUrl); var dockerHostSite = this.client.GetWebsite(dockerHostName); dockerHostSite.Wait(); var dockerHost = dockerHostSite.Result.DockerUrl.ToString(); if(string.IsNullOrEmpty(dockerHost)) { DockerService.Host = ""; } else { DockerService.Host = "-H " + dockerHost; // "-H unix:///var/run/docker.sock"; } }
/// <summary> /// Configures the IdentityProviderSearchService Url in IAppConfiguration. /// </summary> /// <param name="appConfig">The <see cref="IAppConfiguration"/> instance to configure.</param> public static void ConfigureIdentityProviderSearchServiceUrl(this IAppConfiguration appConfig) { var discoveryServiceSettings = appConfig.DiscoveryServiceSettings; if (!discoveryServiceSettings.UseDiscovery) { return; } using (var discoveryServiceClient = new DiscoveryServiceClient(discoveryServiceSettings.Endpoint)) { var identityProviderSearchServiceRegistration = Task .Run(() => discoveryServiceClient.GetServiceAsync("IdentityProviderSearchService", 1)) .Result; if (!string.IsNullOrEmpty(identityProviderSearchServiceRegistration?.ServiceUrl)) { appConfig.IdentityProviderSearchSettings.Endpoint = identityProviderSearchServiceRegistration.ServiceUrl; } } }
private static string DiscoverOrganizationUrl(ClientCredentials credentials, string organizationName, string discoveryServiceUrl) { using (DiscoveryServiceClient client = new DiscoveryServiceClient("CustomBinding_IDiscoveryService", discoveryServiceUrl)) { ApplyCredentials(client, credentials); RetrieveOrganizationRequest request = new RetrieveOrganizationRequest() { UniqueName = organizationName }; RetrieveOrganizationResponse response = (RetrieveOrganizationResponse)client.Execute(request); foreach (KeyValuePair <CrmSdk.Discovery.EndpointType, string> endpoint in response.Detail.Endpoints) { if (CrmSdk.Discovery.EndpointType.OrganizationService == endpoint.Key) { Console.WriteLine("Organization Service URL: {0}", endpoint.Value); return(endpoint.Value); } } throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Organization {0} does not have an OrganizationService endpoint defined.", organizationName)); } }
public DotnetController() { this.discoveryServiceClient = new DiscoveryServiceClient("http://192.168.10.125:8000"); }
/// <summary> /// Discover GameServer Task /// </summary> private void DiscoverTask() { var client = new DiscoveryServiceClient(); var ip = client.Discover(); if (ip != null) { GameServer = ip; } else { ShowInformationOverlay("Could not find Service"); } }
private static string DiscoverOrganizationUrl(SecurityToken token, string organizationName, string discoveryServiceUrl, Uri issuerUri) { using (DiscoveryServiceClient client = new DiscoveryServiceClient("CustomBinding_IDiscoveryService", discoveryServiceUrl)) { client.ConfigureCrmOnlineBinding(issuerUri); client.Token = token; RetrieveOrganizationRequest request = new RetrieveOrganizationRequest() { UniqueName = organizationName }; RetrieveOrganizationResponse response; try { response = (RetrieveOrganizationResponse)client.Execute(request); } catch (CommunicationException) { throw; } foreach (KeyValuePair<EndpointType, string> endpoint in response.Detail.Endpoints) { if (EndpointType.OrganizationService == endpoint.Key) { Console.WriteLine("Organization Service URL: {0}", endpoint.Value); return endpoint.Value; } } throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Organization {0} does not have an OrganizationService endpoint defined.", organizationName)); } }