diff --git a/.gitattributes b/.gitattributes index 538c95f55..5cfb8610b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,9 @@ # If there are abnormal line endings in any file, run "git add --renormalize ", # review the changes, and commit them to fix the line endings. * text=auto + +# Third-party library files should not have line endings normalized +**/wwwroot/lib/** -text +*.min.css -text +*.min.js -text +*.map -text diff --git a/.github/code-gen-instructions.md b/.github/code-gen-instructions.md new file mode 100644 index 000000000..edddb668b --- /dev/null +++ b/.github/code-gen-instructions.md @@ -0,0 +1,93 @@ +# AppConfiguration-DotnetProvider Coding Guidelines + +This document outlines coding guidelines for the Azure App Configuration .NET Provider repository. Follow these guidelines when generating or modifying code. + +## General Guidelines + +1. **Exception Handling**: + * When adding error handling, always catch specific exceptions and avoid catching the base `Exception` class in catch blocks. + * Throw specific exception types (e.g., `ArgumentNullException`, `FormatException`, custom exceptions) rather than generic `System.Exception`. + * Include the parameter name when throwing `ArgumentNullException` using `nameof()`. + +2. **Variable Declaration**: + * Never use `var` to declare a variable if the assignment doesn't include the type or the type isn't immediately obvious. + * Use explicit type names for fields, properties, method parameters, and return types. + * Use `var` only when the type is obvious from the right-hand side (e.g., `var user = new User();`). + +3. **Null Handling**: + * Validate arguments in public methods and constructors with explicit null checks. + * Use explicit `if (argument == null) throw new ArgumentNullException(nameof(argument));` checks at the beginning of methods/constructors. + * Avoid using the null-forgiving operator (`!`) unless absolutely necessary. + +4. **Asynchronous Programming**: + * All async methods should accept a `CancellationToken` as the last parameter. + * Pass the `cancellationToken` down the call stack to all subsequent asynchronous operations. + * Use `Task` or `Task` for asynchronous methods. + +5. **LINQ and Collections**: + * Prefer simple, readable LINQ queries. + * Break down complex LINQ queries into separate statements with intermediate variables. + * Use collection interfaces (e.g., `IList`, `IReadOnlyList`) in parameter and return types. + +6. **Resource Management**: + * Wrap `IDisposable` instances in `using` statements to ensure proper disposal. + * Implement `IDisposable` correctly if your class manages disposable objects. + +7. **Dependency Injection**: + * Use constructor injection for dependencies. + * Store injected dependencies in `private readonly` fields. + * Validate injected dependencies for null in the constructor. + +8. **Naming Conventions**: + * Use `PascalCase` for classes, interfaces, enums, methods, properties, and constants. + * Use `camelCase` for local variables and method parameters. + * Prefix private fields with an underscore (`_`). + * Define constants for error messages and other string literals. + +9. **Comments**: + * Only add comments when it's not obvious what the code is doing. For example, if a variable name is already fairly descriptive, a comment isn't needed explaining its name. + * Add summary comments to public classes and members of those classes. + +## AppConfiguration-Specific Guidelines + +1. **Feature Flag Handling**: + * Validate feature flag data structure before processing. + * Handle different feature flag schemas (Microsoft vs .NET) appropriately. + * Use proper error handling when parsing feature flags with clear error messages. + +2. **Configuration Key-Value Processing**: + * Follow adapter pattern for processing different configuration types. + * Properly handle key-value pairs with appropriate content type detection. + * Use `KeyValuePair` for configuration values. + +3. **Content Type Handling**: + * Validate content types before processing. + * Use appropriate content type constants. + * Check content type using extension methods like `IsFeatureFlag()`. + +4. **JSON Parsing**: + * Use `Utf8JsonReader` for performance-critical JSON parsing. + * Validate JSON structure and provide clear error messages for malformed input. + * Handle JSON token types appropriately with proper error handling. + +5. **Refresh Mechanisms**: + * Implement proper configuration refresh patterns. + * Use sentinel-based refresh mechanisms when appropriate. + * Handle refresh failures gracefully. + +## Performance Considerations + +1. **String Handling**: + * Use `StringBuilder` for concatenating multiple strings. + * Define string constants for recurring strings. + * Use string interpolation instead of string concatenation when appropriate. + +2. **Collections**: + * Initialize collections with estimated capacity when possible. + * Use appropriate collection types for the use case (e.g., `List`, `Dictionary`). + * Avoid unnecessary collection allocations. + +3. **Memory Management**: + * Use `Span` and `ReadOnlySpan` for high-performance scenarios. + * Minimize allocations in performance-critical paths. + * Be mindful of closure allocations in LINQ and lambdas. \ No newline at end of file diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 000000000..29084da31 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,3 @@ +This is the Azure App Configuration .NET Provider codebase. The service abides by coding guidelines specified in the `github/code-gen-instructions.md` file. + +When suggesting code changes, do not modify the files directly. Instead, provide a detailed explanation of the changes you would make and ask for confirmation before editing the files. You may create markdown files to demonstrate the changes you would like to make. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af9b1d227..2928be53e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ on: permissions: security-events: write + id-token: write jobs: build: @@ -40,8 +41,17 @@ jobs: - name: Dotnet Pack run: pwsh pack.ps1 + - name: Azure Login with OIDC + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: Dotnet Test run: pwsh test.ps1 + env: + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Publish Test Results uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index 530af0645..39f97d76a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ # Azure Functions localsettings file local.settings.json +# Integration test secrets +appsettings.Secrets.json + # User-specific files *.suo *.user diff --git a/CodeQL.yml b/CodeQL.yml new file mode 100644 index 000000000..01662492c --- /dev/null +++ b/CodeQL.yml @@ -0,0 +1,10 @@ +path_classifiers: + docs: + # Documentation + - "examples" # Exclude code samples from scan results + library: + # Library code + - "" + generated: + # Generated code + - "" diff --git a/examples/ConfigStoreDemo/Pages/_Layout.cshtml b/examples/ConfigStoreDemo/Pages/_Layout.cshtml index 553e6de60..5da3134b8 100644 --- a/examples/ConfigStoreDemo/Pages/_Layout.cshtml +++ b/examples/ConfigStoreDemo/Pages/_Layout.cshtml @@ -3,15 +3,16 @@ - @ViewData["Title"] - Azure App Configuration Demo - + @ViewData["Title"] - Azure App Configuration Demo - - + + - + -