Exemple #1
0
        private async Task UpdateFamiliesPermissions(Database database)
        {
            var families = await GetFamilies <Family>(database);

            // We cannot inject the AuthzService in the ctor, as the Casbin Enforcer tries to load policies in it's ctor and the CasbinRules container may not exist yet.
            // This will cause the function to fail on startup never reaching the Db.EnsureCreated line that would have created the container for the Enforcer to work.
            // Therefore we load it using the provider here after the container has been created.
            var authz = _provider.GetService <IAuthzService>();
            var updateAuthorizationPoliciesCommand = new UpdateAuthorizationPoliciesCommand(authz);

            foreach (var family in families)
            {
                await updateAuthorizationPoliciesCommand.Handle(family);
            }
        }
        public async Task Run([CosmosDBTrigger(
                                   databaseName: "EzDinner",
                                   collectionName: "Families",
                                   ConnectionStringSetting = "CosmosDb:ConnectionString",
                                   LeaseCollectionName = "Leases",
                                   LeaseCollectionPrefix = "policies",
                                   CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document> input)
        {
            if (input != null && input.Count > 0)
            {
                _logger.LogInformation("Families updated " + input.Count);
                var updatePermissionsCommand = new UpdateAuthorizationPoliciesCommand(_authz);

                foreach (var document in input)
                {
                    var family = JsonConvert.DeserializeObject <Family>(document.ToString());
                    _logger.LogInformation("Updating policies for family " + family.Id);
                    await updatePermissionsCommand.Handle(family);
                }
            }
        }