-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frends.salesforce.authenticate #25
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce a new GitHub workflow for Salesforce authentication tasks using FrendsPlatform, targeting both the main branch and other branches. The updates include configuration files for building, testing, and releasing, as well as project-specific files like .NET project files, unit tests, and documentation. The new functionality focuses on obtaining Salesforce access tokens, with appropriate environment settings and secrets management. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Outside diff range and nitpick comments (2)
Frends.Salesforce.Authenticate/README.md (1)
12-31
: The building instructions are well-detailed. Consider adding more context about the environment setup required before building, if any.Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/UnitTests.cs (1)
51-68
: Consider refining the exception message inAuthenticate_ThrowOnInvalidCredentials
to be more descriptive than "Bad Request".
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (18)
- .github/workflows/Frends.Salesforce.Authenticate_build_and_test_on_main.yml (1 hunks)
- .github/workflows/Frends.Salesforce.Authenticate_build_and_test_on_push.yml (1 hunks)
- .github/workflows/Frends.Salesforce.Authenticate_release.yml (1 hunks)
- .gitignore (1 hunks)
- Frends.Salesforce.Authenticate/Apache-2.0 (1 hunks)
- Frends.Salesforce.Authenticate/CHANGELOG.md (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/.env (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/Frends.Salesforce.Authenticate.Tests.csproj (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/GlobalSuppressions.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/UnitTests.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.sln (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Definitions/Input.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Definitions/Result.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.csproj (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/FrendsTaskMetadata.json (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/GlobalSuppressions.cs (1 hunks)
- Frends.Salesforce.Authenticate/README.md (1 hunks)
Files skipped from review due to trivial changes (8)
- .github/workflows/Frends.Salesforce.Authenticate_release.yml
- .gitignore
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/.env
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.sln
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Definitions/Input.cs
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.csproj
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/FrendsTaskMetadata.json
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/GlobalSuppressions.cs
Additional context used
Markdownlint
Frends.Salesforce.Authenticate/CHANGELOG.md
3-3: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines
4-4: Expected: 1; Actual: 0; Above (MD022, blanks-around-headings)
Headings should be surrounded by blank lines
4-4: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines
5-5: null (MD032, blanks-around-lists)
Lists should be surrounded by blank linesFrends.Salesforce.Authenticate/README.md
1-1: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines
34-34: null (MD034, no-bare-urls)
Bare URL used
LanguageTool
Frends.Salesforce.Authenticate/README.md
[uncategorized] ~32-~32: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL)
Context: ...tnet pack --configuration Release` ### Third party licenses StyleCop.Analyzer version (un...
Additional comments not posted (11)
Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Definitions/Result.cs (1)
17-17
: Correct the example value for theSuccess
property.- /// <example>true</example> + /// <example>false</example>Likely invalid or redundant comment.
.github/workflows/Frends.Salesforce.Authenticate_build_and_test_on_main.yml (1)
1-26
: The workflow configuration looks good and is well-structured for building and testing on the main branch..github/workflows/Frends.Salesforce.Authenticate_build_and_test_on_push.yml (1)
1-26
: The workflow configuration looks good and is correctly set up to build and test on branches other than the main.Frends.Salesforce.Authenticate/README.md (2)
8-11
: The installation instructions are clear and concise.
1-6
: Ensure that the badge URLs are correct and functional. The URL for the build badge seems incorrect as it references a non-existent workflow file and a duplicated repository name.Verification successful
The workflow file
Frends.Salesforce.Authenticate_build_and_test_on_main.yml
does exist in the repository. Therefore, the badge URL in the README is correct.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the existence of the workflow file referenced in the badge URL. fd 'Frends.Salesforce.Authenticate_build_and_test_on_main.yml' --type fLength of output: 71
Script:
#!/bin/bash # List all workflow files in the repository to identify the correct one for the build badge. fd '.yml' --type f --exec cat {} +Length of output: 36
Script:
#!/bin/bash # List all files in the .github/workflows directory to identify any existing workflow files. fd . --type f --search-path .github/workflowsLength of output: 905
Tools
Markdownlint
1-1: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank linesFrends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/Frends.Salesforce.Authenticate.Tests.csproj (1)
1-36
: The project file is well-structured and specifies all necessary configurations and package references clearly. Ensure that all package versions are compatible with the target framework and each other.Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/GlobalSuppressions.cs (1)
1-13
: The suppressions are well-documented with justifications. However, ensure that suppressing these rules aligns with the overall coding standards and guidelines of your project.Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/UnitTests.cs (3)
24-30
: TheAssemblyInit
method correctly sets up environment variables using the.env.local
file. Good use of directory navigation to ensure the correct path.
32-49
: The testAuthenticate_ShouldReturnAccessToken_OnSuccess
is well-structured and correctly asserts the success and presence of an access token.
77-99
: The testAccessToken_ShouldBeValid
effectively checks the validity of the access token by making an HTTP request and ensuring it succeeds.Frends.Salesforce.Authenticate/Apache-2.0 (1)
1-93
: The Apache License 2.0 text is correctly included and unmodified, ensuring compliance with standard open-source licensing practices.
[TestMethod] | ||
public async Task Authenticate_ThrowWhenCredentialsAreNull() | ||
{ | ||
Input input = null; | ||
await Assert.ThrowsExceptionAsync<NullReferenceException>(() => Salesforce.Authenticate(input, CancellationToken.None)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using NullReferenceException
is not ideal for handling null inputs in Authenticate_ThrowWhenCredentialsAreNull
. Consider implementing more graceful error handling.
@@ -0,0 +1,5 @@ | |||
# Changelog | |||
|
|||
## [1.0.0] - 2024-06-11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank lines around headings and lists for proper markdown formatting.
+
## [1.0.0] - 2024-06-11
+
### Changed
+
- Initial implementation
+
Also applies to: 4-4, 5-5
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
## [1.0.0] - 2024-06-11 | |
## [1.0.0] - 2024-06-11 | |
### Changed | |
- Initial implementation | |
Tools
Markdownlint
3-3: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines
### Third party licenses | ||
|
||
StyleCop.Analyzer version (unmodified version 1.1.118) used to analyze code uses Apache-2.0 license, full text and source code can be found in https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/README.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a hyphen to "Third-party licenses" for grammatical correctness. Also, replace the bare URL with a markdown link to improve the document's readability and professionalism.
- ### Third party licenses
+ ### Third-party licenses
- StyleCop.Analyzer version (unmodified version 1.1.118) used to analyze code uses Apache-2.0 license, full text and source code can be found in https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/README.md
+ StyleCop.Analyzer version (unmodified version 1.1.118) used to analyze code uses Apache-2.0 license, full text and source code can be found in [StyleCop.Analyzers GitHub](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/README.md)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
### Third party licenses | |
StyleCop.Analyzer version (unmodified version 1.1.118) used to analyze code uses Apache-2.0 license, full text and source code can be found in https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/README.md | |
### Third-party licenses | |
StyleCop.Analyzer version (unmodified version 1.1.118) used to analyze code uses Apache-2.0 license, full text and source code can be found in [StyleCop.Analyzers GitHub](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/README.md) |
Tools
LanguageTool
[uncategorized] ~32-~32: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL)
Context: ...tnet pack --configuration Release` ### Third party licenses StyleCop.Analyzer version (un...
Markdownlint
34-34: null (MD034, no-bare-urls)
Bare URL used
namespace Frends.Salesforce.Authenticate; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Frends.Salesforce.Authenticate.Definitions; | ||
using Newtonsoft.Json.Linq; | ||
|
||
/// <summary> | ||
/// Salesforce Task. | ||
/// </summary> | ||
public static class Salesforce | ||
{ | ||
/// <summary> | ||
/// Frends Task for retrieving an access token for a Salesforce user using the provided input parameters. | ||
/// [Documentation](https://tasks.frends.com/tasks/frends-tasks/Frends.Salesforce.Authenticate) | ||
/// </summary> | ||
/// <param name="input">Input parameters including login details.</param> | ||
/// <param name="cancellationToken">Token generated by Frends to stop this task.</param> | ||
/// <returns>Object { bool Success, string accessToken }</returns> | ||
public static async Task<Result> Authenticate([PropertyTab] Input input, CancellationToken cancellationToken) | ||
{ | ||
var accessToken = await GetAccessTokenAsync(input, cancellationToken); | ||
return new Result(accessToken, true); | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously obtains an access token from Salesforce using the provided authentication parameters. | ||
/// </summary> | ||
/// <param name="authParams">Authentication parameters including login URL, client ID, client secret, username, and password with security token.</param> | ||
/// <param name="cancellationToken">Token to cancel the task if needed.</param> | ||
/// <returns>Access token as a string.</returns> | ||
public static async Task<string> GetAccessTokenAsync(Input authParams, CancellationToken cancellationToken) | ||
{ | ||
var requestUrl = authParams.LoginUrl; | ||
|
||
var formData = new Dictionary<string, string> | ||
{ | ||
{ "grant_type", "password" }, | ||
{ "client_id", authParams.ClientId }, | ||
{ "client_secret", authParams.ClientSecret }, | ||
{ "username", authParams.Username }, | ||
{ "password", $"{authParams.Password}{authParams.SecurityToken}" }, | ||
}; | ||
|
||
using (var httpClient = new HttpClient()) | ||
{ | ||
var content = new FormUrlEncodedContent(formData); | ||
|
||
HttpResponseMessage response = await httpClient.PostAsync(requestUrl, content, cancellationToken); | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
string responseBody = await response.Content.ReadAsStringAsync(); | ||
var jsonResponse = JObject.Parse(responseBody); | ||
return jsonResponse["access_token"].ToString(); | ||
} | ||
else | ||
{ | ||
throw new Exception($"Failed to authenticate with Salesforce. Status code: {response.StatusCode}, Reason: {response.ReasonPhrase}"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of Salesforce authentication is clear and follows good practices. However, consider handling specific exceptions rather than the general Exception
to provide more granular error information to the users.
- throw new Exception($"Failed to authenticate with Salesforce. Status code: {response.StatusCode}, Reason: {response.ReasonPhrase}");
+ throw new HttpRequestException($"Failed to authenticate with Salesforce. Status code: {response.StatusCode}, Reason: {response.ReasonPhrase}");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
namespace Frends.Salesforce.Authenticate; | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.IO; | |
using System.Net.Http; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Frends.Salesforce.Authenticate.Definitions; | |
using Newtonsoft.Json.Linq; | |
/// <summary> | |
/// Salesforce Task. | |
/// </summary> | |
public static class Salesforce | |
{ | |
/// <summary> | |
/// Frends Task for retrieving an access token for a Salesforce user using the provided input parameters. | |
/// [Documentation](https://tasks.frends.com/tasks/frends-tasks/Frends.Salesforce.Authenticate) | |
/// </summary> | |
/// <param name="input">Input parameters including login details.</param> | |
/// <param name="cancellationToken">Token generated by Frends to stop this task.</param> | |
/// <returns>Object { bool Success, string accessToken }</returns> | |
public static async Task<Result> Authenticate([PropertyTab] Input input, CancellationToken cancellationToken) | |
{ | |
var accessToken = await GetAccessTokenAsync(input, cancellationToken); | |
return new Result(accessToken, true); | |
} | |
/// <summary> | |
/// Asynchronously obtains an access token from Salesforce using the provided authentication parameters. | |
/// </summary> | |
/// <param name="authParams">Authentication parameters including login URL, client ID, client secret, username, and password with security token.</param> | |
/// <param name="cancellationToken">Token to cancel the task if needed.</param> | |
/// <returns>Access token as a string.</returns> | |
public static async Task<string> GetAccessTokenAsync(Input authParams, CancellationToken cancellationToken) | |
{ | |
var requestUrl = authParams.LoginUrl; | |
var formData = new Dictionary<string, string> | |
{ | |
{ "grant_type", "password" }, | |
{ "client_id", authParams.ClientId }, | |
{ "client_secret", authParams.ClientSecret }, | |
{ "username", authParams.Username }, | |
{ "password", $"{authParams.Password}{authParams.SecurityToken}" }, | |
}; | |
using (var httpClient = new HttpClient()) | |
{ | |
var content = new FormUrlEncodedContent(formData); | |
HttpResponseMessage response = await httpClient.PostAsync(requestUrl, content, cancellationToken); | |
if (response.IsSuccessStatusCode) | |
{ | |
string responseBody = await response.Content.ReadAsStringAsync(); | |
var jsonResponse = JObject.Parse(responseBody); | |
return jsonResponse["access_token"].ToString(); | |
} | |
else | |
{ | |
throw new Exception($"Failed to authenticate with Salesforce. Status code: {response.StatusCode}, Reason: {response.ReasonPhrase}"); | |
} | |
} | |
} | |
throw new HttpRequestException($"Failed to authenticate with Salesforce. Status code: {response.StatusCode}, Reason: {response.ReasonPhrase}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- Frends.Salesforce.Authenticate/CHANGELOG.md (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/UnitTests.cs (1 hunks)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.cs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.Tests/UnitTests.cs
- Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate/Frends.Salesforce.Authenticate.cs
Additional context used
Markdownlint
Frends.Salesforce.Authenticate/CHANGELOG.md
7-7: null (MD047, single-trailing-newline)
Files should end with a single newline character
Additional comments not posted (1)
Frends.Salesforce.Authenticate/CHANGELOG.md (1)
3-7
: Ensure proper markdown formatting around headings and lists.+ ## [1.0.0] - 2024-06-11 + ### Changed + - Initial implementation +Tools
Markdownlint
7-7: null (MD047, single-trailing-newline)
Files should end with a single newline character
|
||
### Changed | ||
|
||
- Initial implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline at the end of the file to comply with markdown standards.
- Initial implementation
+ Initial implementation
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- Initial implementation | |
- Initial implementation | |
Tools
Markdownlint
7-7: null (MD047, single-trailing-newline)
Files should end with a single newline character
Issue 17
Summary by CodeRabbit
New Features
Documentation
Chores