private bool ValidateModel(ServiceRegistrationInputModel model) { if (string.IsNullOrWhiteSpace(model.ServiceId)) { return(false); } if (model.Endpoints == null || model.Endpoints.Length == 0) { return(false); } return(true); }
public Task <string> GenerateAsync(ServiceRegistrationInputModel serviceRegistration) { using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, DefaultEncoding, true)) { writer.Write(DateTimeOffset.UtcNow.UtcTicks); writer.Write(serviceRegistration.ServiceId); writer.Write(string.Join(";", serviceRegistration.Endpoints.Select(u => u.ToString()))); writer.Write(serviceRegistration.IpAddress ?? ""); } var protectedBytes = _protector.Protect(ms.ToArray()); return(Task.FromResult(Convert.ToBase64String(protectedBytes))); } }
/// <summary> /// Registers a new service /// </summary> /// <param name="registration">The registration information</param> /// <returns>A token which can be used to unregister the service</returns> public async Task <string> RegisterAsync(ServiceRegistrationInputModel registration) { var service = await _store.FindByServiceIdAsync(registration.ServiceId); if (service == null) { service = new Service() { DisplayName = registration.DisplayName, ServiceId = registration.ServiceId, Endpoints = registration.Endpoints, IpAddresses = new[] { registration.IpAddress }, PublicUrls = registration.PublicUrls }; } else { service.Endpoints = service.Endpoints.Concat(registration.Endpoints).ToArray(); if (!string.IsNullOrWhiteSpace(registration.IpAddress)) { if (service.IpAddresses != null) { service.IpAddresses = service.IpAddresses.Concat(new[] { registration.IpAddress }).ToArray(); } else { service.IpAddresses = new[] { registration.IpAddress } }; } if (registration.PublicUrls?.Length > 0) { if (service.PublicUrls != null) { service.PublicUrls = service.PublicUrls.Concat(registration.PublicUrls).Distinct().ToArray(); } else { service.PublicUrls = registration.PublicUrls; } } } await _store.StoreAsync(service); return(await _tokenProvider.GenerateAsync(registration)); }