Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc(mvcOptions =>
            {
                if (!Configuration.GetValue("DISABLE_AUTH", false))
                {
                    // Set Authorized as default policy
                    var policy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme)
                                 .RequireAuthenticatedUser()
                                 .RequireClaim("scope", "uaa.resource")
                                 .Build();
                    mvcOptions.Filters.Add(new AuthorizeFilter(policy));
                }
            });
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddDbContext <TimeEntryContext>(options => options.UseMySql(Configuration));
            services.AddScoped <ITimeEntryDataGateway, TimeEntryDataGateway>();

            services.AddSingleton <IProjectClient>(sp =>
            {
                var handler    = new DiscoveryHttpClientHandler(sp.GetService <IDiscoveryClient>());
                var httpClient = new HttpClient(handler, false)
                {
                    BaseAddress = new Uri(Configuration.GetValue <string>("REGISTRATION_SERVER_ENDPOINT"))
                };
                var contextAccessor = sp.GetService <IHttpContextAccessor>();
                var logger          = sp.GetService <ILogger <ProjectClient> >();
                return(new ProjectClient(httpClient, logger, () => contextAccessor.HttpContext.GetTokenAsync("access_token")));
            });
            services.AddDiscoveryClient(Configuration);
            services.AddHystrixMetricsStream(Configuration);
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddCloudFoundryJwtBearer(Configuration);
        }
 public ProductService(IHystrixCommandOptions options, IDiscoveryClient client, ILogger <ProductService> logger) :
     base(options)
 {
     _logger  = logger;
     _handler = new DiscoveryHttpClientHandler(client);
     IsFallbackUserDefined = true;
 }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.AddDbContext <AllocationContext>(options => options.UseMySql(Configuration));
            services.AddScoped <IAllocationDataGateway, AllocationDataGateway>();

            services.AddSingleton <IProjectClient>(sp =>
            {
                var handler    = new DiscoveryHttpClientHandler(sp.GetService <IDiscoveryClient>());
                var httpClient = new HttpClient(handler, false)
                {
                    BaseAddress = new Uri(Configuration.GetValue <string>("REGISTRATION_SERVER_ENDPOINT"))
                };

                var logger = sp.GetService <ILogger <ProjectClient> >();
                return(new ProjectClient(httpClient, logger));
            });

            services.AddHystrixMetricsStream(Configuration);

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Allocations Server", Version = "v1"
                });
                //c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}/edu.gateway.api.xml");
                c.DescribeAllEnumsAsStrings();
            });

            services.AddDiscoveryClient(Configuration);
        }
        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <string> DoGetAsync(this IDiscoveryClient client, string url)
        {
            _handler = new DiscoveryHttpClientHandler(client);
            HttpClient httpClient = new HttpClient(_handler);

            return(await httpClient.GetStringAsync(url));
        }
        public Feign(IDiscoveryClient client, ILoggerFactory factory)
        {
            Handler = new DiscoveryHttpClientHandler(client, factory.CreateLogger <DiscoveryHttpClientHandler>());
            Logger  = factory.CreateLogger <TollRateServiceClient>();

            Operations = BuildOperations();
        }
 public AbstractService(IDiscoveryClient client, ILogger logger, IHttpContextAccessor context)
 {
     _handler = new DiscoveryHttpClientHandler(client);
     _handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
     _logger  = logger;
     _context = context;
 }
Пример #7
0
 public TestController(ILogger <TestController> logger, IHttpClientFactory clientFactory,
                       IDiscoveryClient discoveryClient)
 {
     _httpClient = clientFactory.CreateClient("CURRRENCY");
     _logger     = logger;
     _handler    = new DiscoveryHttpClientHandler(discoveryClient);
 }
