Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Bump ssri from 6.0.1 to 6.0.2 in /server #20

Merged
9 commits merged into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Created by https://www.gitignore.io/api/node,visualstudiocode
# Edit at https://www.gitignore.io/?templates=node,visualstudiocode

.output

### Node ###
# Logs
logs
Expand Down Expand Up @@ -129,4 +131,4 @@ obj/
*.svclog
*.scc

.idea
.idea
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trigger:
- master

pool:
vmImage: 'Ubuntu-16.04'
vmImage: 'Ubuntu-20.04'

steps:
- task: InstallSSHKey@0
Expand All @@ -24,11 +24,11 @@ steps:
- bash: |
set -eu -o pipefail

sudo pip install setuptools
sudo pip install awscli
sudo pip3 install setuptools
sudo pip3 install awscli
export AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY)

cp ${DOWNLOADSECUREFILE_SECUREFILEPATH} ./ccloud-config
cd server
make release BUILD_NUMBER=$(Build.BuildId)
displayName: 'Build a deployment artifact'
displayName: 'Build a deployment artifact'
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void Then_the_acl_is_returned()
.Where(acl => acl.Operation == _aclCreateDelete.Operation)
.Where(acl => acl.Name == _aclCreateDelete.TopicPrefix)
.Where(acl => acl.ConsumerGroupPrefix == _aclCreateDelete.ConsumerGroupPrefix)
.Single(acl => acl.ServiceAccountId == _aclCreateDelete.ServiceAccountId);
.Single(acl => acl.UserId == _aclCreateDelete.ServiceAccountId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ public static class LocalhostRestClient
public static IRestClient Create()
{
var httpClient = new HttpClient {BaseAddress = new Uri("http://localhost:3000/")};
var clientOptions = new ClientOptions
{
TIKA_ENABLE_MULTI_CLUSTER = false,
TIKA_API_ENDPOINT = "http://localhost:3000",
TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX = null
};

var restClient = RestClientFactory.Create(httpClient);
var restClient = RestClientFactory.Create(httpClient, clientOptions);

return restClient;
}
Expand Down
12 changes: 7 additions & 5 deletions clients/dotnet-core-rest/src/Tika.RestClient/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Http;
using Microsoft.Extensions.Options;
using Tika.RestClient.Features.Acls;
using Tika.RestClient.Features.ApiKeys;
using Tika.RestClient.Features.ServiceAccounts;
Expand All @@ -9,18 +10,19 @@ namespace Tika.RestClient
internal class Client : IRestClient
{
private HttpClient _httpClient;
private ClientOptions _clientOptions;
public ITopicsClient Topics { get; }
public IServiceAccountsClient ServiceAccounts { get; }
public IApiKeysClient ApiKeys { get; }
public IAclsClient Acls { get; }

public Client(HttpClient httpClient)
public Client(HttpClient httpClient, ClientOptions clientOptions)
{
_httpClient = httpClient;
Topics = new TopicsClient(httpClient);
ServiceAccounts = new ServiceAccountsClient(httpClient);
ApiKeys = new ApiKeysClient(httpClient);
Acls = new AclsClient(httpClient);
Topics = new TopicsClient(httpClient, clientOptions);
ServiceAccounts = new ServiceAccountsClient(httpClient, clientOptions);
ApiKeys = new ApiKeysClient(httpClient, clientOptions);
Acls = new AclsClient(httpClient, clientOptions);
}

public void Dispose()
Expand Down
37 changes: 36 additions & 1 deletion clients/dotnet-core-rest/src/Tika.RestClient/ClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
using System;
using Microsoft.Extensions.Configuration;

namespace Tika.RestClient
{
public class ClientOptions
{
public string TIKA_API_ENDPOINT { get; set; }
public bool TIKA_ENABLE_MULTI_CLUSTER { get; set; }
public string TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX { get; set; }

public ClientOptions() {}

public ClientOptions(IConfiguration conf)
{
TIKA_API_ENDPOINT = conf["TIKA_API_ENDPOINT"];
// Main config
// Will be ignored if TIKA_ENABLE_MULTI_CLUSTER is enabled
TIKA_API_ENDPOINT = ConfToString(conf, "TIKA_API_ENDPOINT", null);

// Enable features
TIKA_ENABLE_MULTI_CLUSTER = ConfToBool(conf, "TIKA_ENABLE_MULTI_CLUSTER", false);

// Multi-cluster config
TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX = ConfToString(conf, "TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX", "http://tika-");
}

private static bool ConfToBool(IConfiguration conf, string key, bool defaultValue)
{
var val = conf[key];

if (bool.TryParse(val, out bool result))
{
return result;
}

return defaultValue;
}

private static string ConfToString(IConfiguration conf, string key, string defaultValue)
{
var val = conf[key];

if (String.IsNullOrEmpty(val))
{
return defaultValue;
}

return val;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ namespace Tika.RestClient.Factories
{
public static class RestClientFactory
{
public static IRestClient Create(HttpClient httpClient)
public static IRestClient Create(HttpClient httpClient, ClientOptions options, string cluster = "")
{
return new Client(httpClient);
return new Client(httpClient, options);
}

public static IRestClient CreateFromConfiguration(HttpClient httpClient, IOptions<ClientOptions> options)
public static IRestClient CreateFromConfiguration(HttpClient httpClient, IOptions<ClientOptions> options, string cluster = "")
{
if (options.Value?.TIKA_API_ENDPOINT == null)
if (options.Value?.TIKA_API_ENDPOINT == null && options.Value?.TIKA_ENABLE_MULTI_CLUSTER != true)
{
throw new TikaRestClientInvalidConfigurationException("TIKA_API_ENDPOINT");
}
httpClient.BaseAddress = new Uri(options.Value?.TIKA_API_ENDPOINT);
return new Client(httpClient);

if (options.Value?.TIKA_ENABLE_MULTI_CLUSTER == false)
{
httpClient.BaseAddress = new Uri(options.Value?.TIKA_API_ENDPOINT);
}
else
{
httpClient.BaseAddress = new Uri($"{options.Value?.TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX}-{cluster}:3000");
}

return new Client(httpClient, options.Value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Tika.RestClient.Features.Acls.Models;

Expand All @@ -12,24 +13,26 @@ public class AclsClient : IAclsClient
{
private const string ACLS_ROUTE = "/access-control-lists";
private readonly HttpClient _httpClient;
private readonly ClientOptions _clientOptions;

public AclsClient(HttpClient httpClient)
public AclsClient(HttpClient httpClient, ClientOptions options)
{
_httpClient = httpClient;
_clientOptions = options;
}

public async Task<IEnumerable<Acl>> GetAllAsync()
public async Task<IEnumerable<Acl>> GetAllAsync(string clusterId = null)
{
var httpResponseMessage = await _httpClient.GetAsync(
new Uri(ACLS_ROUTE, UriKind.Relative)
new Uri(Utilities.MakeUrl(_clientOptions, ACLS_ROUTE, clusterId), UriKind.Absolute)
);

var acls = await Utilities.Parse<IEnumerable<Acl>>(httpResponseMessage);

return acls;
}

public async Task CreateAsync(AclCreateDelete aclCreateDelete)
public async Task CreateAsync(AclCreateDelete aclCreateDelete, string clusterId = null)
{
var payload = JsonConvert.SerializeObject(new
{
Expand All @@ -47,12 +50,12 @@ public async Task CreateAsync(AclCreateDelete aclCreateDelete)
);

await _httpClient.PostAsync(
new Uri(ACLS_ROUTE, UriKind.Relative),
new Uri(Utilities.MakeUrl(_clientOptions, ACLS_ROUTE, clusterId), UriKind.Absolute),
content
);
}

public async Task DeleteAsync(AclCreateDelete aclDelete)
public async Task DeleteAsync(AclCreateDelete aclDelete, string clusterId = null)
{
var payload = JsonConvert.SerializeObject(new
{
Expand All @@ -69,9 +72,8 @@ public async Task DeleteAsync(AclCreateDelete aclDelete)
"application/json"
);


var httpResponseMessage = await _httpClient.PostAsync(
new Uri(ACLS_ROUTE + "/delete", UriKind.Relative),
new Uri(Utilities.MakeUrl(_clientOptions, ACLS_ROUTE + "/delete", clusterId), UriKind.Absolute),
content
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Tika.RestClient.Features.Acls
{
public interface IAclsClient
{
Task<IEnumerable<Acl>> GetAllAsync();
Task CreateAsync(AclCreateDelete aclCreateDelete);
Task DeleteAsync(AclCreateDelete aclDelete);
Task<IEnumerable<Acl>> GetAllAsync(string clusterId = null);
Task CreateAsync(AclCreateDelete aclCreateDelete, string clusterId = null);
Task DeleteAsync(AclCreateDelete aclDelete, string clusterId = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ namespace Tika.RestClient.Features.Acls.Models
{
public class Acl
{
public long ServiceAccountId { get; set; }
public long UserId { get; set; }
public string ServiceAccountId { get; set; }
public string Permission { get; set; }
public string Resource { get; set; }
public string Operation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -12,24 +13,28 @@ public class ApiKeysClient : IApiKeysClient
{
private const string APIKEYS_ROUTE = "/api-keys";
private readonly HttpClient _httpClient;
private readonly ClientOptions _clientOptions;

public ApiKeysClient(HttpClient httpClient)
public ApiKeysClient(HttpClient httpClient, ClientOptions clientOptions)
{
_httpClient = httpClient;
_clientOptions = clientOptions;
}

public async Task<IEnumerable<ApiKey>> GetAllAsync()
public async Task<IEnumerable<ApiKey>> GetAllAsync(string clusterId = null)
{

var httpResponseMessage = await _httpClient.GetAsync(
new Uri(APIKEYS_ROUTE, UriKind.Relative)
new Uri(Utilities.MakeUrl(_clientOptions, APIKEYS_ROUTE, clusterId), UriKind.Absolute)
);

var serviceAccounts = await Utilities.Parse<IEnumerable<ApiKey>>(httpResponseMessage);
var apiKeys = await Utilities.Parse<IEnumerable<ApiKey>>(httpResponseMessage);
apiKeys = apiKeys.Where(key => key.Resource.ToLower().Equals(clusterId.ToLower()));

return serviceAccounts;
return apiKeys;
}

public async Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate)
public async Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate, string clusterId = null)
{
var payload = JsonConvert.SerializeObject(new
{
Expand All @@ -44,7 +49,7 @@ public async Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate)
);

var response = await _httpClient.PostAsync(
new Uri(APIKEYS_ROUTE, UriKind.Relative),
new Uri(Utilities.MakeUrl(_clientOptions, APIKEYS_ROUTE, clusterId), UriKind.Absolute),
content
);

Expand All @@ -53,10 +58,11 @@ public async Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate)
return apiKey;
}

public async Task DeleteAsync(string key)
public async Task DeleteAsync(string key, string clusterId = null)
{

var httpResponseMessage = await _httpClient.DeleteAsync(
new Uri(APIKEYS_ROUTE + "/" + key, UriKind.Relative)
new Uri(Utilities.MakeUrl(_clientOptions, APIKEYS_ROUTE + "/" + key, clusterId), UriKind.Absolute)
);

httpResponseMessage.EnsureSuccessStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Tika.RestClient.Features.ApiKeys
{
public interface IApiKeysClient
{
Task<IEnumerable<ApiKey>> GetAllAsync();
Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate);
Task DeleteAsync(string key);
Task<IEnumerable<ApiKey>> GetAllAsync(string clusterId = null);
Task<ApiKey> CreateAsync(ApiKeyCreate apiKeyCreate, string clusterId = null);
Task DeleteAsync(string key, string clusterId = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class ApiKey
public string Secret { get; set; }
public string Description { get; set; }
public string Owner { get; set; }
public string Resource { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Tika.RestClient.Features.ServiceAccounts
{
public interface IServiceAccountsClient
{
Task<IEnumerable<ServiceAccount>> GetAllAsync();
Task<ServiceAccount> CreateAsync(ServiceAccountCreateCommand serviceAccountCreateCommand);
Task DeleteAsync(string id);
Task<IEnumerable<ServiceAccount>> GetAllAsync(string clusterId = null);
Task<ServiceAccount> CreateAsync(ServiceAccountCreateCommand serviceAccountCreateCommand, string clusterId = null);
Task DeleteAsync(string id, string clusterId = null);
}
}
Loading