Ejemplo n.º 1
0
        /// <summary>
        /// Updates service registration useing delete current and creat ne service registration
        /// First searches for existing service registration by service Id provided by <see cref="_serviceSettings"/>.
        /// Then removes previous registration and creates new with updated Tls certificate provided by <see cref="_serviceSettings"/>.
        /// </summary>
        public void UpdateServiceRegistrationTlsCertificate(string user, SecureString password)
        {
            try {
                _logger.LogInformation(
                    string.Format(Resources.PerofomingOperation, Resources.UpdateLookupServiceRegistration));
                var serviceFound = _lsClient.ListRegisteredServices().
                                   Where <LookupServiceRegistrationInfo>(r => r.serviceId == _serviceSettings.ServiceId).
                                   FirstOrDefault();

                if (serviceFound == null)
                {
                    throw new Exception($"Service with id '{_serviceSettings.ServiceId}' not found in lookup service registered services.");
                }

                var registeredEndpoint = serviceFound.serviceEndpoints.FirstOrDefault <LookupServiceRegistrationEndpoint>();
                if (registeredEndpoint == null ||
                    string.IsNullOrEmpty(registeredEndpoint.url))
                {
                    throw new Exception($"Lookup service registration for service with id '{_serviceSettings.ServiceId}' has no valid Endpoint record needed for srvice registrion update operation.");
                }

                // Remove previous registration
                Deregister(user, password);

                _logger.LogInformation(
                    string.Format(Resources.PerofomingOperation, Resources.RegisteringToLookupServiceOperation));
                // Create new service registration with new Tls Certificate
                _lsClient.RegisterService(
                    user,
                    password,
                    serviceFound.nodeId,
                    serviceFound.ownerId,
                    serviceFound.serviceDescriptionResourceKey,
                    serviceFound.serviceId,
                    serviceFound.serviceNameResourceKey,
                    serviceFound.serviceVersion,
                    serviceFound.serviceType?.product,
                    serviceFound.serviceType?.type,
                    registeredEndpoint.url,
                    _serviceSettings.EndpointProtocol,
                    _serviceSettings.EndpointType,
                    _serviceSettings.TlsCertificate);
            } catch (AggregateException ex) {
                _logger.LogError(ex.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
        //[Test]
        public void ListRegisteredServices()
        {
            var services = _lsClient.ListRegisteredServices();

            Assert.NotNull(services);
        }
Ejemplo n.º 3
0
        public int Run(UserInput userInput)
        {
            try {
                var certificatesCommonName = userInput.ServiceHostname;

                _logger.LogDebug($"User Input VC: {userInput.Psc}");
                _logger.LogDebug($"User Input VC User: {userInput.User}");
                _logger.LogDebug($"User Input VC Thumbprint: {userInput.VcThumbprint}");
                _logger.LogDebug($"User Input Force Specified: {userInput.ForceSpecified}");

                userInput.EnsureIsValid(SetupFlowType.CleanupVCRegistration);

                K8sSettings k8sSettings = null;
                if (userInput.K8sSettings != null && File.Exists(userInput.K8sSettings))
                {
                    k8sSettings = JsonConvert.DeserializeObject <K8sSettings>(File.ReadAllText(userInput.K8sSettings));
                }

                // === VC Unregister Actions ===
                X509CertificateValidator certificateValidator = null;
                if (userInput.ForceSpecified)
                {
                    certificateValidator = new AcceptAllX509CertificateValidator();
                }
                else if (!string.IsNullOrEmpty(userInput.VcThumbprint))
                {
                    certificateValidator = new SpecifiedCertificateThumbprintValidator(userInput.VcThumbprint);
                }

                var lookupServiceClient = new LookupServiceClient(
                    userInput.Psc,
                    certificateValidator);

                var    registeredServices = lookupServiceClient.ListRegisteredServices();
                string srsServiceId       = null;
                string srsOwnerId         = null;
                foreach (var service in registeredServices)
                {
                    if (service.ownerId?.StartsWith("srs-SolutionOwner-") ?? false)
                    {
                        // SRS Service registration found
                        srsServiceId = service.serviceId;
                        srsOwnerId   = service.ownerId;
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(srsServiceId) && !string.IsNullOrEmpty(srsOwnerId))
                {
                    _logger.LogInformation($"SRS Service registration found on VC {userInput.Psc}, service Id: {srsServiceId}, service owner Id: {srsOwnerId}");
                    _logger.LogInformation("Performing SRS Service regitration cleanup");
                    var setupServiceSettings = SetupServiceSettings.FromStsSettings(new StsSettings {
                        SolutionServiceId = srsServiceId,
                        SolutionOwnerId   = srsOwnerId
                    });

                    _logger.LogDebug($"SetupServiceSettings ServiceId: {setupServiceSettings.ServiceId}");
                    _logger.LogDebug($"SetupServiceSettings OwnerId: {setupServiceSettings.OwnerId}");

                    var ssoSdkUri = lookupServiceClient.GetSsoAdminEndpointUri();
                    var stsUri    = lookupServiceClient.GetStsEndpointUri();
                    _logger.LogDebug($"Resolved SSO SDK Endpoint: {ssoSdkUri}");
                    _logger.LogDebug($"Resolved Sts Endpoint: {stsUri}");

                    var ssoAdminClient = new SsoAdminClient(ssoSdkUri, stsUri, certificateValidator);

                    // --- SSO Solution User Registration ---
                    var ssoSolutionRegitration = new SsoSolutionUserRegistration(
                        _loggerFactory,
                        setupServiceSettings,
                        ssoAdminClient);

                    ssoSolutionRegitration.DeleteSolutionUser(userInput.User, userInput.Password);
                    // --- SSO Solution User Registration ---

                    // --- Lookup Service Registration ---
                    var lsRegistration = new LookupServiceRegistration(
                        _loggerFactory,
                        setupServiceSettings,
                        lookupServiceClient);
                    lsRegistration.Deregister(userInput.User, userInput.Password);
                }
                else
                {
                    _logger.LogInformation($"SRS Service registration not found on VC {userInput.Psc}");
                }

                // === VC Unregister Actions ===
            } catch (InvalidUserInputException exc) {
                _logger.LogError(exc, exc.Message);
                return(1);
            } catch (Exception exc) {
                _logger.LogError(exc, exc.Message);
                return(2);
            }

            _logger.LogInformation("Success");
            return(0);
        }