Пример #8
0
        /// <summary>
        /// auth configuration from identity server
        /// </summary>
        /// <param name="services">services</param>
        /// <param name="configuration">configuration</param>
        public static void ConfigureResourceAuthService(this IServiceCollection services, IConfiguration configuration)
        {
            var discoveryClient = services.BuildServiceProvider().GetService <IDiscoveryClient>();
            var handler         = new DiscoveryHttpClientHandler(discoveryClient);
            var authority       = configuration.GetSection("Identity:Authority").Value;
            var apiName         = configuration.GetSection("Identity:Api").Value;
            var secret          = configuration.GetSection("Identity:Secret").Value;

            services.AddAuthorization();
            services.AddAuthentication(x =>
            {
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddIdentityServerAuthentication(x =>
            {
                x.ApiName                         = apiName;
                x.ApiSecret                       = secret;
                x.Authority                       = authority;
                x.RequireHttpsMetadata            = false;
                x.JwtBackChannelHandler           = handler;
                x.IntrospectionDiscoveryHandler   = handler;
                x.IntrospectionBackChannelHandler = handler;
            });
        }
        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string DoGetSync(this IDiscoveryClient client, string url)
        {
            _handler = new DiscoveryHttpClientHandler(client);
            HttpClient httpClient = new HttpClient(_handler);

            return(httpClient.GetStringAsync(url).Result);
        }
Пример #10
0
 public HomeController(IDiscoveryClient client, ILoggerFactory logFactory)
 {
     _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger <DiscoveryHttpClientHandler>());
     // Remove comment to use SSL communications with Self-Signed Certs
     // _handler.ServerCertificateCustomValidationCallback = (a,b,c,d) => {return true;};
     _logger = logFactory.CreateLogger <HomeController>();
 }
        public async Task <Response <HttpResponseMessage> > GetResponseAsync(DownstreamContext request)
        {
            _handler = new DiscoveryHttpClientHandler(_discoveryClient);
            var discoveryClientBuilder = new DiscoveryHttpClientBuilder().Create(_handler, request.DownstreamReRoute);
            var httpDiscoveryClient    = discoveryClientBuilder.Client;

            try
            {
                var response = await httpDiscoveryClient.SendAsync(request.DownstreamRequest);

                return(new OkResponse <HttpResponseMessage>(response));
            }
            catch (TimeoutRejectedException exception)
            {
                return
                    (new ErrorResponse <HttpResponseMessage>(new RequestTimedOutError(exception)));
            }
            catch (BrokenCircuitException exception)
            {
                return
                    (new ErrorResponse <HttpResponseMessage>(new RequestTimedOutError(exception)));
            }
            catch (Exception exception)
            {
                return(new ErrorResponse <HttpResponseMessage>(new UnableToCompleteRequestError(exception)));
            }
            finally
            {
                //_cacheHandlers.Set(cacheKey, httpClient, TimeSpan.FromHours(24));
            }
        }
Пример #12
0
 public HttpRpcService(IConfiguration configuration, IDiscoveryClient client, ILogService _LogService)
 {
     _handler       = new DiscoveryHttpClientHandler(client);
     httpClient     = new HttpClient(_handler);
     serviceAddress = configuration.GetSection("gateway")["serviceAddress"];
     oldWebApi      = configuration.GetSection("OldWebApi").Value;
     logService     = _LogService;
 }
Пример #13
0
 public FlowClient(
     IDiscoveryClient discoveryClient,
     ILogger <IFlowClient> logger)
 {
     this.discoveryClient        = discoveryClient;
     this.discoveryClientHandler = new DiscoveryHttpClientHandler(this.discoveryClient, logger);
     this.logger = logger;
 }
Пример #14
0
        // Lab08 End

        public FortuneServiceClient(IDiscoveryClient client, IOptionsSnapshot <FortuneServiceConfig> config, ILogger <FortuneServiceClient> logger)
        {
            // Lab08 Start
            _handler = new DiscoveryHttpClientHandler(client);
            // Lab08 End
            _logger = logger;
            _config = config;
        }
Пример #15
0
        public FrontendController(IDiscoveryClient client, IConfiguration configuration)
        {
            string backendName = configuration.GetSection("c2c:backend").Get <string>();

            // The .NET Eureka handler automatically replaces the backend app name, so just provide it here:
            _backendBaseUrl = "http://" + backendName;
            _handler        = new DiscoveryHttpClientHandler(client);
        }
Пример #16
0
 public FortuneService(IHystrixCommandOptions options, IDiscoveryClient client, ILoggerFactory logFactory) : base(options)
 {
     _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger <DiscoveryHttpClientHandler>());
     // Remove comment to use SSL communications with Self-Signed Certs
     // _handler.ServerCertificateCustomValidationCallback = (a,b,c,d) => {return true;};
     IsFallbackUserDefined = true;
     this._logger          = logFactory.CreateLogger <FortuneService>();
 }
Пример #17
0
        public EurekaService(IDiscoveryClient client)
        {
            var handler = new DiscoveryHttpClientHandler(client);

            this.http = new HttpClient(handler, false)
            {
                BaseAddress = new Uri("http://tas-steeltoe-core-eureka-api/app")
            };
        }
Пример #18
0
        public ProductoService(IDiscoveryClient discoveryClient, IConfiguration configuration)
        {
            var handler    = new DiscoveryHttpClientHandler(discoveryClient);
            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = new Uri(configuration["urlProductosServicios"])
            };

            this._productoService = RestClient.For <IProductoService>(httpClient);
        }
        public PricingClient(IConfiguration configuration, IDiscoveryClient discoveryClient)
        {
            var handler    = new DiscoveryHttpClientHandler(discoveryClient);
            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = new Uri(configuration.GetValue <string>("PricingServiceUri"))
            };

            client = RestClient.For <IPricingClient>(httpClient);
        }
Пример #20
0
 public FortuneServiceClient(
     IOptionsSnapshot <FortuneServiceOptions> config,
     ILogger <FortuneServiceClient> logger,
     IDiscoveryClient discoveryClient)
 {
     _logger = logger;
     _config = config;
     _logger.LogInformation($"FortuneServiceClient URL:{config.Value.RandomFortunePath}");
     _discoveryHandler = new DiscoveryHttpClientHandler(discoveryClient, logger);
 }
Пример #21
0
        public void LookupService_FindsService_ReturnsURI()
        {
            // Arrange
            IDiscoveryClient           client  = new TestDiscoveryClient(new TestServiceInstance(new Uri("http://foundit:5555")));
            DiscoveryHttpClientHandler handler = new DiscoveryHttpClientHandler(client);
            Uri uri = new Uri("http://foo/test/bar/foo?test=1&test2=2");
            // Act and Assert
            var result = handler.LookupService(uri);

            Assert.Equal(new Uri("http://foundit:5555/test/bar/foo?test=1&test2=2"), result);
        }
Пример #22
0
        public void LookupService_NonDefaultPort_ReturnsOriginalURI()
        {
            // Arrange
            IDiscoveryClient           client  = new TestDiscoveryClient();
            DiscoveryHttpClientHandler handler = new DiscoveryHttpClientHandler(client);
            Uri uri = new Uri("http://foo:8080/test");
            // Act and Assert
            var result = handler.LookupService(uri);

            Assert.Equal(uri, result);
        }
Пример #23
0
 public FortuneServiceClient(
     HttpClient httpClient,
     IOptions <FortuneServiceOptions> config,
     ILogger <FortuneServiceClient> logger,
     IDiscoveryClient client)
 {
     _logger     = logger;
     _config     = config;
     _httpClient = httpClient;
     _handler    = new DiscoveryHttpClientHandler(client);
 }
Пример #24
0
        public JurosClient(IDiscoveryClient discoveryClient, IConfiguration configuration)
        {
            var handler    = new DiscoveryHttpClientHandler(discoveryClient);
            var serviceUri = configuration.GetValue <string>("Api1Uri");
            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = new Uri(serviceUri)
            };

            client = RestClient.For <IJurosClient>(httpClient);
        }
Пример #25
0
 public FortuneService(
     IConfiguration config,
     IDiscoveryClient client,
     IConnectionMultiplexer cache,
     ILogger <FortuneService> logger)
 {
     RANDOM_FORTUNE_URL = config["RANDOM_FORTUNE_URL"];
     _handler           = new DiscoveryHttpClientHandler(client);
     _logger            = logger;
     _cache             = cache;
 }
Пример #26
0
        public ProductClient(IOptions <ServicesUrl> servicesUrl, IDiscoveryClient discoveryClient)
        {
            _servicesUrl = servicesUrl.Value;
            var handler = new DiscoveryHttpClientHandler(discoveryClient);

            handler.ServerCertificateCustomValidationCallback = delegate { return(true); };
            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = new Uri(_servicesUrl.ProductApiUrl)
            };

            client = RestClient.For <IProductClient>(httpClient);
        }
Пример #27
0
 public AccountController(
     IConfiguration configuration,
     IDiscoveryClient client,
     SignInManager <Account> signInManager,
     UserManager <Account> userManager,
     IPasswordHasher <Account> passwordHasher
     )
 {
     _configuration              = configuration;
     _handler                    = new DiscoveryHttpClientHandler(client);
     _signInManager              = signInManager;
     _signInManager.UserManager  = _userManager = userManager;
     _userManager.PasswordHasher = passwordHasher;
 }
        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string DoPostSync(this IDiscoveryClient client, string url, object content)
        {
            _handler = new DiscoveryHttpClientHandler(client);
            HttpClient httpClient = new HttpClient(_handler);

            byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content));
            using (StreamContent sc = new StreamContent(new MemoryStream(data)))
            {
                sc.Headers.ContentLength = data.Length;
                sc.Headers.ContentType   = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                HttpResponseMessage response = httpClient.PostAsync(url, sc).Result;
                return(response.Content.ReadAsStringAsync().Result);
            }
        }
Пример #29
0
        // Lab07End

        public FortuneServiceClient(
            IOptionsSnapshot <FortuneServiceOptions> config,
            ILogger <FortuneServiceClient> logger,
            // Lab07 Start
            IDiscoveryClient client)
        // Lab07 End
        {
            // Lab07 Start
            _handler = new DiscoveryHttpClientHandler(client, logger);
            // Lab07 End

            _logger = logger;
            _config = config;
        }
        public WingtipToysProductServiceClient(
            IOptionsSnapshot <WingtipToysProductServiceOptions> config,
            ILogger <WingtipToysProductServiceClient> logger,

            IDiscoveryClient client,

            IHttpContextAccessor context = null)
        {
            _handler = new DiscoveryHttpClientHandler(client);

            _reqContext = context;

            _logger = logger;
            _config = config;
        }