Esempio n. 1
0
        public async Task <INodeResult> CreateNode(
            [Required][MaxLength(255)] string name,
            [Required][MaxLength(255)] string host,
            [Required][MaxLength(255)] string username,
            [Required][Range(1, 65535)] int port,
            string?password,
            string?privateKey,
            [GlobalState("ClaimsPrincipal")] ClaimsPrincipal user
            )
        {
            var tenant = user.Tenant();

            try
            {
                var id = await nodeService.Create(tenant, name, new NodeCredentials(host, username, port, password, privateKey));

                return(await ctxFactiry.CreateDbContext().Nodes.Where(x => x.Id == id)
                       .Select(x => new SuccessfulNodeCreation {
                    Node = x
                }).FirstAsync());
            }
            catch (NodeConnectionFailedException ex)
            {
                return(NodeConnectionFailed.FromNodeConnectionFailedException(ex));
            }
        }
Esempio n. 2
0
        public async Task <NodeConnectionFailed?> TestConnection(
            [Required][MaxLength(255)] string host,
            [Required][MaxLength(255)] string username,
            [Range(1, 65535)] int port,
            string?password,
            string?privateKey,
            Guid?nodeId,
            CancellationToken ct
            )
        {
            try
            {
                await conn.TestConnection(new NodeCredentials(host, username, port, password, privateKey), nodeId, ct);
            }
            catch (NodeConnectionFailedException ex)
            {
                return(NodeConnectionFailed.FromNodeConnectionFailedException(ex));
            }

            return(null);
        }
Esempio n. 3
0
        public async Task <INodeResult> UpdateNode(
            [Required] Guid id,
            [MaxLength(255)] string name,
            [MaxLength(255)] string host,
            [MaxLength(255)] string username,
            [Range(1, 65535)] int port,
            string?password,
            string?privateKey,
            [GlobalState("ClaimsPrincipal")] ClaimsPrincipal user
            )
        {
            try
            {
                var auth = await authorizationService.AuthorizeAsync(user, id, new TenantNodeRequirement());

                if (auth.Failure != null)
                {
                    throw new UnauthorizedAccessException();
                }

                await nodeService.Update(
                    id,
                    name,
                    host,
                    username,
                    port,
                    password,
                    privateKey
                    );

                return(await ctxFactiry.CreateDbContext().Nodes.Where(x => x.Id == id)
                       .Select(x => new SuccessfulNodeUpdate {
                    Node = x
                }).FirstAsync());
            }
            catch (NodeConnectionFailedException ex)
            {
                return(NodeConnectionFailed.FromNodeConnectionFailedException(ex));
            }
        }