public EvrikaPrinterClient(IEvrikaPrinterClientSettings settings, IMasterPortalSettings masterPortalSettings, IPortalSettings portalSettings)
        {
            var provider   = new ApiKeyAuthenticationProvider(portalSettings.ApiKey);
            var authClient = new AuthClient(new ClientSettings(provider, new FakeLog(), TimeSpan.FromSeconds(15), false),
                                            new TopologyProvider(settings.TestAuthUrls.Length > 0 ? settings.TestAuthUrls : portalSettings.AuthUrls));

            var result = authClient.AuthByPassAsync2(new AuthByPassRequest(masterPortalSettings.MasterLogin, masterPortalSettings.MasterPassword)).Result;

            result.EnsureSuccess();
            var authSid = result.Response.Sid;

            Console.WriteLine($"AuthSid: {authSid}");

            clusterClient = new ClusterClient(null, config =>
            {
                var repeatReplicasCount = settings.RepeatReplicasCount;
                config.ClusterProvider  = new FixedClusterProvider(settings.Host);
                config.SetupKonturHttpTransport();
                config.RepeatReplicas(repeatReplicasCount);
                config.ReplicaOrdering        = new AsIsReplicaOrdering();
                config.DefaultRequestStrategy = new ForkingRequestStrategy(new EqualDelaysProvider(repeatReplicasCount), repeatReplicasCount);
                config.AddRequestTransform(new DefaultHeadersTransform(new[]
                {
                    new Header("Authorization", $"auth.sid {authSid}"),
                    new Header("X-Kontur-Apikey", $"{settings.PortalApiKey}"),
                    new Header(HeaderNames.Accept, "application/json"),
                }));
                config.DefaultTimeout = settings.Timeout;
            });
        }
Example #2
0
        public static void ConfigurePortal(this IContainer container)
        {
            var portalSettings = container.Get <IPortalSettings>();
            var provider       = new ApiKeyAuthenticationProvider(portalSettings.ApiKey);

            SetPortalTopology("topology/api.sessions", new FakeLog(), portalSettings.AuthUrls);

            var authClient       = new AuthClient(new ClientSettings(provider, new FakeLog(), TimeSpan.FromSeconds(15), false), new TopologyProvider(portalSettings.AuthUrls));
            var requisitesClient = new RequisitesClient(new ClientSettings(provider, new FakeLog(), TimeSpan.FromSeconds(15), false), new TopologyProvider(portalSettings.RequisitesUrls));

            container.Configurator.ForAbstraction <IRequisitesClient>().UseInstances(requisitesClient);
            container.Configurator.ForAbstraction <IAuthClient>().UseInstances(authClient);
        }