Skip to content
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

feat: Create Dialogporten Serviceowner client library #1513

Open
wants to merge 68 commits into
base: main
Choose a base branch
from

Conversation

Fargekritt
Copy link
Contributor

@Fargekritt Fargekritt commented Nov 22, 2024

Description

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications to the CI/CD workflows and adds new functionality for publishing NuGet packages. Key changes include the addition of a publish-sdk-to-nuget job in multiple workflow files, adjustments to job dependencies for clarity, and the introduction of a new workflow specifically for NuGet publishing. Additionally, several configuration files and classes related to the Dialogporten API client are added, enhancing the structure and functionality of the SDK.

Changes

File Change Summary
.github/workflows/ci-cd-main.yml Added publish-sdk-to-nuget job; reformatted needs attributes for several jobs for consistency.
.github/workflows/ci-cd-pull-request.yml Reformatted on section and needs attributes for jobs; removed CHANGELOG.md from paths-ignore. Added dry-run-deploy-infra and dry-run-deploy-apps jobs.
.github/workflows/ci-cd-staging.yml Added publish-sdk-to-nuget job; reformatted needs attributes for several jobs.
.github/workflows/workflow-publish-nuget.yml New workflow for automating NuGet package publishing with jobs for build and push.
.refitter New configuration for generating a client interface for a Web API.
Digdir.Domain.Dialogporten.sln Added new projects: WebApiClient, Digdir.Library.Dialogporten.WebApiClient, Digdir.Library.Dialogporten.WebApiClient.Sample, Digdir.Library.Dialogporten.WebApiClient.Integration.Tests.
docs/schema/V1/swagger.verified.json Enhanced OpenAPI specification with new schemas and endpoints.
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Dialogs.cs Introduced Dialogs class for API interaction with methods for Purge and PrintGetDialog.
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Digdir.Library.Dialogporten.WebApiClient.Sample.csproj New project file for the sample client.
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Program.cs Implemented console application for interacting with the Dialogporten API.
src/Digdir.Library.Dialogporten.WebApiClient.Sample/appsettings.json New configuration file for API settings.
src/Digdir.Library.Dialogporten.WebApiClient/Config/DialogportenSettings.cs Added classes and records for configuration settings.
src/Digdir.Library.Dialogporten.WebApiClient/Config/MaskinportenSettings.cs New sealed record for Maskinporten settings.
src/Digdir.Library.Dialogporten.WebApiClient/Digdir.Library.Dialogporten.WebApiClient.csproj New project file for the Web API client.
src/Digdir.Library.Dialogporten.WebApiClient/Extensions/ServiceCollectionExtensions.cs Added extension methods for configuring services related to the Dialogporten API.
src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IDialogportenSettings.cs New interface for dialog porten settings configuration.
src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IIdentifiable.cs New interface for identifiable objects.
src/Digdir.Library.Dialogporten.WebApiClient/README.md New README file for the SDK.
src/Digdir.Library.Dialogporten.WebApiClient/Services/DialogTokenVerifier.cs Introduced class for verifying dialog tokens and extracting claims.
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/.refitter New configuration file for Refitter tool.
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests.csproj New project file for integration tests.
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/RefitterInterfaceTests.cs New test class for verifying the generated Refitter interface.
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/Tests.cs New test class for integration testing of the Dialogporten API client.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • arealmaas
  • knuhau
  • oskogstad

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Fargekritt Fargekritt force-pushed the feat/add-WepApiClient-project branch from b859eb3 to d33461f Compare November 25, 2024 07:25
@Fargekritt
Copy link
Contributor Author

Er avhengig av funksjonalitet i refitter som ikke er i preview enda. Bygget refitter fra source og lagret i et lokalt nugetStore.
Refitter Source

@Fargekritt Fargekritt marked this pull request as ready for review December 13, 2024 12:53
@Fargekritt Fargekritt requested review from a team as code owners December 13, 2024 12:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 21

🧹 Outside diff range and nitpick comments (21)
src/Digdir.Library.Dialogporten.WebApiClient/Digdir.Library.Dialogporten.WebApiClient.csproj (2)

7-7: Update the package release notes URL

The current value "Link to release notes." appears to be a placeholder. Please update this with the actual URL to the release notes.


3-13: Consider enabling XML documentation

Since this is a client library, it would be beneficial to enable XML documentation to provide better IntelliSense support for consumers. Consider adding these properties:

 <PropertyGroup>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
+    <GenerateDocumentationFile>true</GenerateDocumentationFile>
+    <NoWarn>$(NoWarn);CS1591</NoWarn>
src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IDialogportenSettings.cs (3)

1-4: Add interface-level documentation.

Consider adding XML documentation for the interface itself to explain its purpose, usage, and any important implementation notes.

 namespace Digdir.Library.Dialogporten.WebApiClient.Interfaces;

+/// <summary>
+/// Defines the configuration settings required for the Dialogporten API client.
+/// </summary>
 public interface IDialogportenSettings

10-13: Enhance Scope property documentation.

The current documentation could be more helpful by including:

  1. Expected format for multiple scopes
  2. Examples of valid scopes
  3. Link to scope documentation
 /// <summary>
-/// Scopes to request. Must be provisioned on the supplied client.
+/// Space-separated list of scopes to request. Must be provisioned on the supplied client.
 /// </summary>
+/// <remarks>
+/// Example: "scope1 scope2 scope3"
+/// See https://docs.digdir.no/docs/Maskinporten/maskinporten_protocol_scope for more information about scopes.
+/// </remarks>
 string Scope { get; set; }

3-29: Consider adding validation support.

