Ejemplo n.º 1
0
        public async Task <IActionResult> Import([FromBody] ResourceImport model)
        {
            if (!_env.IsDevelopment())
            {
                return(Forbid());
            }

            await _importSvc.Import(model);

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task Import(ResourceImport model)
        {
            var resources = await _resources.GetAll();

            var existing = resources
                           .Where(r => r.Type == ResourceType.Api)
                           .ToList();

            foreach (var api in model.Apis)
            {
                var current = existing.SingleOrDefault(r => r.Name == api.Name);
                if (current != null)
                {
                    await _resources.Delete(current.Id);
                }

                await _resources.Add(new Data.Resource {
                    Type       = ResourceType.Api,
                    Name       = api.Name,
                    Enabled    = true,
                    Scopes     = api.Scopes ?? api.Name,
                    UserClaims = api.UserClaims,
                    Secrets    = new Data.ApiSecret[]
                    {
                        new Data.ApiSecret
                        {
                            Type        = "SharedSecret",
                            Value       = api.Name.Sha256(),
                            Description = "Added by Dev at " + DateTime.UtcNow.ToString("u")
                        }
                    }
                });
            }

            foreach (var client in model.Clients)
            {
                await ImportClient(client, resources);
            }
        }