Skip to content

Commit

Permalink
feat(DATAINT-1932): added tls version selector to connection settings
Browse files Browse the repository at this point in the history
  • Loading branch information
roehlerw committed Jan 8, 2025
1 parent af887f2 commit 6d25b72
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,5 @@ __pycache__/
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.xsd.cs
.vscode/*
26 changes: 20 additions & 6 deletions PluginSalesforce/API/Factory/PushTopicConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@ public class PushTopicConnectionFactory : IPushTopicConnectionFactory
{
public PushTopicConnection GetPushTopicConnection(RequestHelper requestHelper, string channel)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
PushTopicConnection pushTopicConnection = null;

var accessToken = requestHelper.GetToken();
var instanceUrl = requestHelper.GetInstanceUrl();

try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
switch (requestHelper.GetTlsVersion())
{
case "System Default":
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
break;
case "TLS 1.2":
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
break;
case "TLS 1.3":
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
break;
default:
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
break;
}

var readTimeOut = 120000;
var streamingEndpointURI = "/cometd/52.0";
var options = new Dictionary<string, object>
Expand All @@ -33,10 +47,10 @@ public PushTopicConnection GetPushTopicConnection(RequestHelper requestHelper, s
{
{HttpRequestHeader.Authorization.ToString(), "Bearer " + accessToken}
};
var transport = new LongPollingTransport(options, new NameValueCollection {collection});
var transport = new LongPollingTransport(options, new NameValueCollection { collection });
var serverUri = new Uri(instanceUrl);
var endpoint = $"{serverUri.Scheme}://{serverUri.Host}{streamingEndpointURI}";
var bayeuxClient = new BayeuxClient(endpoint, new[] {transport});
var bayeuxClient = new BayeuxClient(endpoint, new[] { transport });

pushTopicConnection = new PushTopicConnection(bayeuxClient, channel);
}
Expand All @@ -49,7 +63,7 @@ public PushTopicConnection GetPushTopicConnection(RequestHelper requestHelper, s
{
throw new Exception("Error creating push topic connection");
}

return pushTopicConnection;
}
}
Expand Down
35 changes: 20 additions & 15 deletions PluginSalesforce/Helper/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RequestHelper
private readonly Settings _settings;
private readonly string _baseUrl;
private readonly string _instanceUrl;

public RequestHelper(Settings settings, HttpClient client)
{
_authenticator = new Authenticator(settings, client);
Expand Down Expand Up @@ -43,12 +43,12 @@ public async Task<HttpResponseMessage> GetAsync(string path)
Logger.Error(e, e.Message);
throw;
}

// add token to the request and execute the request
try
{
var uri = String.Format("{0}/{1}", _baseUrl, path.TrimStart('/'));

var client = _client;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

Expand All @@ -62,7 +62,7 @@ public async Task<HttpResponseMessage> GetAsync(string path)
throw;
}
}

/// <summary>
/// Post Async request wrapper for making authenticated requests
/// </summary>
Expand All @@ -83,12 +83,12 @@ public async Task<HttpResponseMessage> PostAsync(string path, StringContent json
Logger.Error(e, e.Message);
throw;
}

// add token to the request and execute the request
try
{
var uri = String.Format("{0}/{1}", _baseUrl, path.TrimStart('/'));

var client = _client;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand Down Expand Up @@ -124,12 +124,12 @@ public async Task<HttpResponseMessage> PutAsync(string path, StringContent json)
Logger.Error(e, e.Message);
throw;
}

// add token to the request and execute the request
try
{
var uri = String.Format("{0}/{1}", _baseUrl, path.TrimStart('/'));

var client = _client;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand All @@ -144,7 +144,7 @@ public async Task<HttpResponseMessage> PutAsync(string path, StringContent json)
throw;
}
}

/// <summary>
/// Patch async wrapper for making authenticated requests
/// </summary>
Expand All @@ -165,12 +165,12 @@ public async Task<HttpResponseMessage> PatchAsync(string path, StringContent jso
Logger.Error(e, e.Message);
throw;
}

// add token to the request and execute the request
try
{
var uri = String.Format("{0}/{1}", _baseUrl, path.TrimStart('/'));

var client = _client;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Expand All @@ -185,7 +185,7 @@ public async Task<HttpResponseMessage> PatchAsync(string path, StringContent jso
throw;
}
}

/// <summary>
/// Delete async wrapper for making authenticated requests
/// </summary>
Expand All @@ -205,12 +205,12 @@ public async Task<HttpResponseMessage> DeleteAsync(string path)
Logger.Error(e, e.Message);
throw;
}

// add token to the request and execute the request
try
{
var uri = String.Format("{0}/{1}", _baseUrl, path.TrimStart('/'));

var client = _client;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

Expand All @@ -227,12 +227,17 @@ public async Task<HttpResponseMessage> DeleteAsync(string path)

public string GetToken()
{
return _authenticator.GetToken().Result;
return _authenticator.GetToken().Result;
}

public string GetInstanceUrl()
{
return _instanceUrl;
}

public string GetTlsVersion()
{
return _settings.TlsVersion;
}
}
}
16 changes: 13 additions & 3 deletions PluginSalesforce/Helper/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Settings
public string ClientSecret { get; set; }
public string RefreshToken { get; set; }
public string InstanceUrl { get; set; }
public string TlsVersion { get; set; }

/// <summary>
/// Validates the settings input object
Expand All @@ -19,21 +20,30 @@ public void Validate()
{
throw new Exception("the ClientId property must be set");
}

if (string.IsNullOrEmpty(ClientSecret))
{
throw new Exception("the ClientSecret property must be set");
}

if (string.IsNullOrEmpty(RefreshToken))
{
throw new Exception("the RefreshToken property must be set");
}

if (string.IsNullOrEmpty(InstanceUrl))
{
throw new Exception("the InstanceUrl property must be set");
}
if (string.IsNullOrEmpty(TlsVersion))
{
throw new Exception("the TlsVersion property must be set");
}
}
}

public class ConnectSettings
{
public string TlsVersion { get; set; }
}
}
21 changes: 12 additions & 9 deletions PluginSalesforce/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,17 @@ public override async Task<ConnectResponse> Connect(ConnectRequest request, Serv

Logger.Info("Connecting...");
Logger.Info(JsonConvert.SerializeObject(request, Formatting.Indented));
// Logger.Info("Got OAuth State: " + request.OauthStateJson);
// Logger.Info("Got OAuthConfig " + JsonConvert.SerializeObject(request.OauthConfiguration));
// Logger.Info("Got OAuth State: " + request.OauthStateJson);
// Logger.Info("Got OAuthConfig " + JsonConvert.SerializeObject(request.OauthConfiguration));

OAuthState oAuthState;
OAuthConfig oAuthConfig;
ConnectSettings connectSettings;
try
{
oAuthState = JsonConvert.DeserializeObject<OAuthState>(request.OauthStateJson);
oAuthConfig = JsonConvert.DeserializeObject<OAuthConfig>(oAuthState.Config);
connectSettings = JsonConvert.DeserializeObject<ConnectSettings>(request.SettingsJson);
}
catch (Exception e)
{
Expand All @@ -252,13 +254,14 @@ public override async Task<ConnectResponse> Connect(ConnectRequest request, Serv
ClientId = request.OauthConfiguration.ClientId,
ClientSecret = request.OauthConfiguration.ClientSecret,
RefreshToken = oAuthState.RefreshToken,
InstanceUrl = oAuthConfig.InstanceUrl
InstanceUrl = oAuthConfig.InstanceUrl,
TlsVersion = connectSettings.TlsVersion
};
}
else
{
var _settings = JsonConvert.DeserializeObject<Settings>(request.SettingsJson);

settings = new Settings
{
ClientId = _settings.ClientId,
Expand Down Expand Up @@ -380,7 +383,7 @@ public override async Task<DiscoverSchemasResponse> DiscoverSchemas(DiscoverSche
Logger.Info("Discovering Schemas...");

DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse();

// handle query based schema
try
{
Expand Down Expand Up @@ -471,7 +474,7 @@ public override Task<ConfigureRealTimeResponse> ConfigureRealTime(ConfigureRealT
{
Logger.Info("Configuring real time...");


var schemaJson = Read.GetSchemaJson();
var uiJson = Read.GetUIJson();

Expand All @@ -491,7 +494,7 @@ public override Task<ConfigureRealTimeResponse> ConfigureRealTime(ConfigureRealT
}
});
}

// if first call
if (string.IsNullOrWhiteSpace(request.Form.DataJson) || request.Form.DataJson == "{}")
{
Expand All @@ -508,7 +511,7 @@ public override Task<ConfigureRealTimeResponse> ConfigureRealTime(ConfigureRealT
}
});
}

// TODO: Enhancement - Validate if the passed in channel name is valid and covers all the properties of the schema

return Task.FromResult(new ConfigureRealTimeResponse
Expand Down Expand Up @@ -545,7 +548,7 @@ public override async Task ReadStream(ReadRequest request, IServerStreamWriter<R
try
{
var recordsCount = 0;

if (!string.IsNullOrWhiteSpace(request.RealTimeSettingsJson))
{
recordsCount = await Read.ReadRecordsRealTimeAsync(_client, request, responseStream,
Expand Down
22 changes: 21 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Publisher which pulls data from a Salesforce instance",
"apiVersion": "2",
"versionDescription": "Version 1",
"version": "1.2.1",
"version": "1.6.9",
"iconFile": "icon.png",
"executable": "PluginSalesforce",
"kind": "publisher",
Expand All @@ -30,8 +30,28 @@
},
"configSchema": {
"ui": {
"ui:order": [
"TlsVersion"
]
},
"schema": {
"type": "object",
"properties": {
"TlsVersion": {
"type": "string",
"title": "TLS Version",
"description": "Which TLS version to use in the plugin",
"default": "System Default",
"enum": [
"System Default",
"TLS 1.2",
"TLS 1.3"
]
}
},
"required": [
"TlsVersion"
]
}
}
}

0 comments on commit 6d25b72

Please sign in to comment.