The interface could benefit from validation support to ensure all required properties are properly configured before use. Consider:

  1. Adding an IValidatable interface
  2. Including validation methods
  3. Providing a builder pattern implementation

Example implementation:

public interface IValidatable
{
    bool IsValid();
    IEnumerable<string> GetValidationErrors();
}

public interface IDialogportenSettings : IValidatable
{
    // ... existing properties ...
}
src/Digdir.Library.Dialogporten.WebApiClient/Services/DialogTokenVerifier.cs (1)

39-39: Add error handling for token body deserialization

Deserializing the token body may throw a JsonException if the token is malformed or the content is invalid. To prevent the application from crashing, add error handling around the deserialization.

Modify the code as follows:

-var bodyJson = JsonSerializer.Deserialize<JsonElement>(Base64Url.DecodeFromChars(parts[1]));
+JsonElement bodyJson;
+try
+{
+    bodyJson = JsonSerializer.Deserialize<JsonElement>(Base64Url.DecodeFromChars(parts[1]));
+}
+catch (JsonException)
+{
+    throw new ArgumentException("Invalid dialog token");
+}
src/Digdir.Library.Dialogporten.WebApiClient/Extensions/ServiceCollectionExtensions.cs (2)

25-25: Avoid using Console.WriteLine in library code

Using Console.WriteLine within a library can produce unwanted console output for consuming applications. It's better to remove it or use a logging framework that can be controlled by the application.

Remove the unnecessary console output:

-Console.WriteLine(dialogportenSettings);

62-68: Improve exception handling for unknown environments

Throwing a NotImplementedException for unknown environments may not accurately represent the issue. Consider throwing an ArgumentException with a descriptive message.

Update the switch expression as follows:

-    _ => throw new NotImplementedException()
+    _ => throw new ArgumentException($"Unknown environment: {dialogportenSettings.Environment}")
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Program.cs (1)

96-96: Check for errors before accessing error content

When accessing updateResponse.Error?.Content, ensure that an error has actually occurred. It's good practice to check if the response indicates a failure before attempting to read the error content.

Consider adding a conditional check:

if (!updateResponse.IsSuccessStatusCode && updateResponse.Error != null)
{
    Console.WriteLine(updateResponse.Error.Content);
}
src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IIdentifiable.cs (1)

3-7: Add XML documentation for better API discoverability.

Consider adding XML documentation to describe the purpose of this interface and its properties, especially since this is part of a client library that will be consumed by other developers.

+/// <summary>
+/// Represents an entity that can be uniquely identified.
+/// </summary>
 public interface IIdentifiable
 {
+    /// <summary>
+    /// Gets the unique identifier of the entity.
+    /// </summary>
     Guid Id { get; }
+    /// <summary>
+    /// Gets the revision identifier used for optimistic concurrency control.
+    /// </summary>
     Guid RevisionId { get; }
 }
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Dialogs.cs (2)

16-23: Refactor PrintGetDialog for better separation of concerns.

The method should return a formatted string instead of writing directly to console, allowing for more flexible usage.

-    public static void PrintGetDialog(V1ServiceOwnerDialogsQueriesGet_Dialog dialog)
+    public static string FormatDialog(V1ServiceOwnerDialogsQueriesGet_Dialog dialog)
     {
-        Console.WriteLine($"System Label: {dialog.SystemLabel}");
-        Console.WriteLine($"Dialog Status: {dialog.Status}");
-        Console.WriteLine($"Dialog Org: {dialog.Org}");
-        Console.WriteLine($"Dialog Progress: {dialog.Progress}");
-        Console.WriteLine($"Deleted at: {dialog.DeletedAt}");
+        return string.Join(Environment.NewLine,
+            $"System Label: {dialog.SystemLabel}",
+            $"Dialog Status: {dialog.Status}",
+            $"Dialog Org: {dialog.Org}",
+            $"Dialog Progress: {dialog.Progress}",
+            $"Deleted at: {dialog.DeletedAt}");
     }

6-6: Consider adding XML documentation for the Dialogs class.

Since this is a sample implementation, documentation would help users understand its purpose and usage.

+/// <summary>
+/// Sample implementation demonstrating usage of the Dialogporten Service Owner API.
+/// </summary>
 public sealed class Dialogs(IServiceownerApi client)
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/RefitterInterfaceTests.cs (1)

26-35: Improve solution root folder detection

The current implementation silently returns null if no solution file is found. Consider throwing an exception with a meaningful message.

     private static string? GetSolutionRootFolder()
     {
         var currentDirectory = Directory.GetCurrentDirectory();
         var solutionFolder = currentDirectory;
         while (solutionFolder != null && Directory.GetFiles(solutionFolder, "*.sln").Length == 0)
         {
             solutionFolder = Directory.GetParent(solutionFolder)?.FullName;
         }
-        return solutionFolder;
+        return solutionFolder ?? throw new InvalidOperationException("Could not find solution root folder. Ensure the test is running from within the solution directory.");
     }
.github/workflows/workflow-publish-nuget.yml (1)

6-9: Add version format validation

Consider adding a pattern check for the version input to ensure it follows semantic versioning.

       version:
         description: "Version"
         required: true
         type: string
+        pattern: '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests.csproj (1)

11-16: Consider package version alignment

Multiple Microsoft.Extensions packages are used. Consider using a Directory.Packages.props file to manage versions centrally.

This would help maintain consistency across the solution and make updates easier.

src/Digdir.Library.Dialogporten.WebApiClient/README.md (2)

4-4: Format URL as a proper Markdown link

The URL should be properly formatted as a Markdown link for better readability and maintainability.

