/// <summary> /// Create a copy of a collection of Service objects. /// </summary> /// <param name="sourceServices">Collection of Service objects to copy.</param> /// <returns>New copy of the collection of Service objects.</returns> private ICollection <Model.Infrastructure.Service> CopyServices(ICollection <Model.Infrastructure.Service> sourceServices) { ICollection <Model.Infrastructure.Service> destinationServices = null; if (sourceServices != null) { destinationServices = new List <Model.Infrastructure.Service>(); foreach (Model.Infrastructure.Service sourceService in sourceServices) { Model.Infrastructure.Service destinationService = new Model.Infrastructure.Service { ContextId = sourceService.ContextId, Name = sourceService.Name, Type = sourceService.Type }; if (sourceService.Rights != null) { destinationService.Rights = CopyRights(sourceService.Rights); } destinationServices.Add(destinationService); } } return(destinationServices); }
private Model.Infrastructure.Service CheckJob(Job job, string zoneId = null) { if (job == null) { throw new ArgumentException("Job cannot be null."); } if (StringUtils.IsEmpty(job.Name)) { throw new ArgumentException("Job name must be specified."); } Model.Infrastructure.Service service = ZoneUtils.GetService( EnvironmentUtils.GetTargetZone(registrationService.CurrentEnvironment, zoneId), job.Name + "s", ServiceType.FUNCTIONAL); if (service == null) { throw new ArgumentException( $"A FUNCTIONAL service with the name {job.Name}s cannot be found in the current environment"); } return(service); }
/// <summary> /// Retrieve the rights for a service in a given zone. /// </summary> /// <param name="serviceType">The service type used for the request <see cref="ServiceType"/> for valid types.</param> /// <param name="serviceName">The service name.</param> /// <param name="zone">The zone to retrieve the rights for.</param> /// <returns>An array of declared rights</returns> private IDictionary <string, Right> GetRightsForService(string serviceType, string serviceName, ProvisionedZone zone) { Model.Infrastructure.Service service = (from Model.Infrastructure.Service s in zone.Services where s.Type.Equals(serviceType) && s.Name.Equals(serviceName) select s).FirstOrDefault(); return(service?.Rights); }
private void checkJob(Job job, RightType right, string zoneId = null, Boolean ignoreId = false) { Model.Infrastructure.Service service = checkJob(job, zoneId); if (!ignoreId && !right.Equals(RightType.CREATE) && job.Id == null) { throw new ArgumentException("Job must have an Id for any non-creation operation"); } if (service.Rights[right.ToString()].Value.Equals(RightValue.REJECTED.ToString())) { throw new ArgumentException("The attempted operation is not permitted in the ACL of the current environment"); } }
/// <summary> /// Internal method to retrieve the rights for a service in a given zone. /// </summary> /// <param name="serviceName">The service name to look for</param> /// <param name="zone">The zone to retrieve the rights for</param> /// <returns>An array of declared rights</returns> private IDictionary <string, Right> getRights(string serviceName, ProvisionedZone zone) { Model.Infrastructure.Service service = (from Model.Infrastructure.Service s in zone.Services where s.Type.Equals(ServiceType.FUNCTIONAL.ToString()) && s.Name.Equals(serviceName) select s).FirstOrDefault(); if (service == null) { string msg = "No Functional Service called " + serviceName + " found in Environment."; log.Debug(msg); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg)); } log.Debug("Found access rights for " + service.Type + " service " + service.Name); return(service.Rights); }
private ICollection <Model.Infrastructure.Service> CopyServices(ICollection <Model.Infrastructure.Service> sourceServices) { ICollection <Model.Infrastructure.Service> destinationServices = new List <Model.Infrastructure.Service>(); if (sourceServices != null && sourceServices.Count > 0) { foreach (Model.Infrastructure.Service sourceService in sourceServices) { Model.Infrastructure.Service destinationService = new Model.Infrastructure.Service { ContextId = sourceService.ContextId, Name = sourceService.Name, Type = sourceService.Type }; IDictionary <string, Right> rights = CopyRights(sourceService.Rights); if (rights.Count > 0) { destinationService.Rights = rights; } destinationServices.Add(destinationService); } } return(destinationServices); }