Exemplo n.º 1
0
        public async Task <List <CredentialPermission> > AddPermissionsAsync(string name, List <CredentialPermission> permissions)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name is required");
            }

            if (permissions == null || !permissions.Any())
            {
                throw new ArgumentException("At least one permission is required");
            }

            HttpClientHelper.ConfigureCertificateValidatation(_validateCertificates, out SecurityProtocolType protocolType, out RemoteCertificateValidationCallback prevValidator);
            try
            {
                _logger?.LogTrace($"About to POST {_baseCredHubUrl}/v1/permissions");
                var newPermissions = new CredentialPermissions {
                    CredentialName = name, Permissions = permissions
                };
                var addResponse = await _httpClient.PostAsJsonAsync($"{_baseCredHubUrl}/v1/permissions", newPermissions, _serializerSettings);

                return(await GetPermissionsAsync(name));
            }
            finally
            {
                HttpClientHelper.RestoreCertificateValidation(_validateCertificates, protocolType, prevValidator);
            }
        }
Exemplo n.º 2
0
        private async Task<List<CredentialPermission>> AddPermissionsInternalAsync(string name, List<CredentialPermission> permissions)
        {
            HttpClientHelper.ConfigureCertificateValidation(_validateCertificates, out var protocolType, out var prevValidator);
            try
            {
                _logger?.LogTrace($"About to POST {_baseCredHubUrl}/v1/permissions");
                var newPermissions = new CredentialPermissions { CredentialName = name, Permissions = permissions };
                _ = await _httpClient.PostAsJsonAsync($"{_baseCredHubUrl}/v1/permissions", newPermissions, SerializerOptions).ConfigureAwait(false);

                return await GetPermissionsAsync(name).ConfigureAwait(false);
            }
            finally
            {
                HttpClientHelper.RestoreCertificateValidation(_validateCertificates, protocolType, prevValidator);
            }
        }
Exemplo n.º 3
0
        public async Task <List <CredentialPermission> > AddPermissionsAsync(string name, List <CredentialPermission> permissions)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name is required");
            }

            if (permissions == null || !permissions.Any())
            {
                throw new ArgumentException("At least one permission is required");
            }

            _logger?.LogTrace($"About to POST {_baseCredHubUrl}/v1/permissions");
            var newPermissions = new CredentialPermissions {
                CredentialName = name, Permissions = permissions
            };
            var addResponse = await _httpClient.PostAsJsonAsync($"{_baseCredHubUrl}/v1/permissions", newPermissions, _serializerSettings);

            return(await GetPermissionsAsync(name));
        }