-Refit-based client SDK Based on https://github.com/altinn/altinn-apiclient-maskinporten
+Refit-based client SDK Based on [Altinn API Client Maskinporten](https://github.com/altinn/altinn-apiclient-maskinporten)
🧰 Tools
🪛 Markdownlint (0.37.0)

4-4: null
Bare URL used

(MD034, no-bare-urls)


1-205: Enhance documentation with additional sections

The README provides good setup and usage examples but could benefit from additional sections:

  • Error handling and exceptions
  • Rate limiting and throttling
  • Authentication and authorization details
  • API versioning
  • Troubleshooting guide

Would you like me to help generate content for these sections?

🧰 Tools
🪛 Markdownlint (0.37.0)

4-4: null
Bare URL used

(MD034, no-bare-urls)

.github/workflows/ci-cd-staging.yml (1)

102-102: Improve project path handling

Using find command directly in the path parameter could be fragile. Consider moving this logic to the reusable workflow or using a predefined path.

-      path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p"  -quit)
+      path: 'src/Digdir.Library.Dialogporten.WebApiClient/Digdir.Library.Dialogporten.WebApiClient.csproj'
.github/workflows/ci-cd-pull-request.yml (3)

6-8: Consider keeping CHANGELOG.md in paths-ignore

The removal of CHANGELOG.md from paths-ignore means the workflow will run even when only the changelog is modified. This could lead to unnecessary workflow runs since changelog updates typically don't require CI/CD validation.

paths-ignore:
  - "tests/k6/**"
+ - "CHANGELOG.md"

21-21: Remove trailing spaces

There are trailing spaces on these lines that should be removed for consistency.

Also applies to: 26-26, 37-37

🧰 Tools
🪛 yamllint (1.35.1)

[error] 21-21: trailing spaces

(trailing-spaces)


Job dependencies need to be updated for complete workflow integrity

The verification revealed some inconsistencies in the job dependencies:

  • dry-run-deploy-infra depends on build-infrastructure, but build-infrastructure only depends on check-for-changes
  • dry-run-deploy-apps depends on dry-run-deploy-infra, but it should also include build-infrastructure in its dependency chain
  • Both deployment jobs use outputs from generate-git-short-sha and get-current-version, but these jobs aren't properly included in the dependency chain of build-infrastructure

To ensure workflow integrity:

  • Add generate-git-short-sha and get-current-version to build-infrastructure job's needs array
  • Update dry-run-deploy-apps to include build-infrastructure in its needs array when infrastructure changes are detected
🔗 Analysis chain

Line range hint 38-98: LGTM! Well-structured job dependencies and conditions

The job dependency chain and conditional execution logic is well thought out:

  • Infrastructure deployment is properly gated by change detection
  • App deployment handles both infrastructure-dependent and independent scenarios
  • Failure conditions are properly handled with always() and !failure()

Let's verify the job dependencies are complete:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all referenced jobs exist and are properly connected

# Check for any jobs referenced in needs that aren't defined
rg -o 'needs:.*\[(.*)\]' | tr ',' '\n' | tr -d '[]' | tr -d ' ' > needed_jobs.txt
rg '^[[:space:]]*\w+:' | cut -d':' -f1 | tr -d ' ' > defined_jobs.txt
comm -23 needed_jobs.txt defined_jobs.txt

# Check for jobs that might be missing from delete-github-deployments needs
rg -A 5 'dry-run-deploy' | grep 'name:'

Length of output: 291


Script:

#!/bin/bash
# Let's try a different approach to verify job dependencies
# First, let's get all defined jobs
rg '^\s+\w+:' .github/workflows/ci-cd-pull-request.yml

# Then, let's get all job dependencies
rg 'needs:.*\[.*\]' .github/workflows/ci-cd-pull-request.yml

# And finally, let's check the specific jobs mentioned in the needs section
rg '^\s+(generate-git-short-sha|check-for-changes|get-current-version|build-infrastructure|dry-run-deploy-infra|dry-run-deploy-apps):' .github/workflows/ci-cd-pull-request.yml

Length of output: 4045

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86a8680 and b952394.

📒 Files selected for processing (23)
  • .github/workflows/ci-cd-main.yml (6 hunks)
  • .github/workflows/ci-cd-pull-request.yml (3 hunks)
  • .github/workflows/ci-cd-staging.yml (10 hunks)
  • .github/workflows/workflow-publish-nuget.yml (1 hunks)
  • .refitter (1 hunks)
  • Digdir.Domain.Dialogporten.sln (3 hunks)
  • docs/schema/V1/swagger.verified.json (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient.Sample/Dialogs.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient.Sample/Digdir.Library.Dialogporten.WebApiClient.Sample.csproj (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient.Sample/Program.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient.Sample/appsettings.json (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Config/DialogportenSettings.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Config/MaskinportenSettings.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Digdir.Library.Dialogporten.WebApiClient.csproj (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Extensions/ServiceCollectionExtensions.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IDialogportenSettings.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Interfaces/IIdentifiable.cs (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/README.md (1 hunks)
  • src/Digdir.Library.Dialogporten.WebApiClient/Services/DialogTokenVerifier.cs (1 hunks)
  • tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/.refitter (1 hunks)
  • tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests.csproj (1 hunks)
  • tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/RefitterInterfaceTests.cs (1 hunks)
  • tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/Tests.cs (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • .refitter
  • src/Digdir.Library.Dialogporten.WebApiClient.Sample/Digdir.Library.Dialogporten.WebApiClient.Sample.csproj
  • src/Digdir.Library.Dialogporten.WebApiClient/Config/MaskinportenSettings.cs
  • tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/.refitter
🧰 Additional context used
📓 Learnings (1)
src/Digdir.Library.Dialogporten.WebApiClient.Sample/appsettings.json (2)
Learnt from: elsand
PR: digdir/dialogporten#1182
File: src/Digdir.Domain.Dialogporten.Janitor/appsettings.staging.json:4-4
Timestamp: 2024-11-12T05:32:45.311Z
Learning: In this project, "TODO: Add to local secrets" placeholders in configuration files are intentionally used to ensure that missing configurations fail fast and loud. These settings are overridden by Azure app configuration mechanisms, as documented in `docs/Configuration.md`.
Learnt from: MagnusSandgren
PR: digdir/dialogporten#1277
File: src/Digdir.Domain.Dialogporten.Service/appsettings.staging.json:9-23
Timestamp: 2024-11-12T05:32:45.311Z
Learning: In this project, the scopes defined in `appsettings.staging.json` (such as `altinn:events.publish`, `altinn:events.publish.admin`, `altinn:register/partylookup.admin`, `altinn:authorization/authorize.admin`, and `altinn:accessmanagement/authorizedparties.admin`) are the scopes required by the application from the Altinn platform. The scopes referenced in the code (like `digdir:dialogporten` and `digdir:dialogporten.serviceprovider`) are the scopes required from consumers of the application.
🪛 Markdownlint (0.37.0)
src/Digdir.Library.Dialogporten.WebApiClient/README.md

4-4: null
Bare URL used

(MD034, no-bare-urls)

🪛 Gitleaks (8.21.2)
src/Digdir.Library.Dialogporten.WebApiClient.Sample/Program.cs

33-33: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

🪛 actionlint (1.7.4)
.github/workflows/workflow-publish-nuget.yml

30-30: shellcheck reported issue in this script: SC2086:info:3:30: Double quote to prevent globbing and word splitting

(shellcheck)


41-41: shellcheck reported issue in this script: SC2086:info:1:71: Double quote to prevent globbing and word splitting

(shellcheck)


44-44: shellcheck reported issue in this script: SC2086:info:1:134: Double quote to prevent globbing and word splitting

(shellcheck)


61-61: shellcheck reported issue in this script: SC2035:info:1:19: Use ./glob or -- glob so names with dashes won't become options

(shellcheck)

.github/workflows/ci-cd-staging.yml

97-97: secret "NUGET_API_KEY" is required by "./.github/workflows/workflow-publish-nuget.yml" reusable workflow

(workflow-call)


104-104: secret "NUGET_API_TEST_KEY" is not defined in "./.github/workflows/workflow-publish-nuget.yml" reusable workflow. defined secret is "NUGET_API_KEY"

(workflow-call)

🪛 yamllint (1.35.1)
.github/workflows/workflow-publish-nuget.yml

[error] 62-62: trailing spaces

(trailing-spaces)

.github/workflows/ci-cd-main.yml

[error] 120-120: trailing spaces

(trailing-spaces)

.github/workflows/ci-cd-staging.yml

[error] 105-105: trailing spaces

(trailing-spaces)

.github/workflows/ci-cd-pull-request.yml

[error] 21-21: trailing spaces

(trailing-spaces)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 37-37: trailing spaces

(trailing-spaces)

🔇 Additional comments (8)
src/Digdir.Library.Dialogporten.WebApiClient/Digdir.Library.Dialogporten.WebApiClient.csproj (2)

27-28: Verify the purpose of compilation exclusions

The exclusion of Program.cs and *.received.cs files suggests:

  1. This is a library project (hence no Program.cs needed)
  2. Approval tests might be in use (*.received.cs files)

Please confirm if these exclusions are intentional and if approval tests are being used for testing.

Let's check for approval test setup:

✅ Verification successful

Let me verify if approval tests are being used by checking for approval test packages and test files.


Let me check the specific project's test setup and verify if it's using approval tests.


Compilation exclusions are correctly configured

The exclusions are intentional and serve specific purposes:

  1. Program.cs exclusion is correct as this is a library project (WebApiClient)
  2. *.received.cs exclusion is for approval testing, specifically used in the RefitterInterfaceTests which generates and verifies interface files using the Verify testing tool
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for approval test packages
rg -l "ApprovalTests" 

# Check for actual test files
fd -e cs -e approved -e received . src/

Length of output: 50953


Script:

#!/bin/bash
# Search for approval test package references in csproj files
rg -l "ApprovalTests" --type csproj

# Search for received/approved files
fd -e received.cs -e approved.cs . src/

# Check for test files that might use approval tests
rg -l "Verify\(" --type cs

Length of output: 828


Script:

#!/bin/bash
# Check for test project associated with the WebApiClient
fd -e csproj . tests/ | grep -i "WebApiClient"

# Look for test files in the WebApiClient project
rg -l "Test" tests/.*WebApiClient.*

# Check content of the RefitterInterfaceTests.cs which seems to use Verify
cat tests/Digdir.Library.Dialogporten.WebApiClient.Integration.Tests/RefitterInterfaceTests.cs

Length of output: 1823


16-16: Verify security vulnerabilities in Maskinporten package

Based on previous comments, version 9.2.1 had known security vulnerabilities related to JWT packages. Version 9.2.0 might have the same issues.

Let's check the dependencies and vulnerabilities:

src/Digdir.Library.Dialogporten.WebApiClient/Services/DialogTokenVerifier.cs (1)

8-8: ⚠️ Potential issue

Incorrect class constructor syntax

Defining a class with constructor parameters directly after the class name is not supported in C#. To properly initialize the class with parameters, you should define a constructor inside the class body.

Apply this diff to fix the syntax:

-public sealed class DialogTokenVerifier(string kid, PublicKey publicKey)
+public sealed class DialogTokenVerifier
+{
+    private readonly string _kid;
+    private readonly PublicKey _publicKey;
+
+    public DialogTokenVerifier(string kid, PublicKey publicKey)
+    {
+        _kid = kid;
+        _publicKey = publicKey;
+    }

Remember to update references in the class to use _kid and _publicKey instead of kid and publicKey.

Likely invalid or redundant comment.

src/Digdir.Library.Dialogporten.WebApiClient/Extensions/ServiceCollectionExtensions.cs (1)

49-55: Verify environment mapping for Maskinporten settings

In the environment mapping for Maskinporten settings, "local" is mapped to "test". Ensure that this mapping aligns with your deployment environments and that it does not cause unintended behavior.

Please confirm that mapping "local" to "test" is correct. If "local" should have distinct settings, update the mapping accordingly.

src/Digdir.Library.Dialogporten.WebApiClient.Sample/Dialogs.cs (1)

1-24: Add unit tests for the Dialogs class.

According to the PR objectives, no tests have been added. Consider adding unit tests to verify the behavior of the Purge method and dialog formatting.

.github/workflows/ci-cd-main.yml (1)

111-120: LGTM! Consider making the environment variable name environment-agnostic.

The new publish-sdk-to-nuget job is well-structured with appropriate dependencies. However, the environment variable NUGET_API_TEST_KEY could be renamed to just NUGET_API_KEY to make it environment-agnostic, as suggested in a previous review comment.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 120-120: trailing spaces

(trailing-spaces)

Digdir.Domain.Dialogporten.sln (1)

70-77: LGTM! Well-structured solution organization.

The solution changes follow best practices:

  • Clear separation of concerns with WebApiClient in Libraries folder
  • Sample project included for documentation/examples
  • Integration tests properly placed in tests folder
  • Project naming follows established conventions

Also applies to: 176-187, 219-222

docs/schema/V1/swagger.verified.json (1)

Line range hint 1-6973: LGTM! Comprehensive and well-documented API specification.

The OpenAPI specification is thorough and follows best practices:

  • Clear endpoint descriptions and examples
  • Proper security scheme definitions
  • Complete schema definitions with descriptions
  • Consistent error response handling

/// <summary>
/// ClientID to use
/// </summary>
string ClientId { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making properties immutable.

Configuration properties should typically be immutable after initialization to prevent unexpected runtime changes. Consider removing the setters and initializing values through constructor injection.

-    string ClientId { get; set; }
+    string ClientId { get; }

-    string Scope { get; set; }
+    string Scope { get; }

-    string Resource { get; set; }
+    string Resource { get; }

-    string Environment { get; set; }
+    string Environment { get; }

-    string EncodedJwk { get; set; }
+    string EncodedJwk { get; }

Also applies to: 13-13, 18-18, 23-23, 28-28

Comment on lines +25 to +28
/// <summary>
/// Base64 Encoded Json Web Key
/// </summary>
string EncodedJwk { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Mark sensitive data and improve security documentation.

The EncodedJwk property contains sensitive cryptographic material. Consider:

  1. Adding security-related XML comments
  2. Using a secure string type or marking it as sensitive
  3. Adding validation requirements in the documentation
 /// <summary>
-/// Base64 Encoded Json Web Key 
+/// Base64 Encoded Json Web Key. This is sensitive cryptographic material that should be stored securely.
 /// </summary>
+/// <remarks>
+/// Security considerations:
+/// - Store this value in a secure configuration store or key vault
+/// - Ensure the value is properly Base64 encoded
+/// - Protect this value in memory and logs
+/// </remarks>
 string EncodedJwk { get; set; }
📝 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.

Suggested change
/// <summary>
/// Base64 Encoded Json Web Key
/// </summary>
string EncodedJwk { get; set; }
/// <summary>
/// Base64 Encoded Json Web Key. This is sensitive cryptographic material that should be stored securely.
/// </summary>
/// <remarks>
/// Security considerations:
/// - Store this value in a secure configuration store or key vault
/// - Ensure the value is properly Base64 encoded
/// - Protect this value in memory and logs
/// </remarks>
string EncodedJwk { get; set; }

Comment on lines +20 to +23
/// <summary>
/// The Maskinporten environment. Valid values are ver1, ver2, test or prod
/// </summary>
string Environment { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use enum for Environment property.

Instead of using a string for environment values, consider using an enum to enforce valid values at compile-time.

+/// <summary>
+/// Represents the available Maskinporten environments.
+/// </summary>
+public enum MaskinportenEnvironment
+{
+    /// <summary>
+    /// Version 1 environment
+    /// </summary>
+    Ver1,
+    
+    /// <summary>
+    /// Version 2 environment
+    /// </summary>
+    Ver2,
+    
+    /// <summary>
+    /// Test environment
+    /// </summary>
+    Test,
+    
+    /// <summary>
+    /// Production environment
+    /// </summary>
+    Prod
+}

 /// <summary>
 /// The Maskinporten environment. Valid values are ver1, ver2, test or prod
 /// </summary>
-string Environment { get; set; }
+MaskinportenEnvironment Environment { get; }
📝 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.

Suggested change
/// <summary>
/// The Maskinporten environment. Valid values are ver1, ver2, test or prod
/// </summary>
string Environment { get; set; }
/// <summary>
/// Represents the available Maskinporten environments.
/// </summary>
public enum MaskinportenEnvironment
{
/// <summary>
/// Version 1 environment
/// </summary>
Ver1,
/// <summary>
/// Version 2 environment
/// </summary>
Ver2,
/// <summary>
/// Test environment
/// </summary>
Test,
/// <summary>
/// Production environment
/// </summary>
Prod
}
/// <summary>
/// The Maskinporten environment. Valid values are ver1, ver2, test or prod
/// </summary>
MaskinportenEnvironment Environment { get; }

var fieldsInfo = typeof(DialogTokenClaimTypes).GetFields().Where(f => f.FieldType == typeof(string));
foreach (var fieldInfo in fieldsInfo)
{
var value = fieldInfo.GetValue("string");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect usage of GetValue method in reflection

When retrieving the value of a static field using reflection, you should pass null to GetValue since there is no instance associated with static members. Passing "string" is incorrect and will lead to unexpected behavior.

Apply this diff to correct the method call:

-var value = fieldInfo.GetValue("string");
+var value = fieldInfo.GetValue(null);
📝 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.

Suggested change
var value = fieldInfo.GetValue("string");
var value = fieldInfo.GetValue(null);

return false;
}
var signature = Base64Url.DecodeFromChars(parts[2]);
return SignatureAlgorithm.Ed25519.Verify(publicKey, Encoding.UTF8.GetBytes(parts[0] + '.' + parts[1]), signature);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle potential exceptions during signature verification

The SignatureAlgorithm.Ed25519.Verify method may throw exceptions if the inputs are invalid or if an error occurs during verification. To ensure the Verify method in your class returns false instead of allowing an exception to propagate, consider wrapping the call in a try-catch block.

Modify the method as follows:

-var signature = Base64Url.DecodeFromChars(parts[2]);
-return SignatureAlgorithm.Ed25519.Verify(publicKey, Encoding.UTF8.GetBytes(parts[0] + '.' + parts[1]), signature);
+try
+{
+    var signature = Base64Url.DecodeFromChars(parts[2]);
+    return SignatureAlgorithm.Ed25519.Verify(_publicKey, Encoding.UTF8.GetBytes(parts[0] + '.' + parts[1]), signature);
+}
+catch
+{
+    return false;
+}

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +41 to +44
run: dotnet build --configuration Release /p:Version=${{ inputs.version }} ${PROJECT}

- name: Pack with debug symbols
run: dotnet pack --configuration Release /p:Version=${{ inputs.version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . ${PROJECT}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix command argument quoting

The project path needs proper quoting in dotnet commands.

-        run: dotnet build --configuration Release /p:Version=${{ inputs.version }} ${PROJECT}
+        run: dotnet build --configuration Release /p:Version="${{ inputs.version }}" "${PROJECT}"

-        run: dotnet pack --configuration Release /p:Version=${{ inputs.version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . ${PROJECT}
+        run: dotnet pack --configuration Release /p:Version="${{ inputs.version }}" -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . "${PROJECT}"
📝 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.

Suggested change
run: dotnet build --configuration Release /p:Version=${{ inputs.version }} ${PROJECT}
- name: Pack with debug symbols
run: dotnet pack --configuration Release /p:Version=${{ inputs.version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . ${PROJECT}
run: dotnet build --configuration Release /p:Version="${{ inputs.version }}" "${PROJECT}"
- name: Pack with debug symbols
run: dotnet pack --configuration Release /p:Version="${{ inputs.version }}" -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . "${PROJECT}"
🧰 Tools
🪛 actionlint (1.7.4)

41-41: shellcheck reported issue in this script: SC2086:info:1:71: Double quote to prevent globbing and word splitting

(shellcheck)


44-44: shellcheck reported issue in this script: SC2086:info:1:134: Double quote to prevent globbing and word splitting

(shellcheck)

Comment on lines +30 to +34
run: |
PROJECT=${{inputs.path}}
echo "PROJECT ${PROJECT}"
echo "PROJECT=${PROJECT}" >> $GITHUB_ENV

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix shell script quoting

The PROJECT variable assignment needs proper quoting to handle paths with spaces.

-          PROJECT=${{inputs.path}}
+          PROJECT="${{inputs.path}}"
           echo "PROJECT ${PROJECT}"
-          echo "PROJECT=${PROJECT}" >> $GITHUB_ENV
+          echo "PROJECT=${PROJECT}" >> "$GITHUB_ENV"
📝 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.

Suggested change
run: |
PROJECT=${{inputs.path}}
echo "PROJECT ${PROJECT}"
echo "PROJECT=${PROJECT}" >> $GITHUB_ENV
run: |
PROJECT="${{inputs.path}}"
echo "PROJECT ${PROJECT}"
echo "PROJECT=${PROJECT}" >> "$GITHUB_ENV"
🧰 Tools
🪛 actionlint (1.7.4)

30-30: shellcheck reported issue in this script: SC2086:info:3:30: Double quote to prevent globbing and word splitting

(shellcheck)

Comment on lines +17 to +25
<!-- New funksjonaliet som ikke har kommet in til preview engang, Compilert lokalt og Hentet fra lokalt Nugetstore -->
<PackageReference Include="Refitter.SourceGenerator" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- <PackageReference Include="Refitter.SourceGenerator" Version="1.4.1">-->
<!-- <PrivateAssets>all</PrivateAssets>-->
<!-- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
<!-- </PackageReference>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address Refitter dependency management

The current setup uses a locally built version of Refitter, which could cause build issues for other developers. Consider:

  1. Publishing the required Refitter version to a shared feed
  2. Adding documentation for local build setup
  3. Removing commented out code

Would you like me to help create a setup guide for building and using Refitter locally?

Comment on lines +5 to +7
"ClientId": "ce3b732a-d4f2-4997-8545-adf8df70fe6c",
"Scope": "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search",
"EncodedJwk": "eyJwIjoieTRBZEhlVVBxdFEtSFlOWkR5ci0zS09RT3NQajA5TFh2a2hIUFlTdGFYNThkMndIWUJiVXlDTWdMYWtGTHo4UExKNWtscURsanRoczFtM1dFVGJhSWVuY25TalpjZTh4S1Q2SHh3bTNyaDlydWZ1TWVOZDRqaFptTm9WZmJrcGNXcVh0UDFvb1NPTE5zYUNVUWFUUEVKTXlFd3VhdWxMSzgxRG1SSTlMSmVNIiwia3R5IjoiUlNBIiwicSI6InFmOEQ2Uy1Kd19BdVQ0Q2hjQTlDek9WNk1uTW9mc1VCdTkteHJBcVFDRjh4WWZZOTRxQ1ZjQ3llajlkTlN3eXZUZXg1dThIMzNSaU1LMEFWM2tTQlpJLVZqcXJHLUx6YzNfTUlTTVpSVDJfbzNVQlRWVHpqTkUtSkpMX1hKaXJ6ZVhhQjM1UmFZMjFnWVhKQWg3X2tuR3dpRzF3MGxiT2ozQ0FzdnVwaU1BMCIsImQiOiJLVkF1b1Zhd2paTTgwenRYcUxSZUJGZkJ3M3pxVjdkUGFpaWFONWU0RFp6bW5MYTFMNEZJMTgtanVraHN4UVdqR1NFQnBIdTFrOHRPUWMyWjBsSDVaaTBydERqM0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Gt3ckZZdlp0WjBEeHJDYm9Md1hjc0Y3Ukwyejl4LWMwSFBGVFAzLVREQWF6UWlBNVVtRmNwYnAzeDYzWGFLSWFuYnVFc0NiSDdFIiwibiI6Imh5Sks4WnE2Wk8tRjFSSklVWVNCdUpfeG9RWkNNV1EyTVhrSFQ1bVROVVJJZmVWWWpCNWMwMzI0Uk5nc3ZPMEtXX0hUejRRSnptLV9rU1VaZ0h1Z2JoR0F3a1Vqc1lwTlJJRTBvLVNtdEExMlMxZHVCZWx6ajg2LVFrZkFzeFlwblNnSzl5OXpTS1B0YVlzMS1EcEVIb0hVdk9BSDJlNktFTXRaYUZPM0J0Yk9WUURXMENMYi1FY0UyaDBQRlFMMUp3NU8zeDhHcXBZeUFhamNoWnptcWlFbjBaSEd1QTNZZ1NyNGxQV1lkTzBNWHZmRFdyaFBTcnVTS3FodzBHMTlBRUpHOFhoek9xTWxLTUFIbW5ybk9XOHM2cWR2Sy1UQ1BiVGJJOU5XUWdFd2JpUFBBdlU0MUFITzZmTEYxUHZzQ3FhNjZTSGdYMkJzS3pvNVhORjhodyJ9"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Remove sensitive information from sample configuration

The configuration file contains actual sensitive values including a ClientId and an EncodedJwk with private key components. This poses a security risk as these credentials could be misused.

Replace the sensitive values with placeholders:

-      "ClientId": "ce3b732a-d4f2-4997-8545-adf8df70fe6c",
-      "Scope": "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search",
-      "EncodedJwk": "eyJwIjoieTRBZEhlVVBxdFEtSFlOWkR5ci0zS09RT3NQajA5TFh2a2hIUFlTdGFYNThkMndIWUJiVXlDTWdMYWtGTHo4UExKNWtscURsanRoczFtM1dFVGJhSWVuY25TalpjZTh4S1Q2SHh3bTNyaDlydWZ1TWVOZDRqaFptTm9WZmJrcGNXcVh0UDFvb1NPTE5zYUNVUWFUUEVKTXlFd3VhdWxMSzgxRG1SSTlM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️ 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.

Suggested change
"ClientId": "ce3b732a-d4f2-4997-8545-adf8df70fe6c",
"Scope": "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search",
"EncodedJwk": "eyJwIjoieTRBZEhlVVBxdFEtSFlOWkR5ci0zS09RT3NQajA5TFh2a2hIUFlTdGFYNThkMndIWUJiVXlDTWdMYWtGTHo4UExKNWtscURsanRoczFtM1dFVGJhSWVuY25TalpjZTh4S1Q2SHh3bTNyaDlydWZ1TWVOZDRqaFptTm9WZmJrcGNXcVh0UDFvb1NPTE5zYUNVUWFUUEVKTXlFd3VhdWxMSzgxRG1SSTlMSmVNIiwia3R5IjoiUlNBIiwicSI6InFmOEQ2Uy1Kd19BdVQ0Q2hjQTlDek9WNk1uTW9mc1VCdTkteHJBcVFDRjh4WWZZOTRxQ1ZjQ3llajlkTlN3eXZUZXg1dThIMzNSaU1LMEFWM2tTQlpJLVZqcXJHLUx6YzNfTUlTTVpSVDJfbzNVQlRWVHpqTkUtSkpMX1hKaXJ6ZVhhQjM1UmFZMjFnWVhKQWg3X2tuR3dpRzF3MGxiT2ozQ0FzdnVwaU1BMCIsImQiOiJLVkF1b1Zhd2paTTgwenRYcUxSZUJGZkJ3M3pxVjdkUGFpaWFONWU0RFp6bW5MYTFMNEZJMTgtanVraHN4UVdqR1NFQnBIdTFrOHRPUWMyWjBsSDVaaTBydERqM0JKeEhxeDNsUGdYMWdTNXNiX1EyeXNfb2FKcklSX012MHBDQUFHX3hpa2lUY2kzTHMyeV9femV4QTdLbG0yalNmYW9Udzdhbml1R3RId1d5dHhCSnJnZ0J2c3loaHZIaUVQcnZaMHZBZldYYWI3QUtkUjc1cEtEaVVHOGdGNTdJN0hrWnpJSk9QYXp3MTU1Skx4TG9HcDVzeTFCVVpBNHRiQmlseWVsdG9ONGZINWd1aUktOXJjTE5zUmVYaz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JJRTBvLVNtdEExMlMxZHVCZWx6ajg2LVFrZkFzeFlwblNnSzl5OXpTS1B0YVlzMS1EcEVIb0hVdk9BSDJlNktFTXRaYUZPM0J0Yk9WUURXMENMYi1FY0UyaDBQRlFMMUp3NU8zeDhHcXBZeUFhamNoWnptcWlFbjBaSEd1QTNZZ1NyNGxQV1lkTzBNWHZmRFdyaFBTcnVTS3FodzBHMTlBRUpHOFhoek9xTWxLTUFIbW5ybk9XOHM2cWR2Sy1UQ1BiVGJJOU5XUWdFd2JpUFBBdlU0MUFITzZmTEYxUHZzQ3FhNjZTSGdYMkJzS3pvNVhORjhodyJ9"
"ClientId": "<your-client-id>",
"Scope": "<required-scopes>",
"EncodedJwk": "<your-encoded-jwk>"

Comment on lines 96 to 104
publish-sdk-to-nuget:
uses: ./.github/workflows/workflow-publish-nuget.yml
needs: [ get-current-version, check-for-changes ]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}
with:
version: ${{ needs.get-current-version.outputs.version }}
path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p" -quit)
secrets:
NUGET_API_TEST_KEY: ${{ secrets.NUGET_API_TEST_KEY }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix secret name mismatch in workflow

The workflow uses NUGET_API_TEST_KEY but the reusable workflow expects NUGET_API_KEY.

-      NUGET_API_TEST_KEY: ${{ secrets.NUGET_API_TEST_KEY }}
+      NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
📝 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.

Suggested change
publish-sdk-to-nuget:
uses: ./.github/workflows/workflow-publish-nuget.yml
needs: [ get-current-version, check-for-changes ]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}
with:
version: ${{ needs.get-current-version.outputs.version }}
path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p" -quit)
secrets:
NUGET_API_TEST_KEY: ${{ secrets.NUGET_API_TEST_KEY }}
publish-sdk-to-nuget:
uses: ./.github/workflows/workflow-publish-nuget.yml
needs: [ get-current-version, check-for-changes ]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}
with:
version: ${{ needs.get-current-version.outputs.version }}
path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p" -quit)
secrets:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
🧰 Tools
🪛 actionlint (1.7.4)

97-97: secret "NUGET_API_KEY" is required by "./.github/workflows/workflow-publish-nuget.yml" reusable workflow

(workflow-call)


104-104: secret "NUGET_API_TEST_KEY" is not defined in "./.github/workflows/workflow-publish-nuget.yml" reusable workflow. defined secret is "NUGET_API_KEY"

(workflow-call)

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Outside diff range and nitpick comments (1)
.github/workflows/ci-cd-staging.yml (1)

105-105: Remove trailing whitespace

Remove trailing spaces on line 105.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 105-105: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b952394 and 8d6b5c0.

📒 Files selected for processing (1)
  • .github/workflows/ci-cd-staging.yml (10 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/ci-cd-staging.yml

[error] 105-105: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
.github/workflows/ci-cd-staging.yml (3)

23-23: LGTM: Improved job dependency formatting

The reformatting of needs arrays improves readability while maintaining functionality.

Also applies to: 36-36, 53-53, 67-67, 77-77, 108-108, 120-120, 136-136, 148-148, 163-163


104-104: ⚠️ Potential issue

Fix secret name mismatch in workflow

The workflow uses NUGET_API_TEST_KEY but the reusable workflow expects NUGET_API_KEY.

-      NUGET_API_KEY: ${{ secrets.NUGET_API_TEST_KEY }}
+      NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

96-104: Verify Refitter dependency handling

Since this package depends on Refitter which isn't available in the preview version, we should verify that the package can be built and published successfully in the CI environment.

Comment on lines +96 to +104
publish-sdk-to-nuget:
uses: ./.github/workflows/workflow-publish-nuget.yml
needs: [ get-current-version, check-for-changes ]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}
with:
version: ${{ needs.get-current-version.outputs.version }}
path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p" -quit)
secrets:
NUGET_API_KEY: ${{ secrets.NUGET_API_TEST_KEY }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve robustness of project file path resolution

The current implementation has several potential issues:

  1. The $(find ...) command is embedded in the path parameter and uses shell syntax that might not work consistently in GitHub Actions
  2. The pattern could match multiple files if there are test projects with similar names

Consider using a dedicated step to find the project file:

  publish-sdk-to-nuget:
    uses: ./.github/workflows/workflow-publish-nuget.yml
    needs: [ get-current-version, check-for-changes ]
    if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}
+   run: |
+     PROJECT_PATH=$(find . -name "Digdir.Library.Dialogporten.WebApiClient.csproj" -not -path "*/test/*" -print -quit)
+     echo "PROJECT_PATH=$PROJECT_PATH" >> $GITHUB_ENV
    with:
      version: ${{ needs.get-current-version.outputs.version }}
-     path: $(find . -name '*Digdir.Library.Dialogporten.WebApiClient.csproj' -printf "%p"  -quit)
+     path: ${{ env.PROJECT_PATH }}
    secrets:
      NUGET_API_KEY: ${{ secrets.NUGET_API_TEST_KEY }}

This approach:

  1. Uses a dedicated step for path resolution
  2. Excludes test projects using -not -path "*/test/*"
  3. Stores the result in an environment variable
  4. Fails fast if the project file is not found

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants