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()));
        }
        private Resource ToModel(Persistance.Models.Resource resource)
        {
            var identifier = CRN.FromValue(resource.CanonicalName);
            var actions    = resource.Actions.Select(a => ResourceAction.FromValue(a.Action.CanonicalName)).ToArray();

            return(Resource.FromIdentifier(identifier).WithActions(actions));
        }
 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 override Resource ReadJson(JsonReader reader, Type objectType, Resource existingValue, bool hasExistingValue,
                                          JsonSerializer serializer)
        {
            var token = JToken.Load(reader);

            if (token.Type == JTokenType.Object)
            {
                CRN identifier           = null;
                ResourceAction[] actions = null;
                foreach (var t in token.Children())
                {
                    if (t.Path == "identifier")
                    {
                        identifier = CRN.FromValue(t.First.Value <string>());
                        continue;
                    }

                    if (t.Path == "action")
                    {
                        var values = t.Values();
                        actions = values.Select(v => ResourceAction.FromValue(v.Value <string>())).ToArray();
                        continue;
                    }
                }

                if (actions != null)
                {
                    return(Resource.FromIdentifier(identifier).WithActions(actions));
                }
                return(Resource.FromIdentifier(identifier));
            }

            if (token.Type == JTokenType.String)
            {
                var value = serializer.Deserialize <CRN>(token.CreateReader());
                return(Resource.FromIdentifier(value));
            }

            try
            {
                if (token.Value <CRN>() == default)
                {
                    return(null);
                }
                var value = serializer.Deserialize <CRN>(reader);
                return(Resource.FromIdentifier(value));
            }
            catch
            {
                return(null);
            }
        }
Exemple #5
0
        public IActionResult Delete(string resource)
        {
            var actionName = ResourceAction.FromValue(HttpUtility.UrlDecode(resource));

            var found = this.context.Actions.FirstOrDefault(a => a.CanonicalName == actionName);

            if (found == null)
            {
                return(NotFound());
            }

            this.context.Actions.Remove(found);

            return(Ok(resource));
        }
Exemple #6
0
 public IActionResult Get() => Ok(this.context.Actions.ToList().Select(a => ResourceAction.FromValue(a.CanonicalName)));
 public IEnumerable <ResourceAction> AllActions() =>
 this.context.Actions.ToList().Select(a => ResourceAction.FromValue(a.CanonicalName));