public NamingProxy(
            ILoggerFactory loggerFactory,
            NacosOptions optionsAccs,
            IHttpClientFactory clientFactory)
        {
            _logger        = loggerFactory.CreateLogger <NamingProxy>();
            _options       = optionsAccs;
            _clientFactory = clientFactory;

            _serverUrls    = new List <string>();
            _namespace     = _options.Namespace;
            _endpoint      = _options.EndPoint;
            _securityProxy = new Security.SecurityProxy(_options, _logger);

            var serverAddresses = _options.ServerAddresses;

            if (serverAddresses != null && serverAddresses.Any())
            {
                foreach (var item in serverAddresses)
                {
                    // here only trust the input server addresses of user
                    _serverUrls.Add(item.TrimEnd('/'));
                }

                if (_serverUrls.Count == 1)
                {
                    _nacosDomain = _serverUrls.First();
                }
            }

            InitRefreshTask();
        }
Exemple #2
0
 public SecurityProxy(NacosOptions options)
 {
     _username   = options.UserName ?? "";
     _password   = options.Password ?? "";
     contextPath = options.ContextPath;
     contextPath = contextPath.StartsWith("/") ? contextPath : "/" + contextPath;
 }
        public ServerListManager(NacosOptions options)
        {
            _serverUrls       = new List <string>();
            _contentPath      = options.ContextPath;
            _defaultNodesPath = options.ClusterName;
            var serverAddresses = options.ServerAddresses;
            var @namespace      = options.Namespace;

            if (serverAddresses != null && serverAddresses.Any())
            {
                _isFixed = true;
                foreach (var item in serverAddresses)
                {
                    // here only trust the input server addresses of user
                    _serverUrls.Add(item.TrimEnd('/'));
                }

                if (string.IsNullOrWhiteSpace(@namespace))
                {
                    _name = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}";
                }
                else
                {
                    _namespace = @namespace;
                    _tenant    = @namespace;
                    _name      = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}-{@namespace}";
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(options.EndPoint))
                {
                    throw new Nacos.Exceptions.NacosException(ConstValue.CLIENT_INVALID_PARAM, "endpoint is blank");
                }

                _isFixed = false;

                if (string.IsNullOrWhiteSpace(@namespace))
                {
                    _name             = options.EndPoint;
                    _addressServerUrl = $"http://{options.EndPoint}:{_endpointPort}/{_contentPath}/{_defaultNodesPath}";
                }
                else
                {
                    _namespace = @namespace;
                    _tenant    = $"{options.EndPoint}-{@namespace}";
                    _name      = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}-{@namespace}";

                    _addressServerUrl = $"http://{options.EndPoint}:{_endpointPort}/{_contentPath}/{_defaultNodesPath}?namespace={@namespace}";
                }

                t = new Timer(async x =>
                {
                    await RefreshSrvAsync();
                }, null, TimeSpan.Zero, TimeSpan.FromSeconds(10));

                RefreshSrvAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
        public NacosMsConfigClient(
            ILoggerFactory loggerFactory,
            NacosOptions options)
        {
            _logger    = loggerFactory.CreateLogger <NacosMsConfigClient>();
            _options   = options;
            _processor = new FileLocalConfigInfoProcessor();

            _httpAgent = new MsConfigServerHttpAgent(_options);

            listeners = new List <Listener>();
        }
Exemple #5
0
        public MsConfigServerHttpAgent(NacosOptions options)
        {
            _options       = options;
            _serverListMgr = new ServerListManager(_options);
            _namespaceId   = _options.Namespace;

            _serverListMgr = new ServerListManager(_options);
            _securityProxy = new Security.SecurityProxy(_options);

            _securityProxy.LoginAsync(_serverListMgr.GetServerUrls()).ConfigureAwait(false).GetAwaiter().GetResult();

            _timer = new Timer(async x =>
            {
                await _securityProxy.LoginAsync(_serverListMgr.GetServerUrls());
            }, null, 0, _securityInfoRefreshIntervalMills);
        }
Exemple #6
0
        public ServerHttpAgent(
            ILoggerFactory loggerFactory,
            IOptions <NacosOptions> optionsAccs,
            IHttpClientFactory clientFactory)
        {
            _logger        = loggerFactory.CreateLogger <ServerHttpAgent>();
            _options       = optionsAccs.Value;
            _clientFactory = clientFactory;
            _namespaceId   = _options.Namespace;

            _serverListMgr = new ServerListManager(_options);
            _securityProxy = new Security.SecurityProxy(_options);

            _securityProxy.LoginAsync(_serverListMgr.GetServerUrls()).ConfigureAwait(false).GetAwaiter().GetResult();

            _timer = new Timer(async x =>
            {
                await _securityProxy.LoginAsync(_serverListMgr.GetServerUrls());
            }, null, 0, _securityInfoRefreshIntervalMills);
        }