public IActionResult Get() { // somehow determine what the resource, action and schema are var resource = CRN.FromValue("crn:farm/1"); var action = ResourceAction.FromValue("iam:owner"); var schema = CSN.FromValue("csn:ag-data:farm"); // validate permissions var permissionsValid = this.ValidatePermissions(resource, action, schema); if (!permissionsValid) { return(Forbid()); } var rng = new Random(); return(Ok(Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray())); }
public IEnumerable <DataSchema> All() { return(this.context.Schemas.ToList().Select(s => new DataSchema() { Description = s.Description, DisplayName = s.DisplayName, Identifier = CSN.FromValue(s.CanonicalName) })); }
private PermissionGrant ToModel(Persistance.Models.PermissionGrant entity) { return(new PermissionGrant() { Id = entity.PermissionGrantId, Principal = CPN.FromValue(entity.Principal.CanonicalName), Schema = CSN.FromValue(entity.Schema.CanonicalName), Actions = entity.Actions.Select(a => ResourceAction.FromValue(a.Action.CanonicalName)).ToList(), Resource = entity.Resources.Select(r => CRN.FromValue(r.Resource.CanonicalName)).ToList() }); }
public IEnumerable <DataProviderPolicy> GetPoliciesForSchema(CSN schema) { return(this.context.DataProviderPolicies .Include(p => p.Provider) .Include(p => p.Schema) .Include(p => p.PolicyItems) .ThenInclude(i => i.Principal) .Where(p => p.Schema.CanonicalName == schema.ToString()) .ToList() .Select(p => new DataProviderPolicy() { Provider = CRN.FromValue(p.Provider.CanonicalName), Schema = CSN.FromValue(p.Schema.CanonicalName), Rule = p.PolicyItems.Select(i => new DataProviderPolicyRule() { Principal = CPN.FromValue(i.Principal.CanonicalName), Allow = i.Allow, Deny = i.Deny }).ToList() })); }
public IActionResult Get([FromRoute] string principal, [FromQuery] string schema = null) { IEnumerable <PermissionGrant> results; var principalRn = CPN.FromValue(HttpUtility.UrlDecode(principal)); if (schema == null) { results = this.grantFinder.Find(principalRn); } else { var schemaRn = CSN.FromValue(HttpUtility.UrlDecode(schema)); results = this.grantFinder.Find(principalRn, schemaRn); } if (!results.Any()) { return(NotFound()); } return(Ok(results)); }
public IActionResult Delete(string identifier) { identifier = HttpUtility.UrlDecode(identifier); this.storage.Remove(CSN.FromValue(identifier)); return(Ok()); }