Skip to content

Commit 21236d5

Browse files
authored
Update Get-CosmosDbEntraIdToken to output correct SecureString - Fixes #511 (#512)
* Add new prompts for GitHub issue creation, specification file generation, and LLM updates; update CosmosDB module requirements and improve README for Entra ID authentication * Enhance specification prompt for Generative AI and update changelog; fix Convert-CosmosDbSecureStringToString for proper pipelining in PowerShell * Update changelog and improve error handling in Get-CosmosDbEntraIdToken; enhance Convert-CosmosDbSecureStringToString parameter handling and add tests for pipeline usage * Update Az.Accounts to 5.0.0 and Az.Resources to 8.0.0 for compatibility with latest features * Update Az.Accounts to 5.1.0 for compatibility with latest features * Update module requirements for Az.Accounts and Az.Resources; enhance verbose logging in Get-CosmosDbEntraIdToken and update localization strings * Refactor Cosmos DB integration tests to remove insecure token conversion; enhance verbose logging for role assignments and context creation * Update module requirements for Az.Accounts to 5.0.0 and Az.Resources to 8.0.0; adjust changelog and README for compatibility
1 parent 6434375 commit 21236d5

14 files changed

+296
-123
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
mode: 'agent'
3+
description: 'Create a GitHub Issue for a feature request using the GitHub Issue template feature_request.yml from a specification file.'
4+
tools: [ "create_issue", "get_issue", "list_issues", "search_issues", "update_issue", "websearch", "codebase", "gitHubRepo", "directory_tree", "read_file", "read_multiple_files", "write_file", "edit_file", "create_directory", "list_directory", "move_file", "search_files", "get_file_info", "list_allowed_directories"]
5+
---
6+
Create a GitHub Issue in this GitHub repo using the `create_issue` tool for a feature request to implement the specification in the spec file [${input:SpecFile}](../spec/${input:SpecFile}) using the GitHub Issue template [feature_request.yml](../ISSUE_TEMPLATE/feature_request.yml).
7+
If the issue already exists, you should update it with the latest information from the spec file.
8+
The specification file contains the details of the feature request, including the problem statement, proposed solution, and any additional context or requirements and should be clearly identified in the GitHub issue title.
9+
The issue should be clear, concise, and structured to facilitate understanding and implementation by the development team.
10+
It should only apply changes that are neccessary to implement the specification file and not any other changes that are not required because they are already implemented.
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mode: 'agent'
33
description: 'Create a new specification file for the solution, optimized for Generative AI consumption'
44
tools: [ "codebase", "read_file", "read_multiple_files", "write_file", "edit_file", "create_directory", "list_directory", "move_file", "search_files", "get_file_info", "list_allowed_directories"]
55
---
6-
Your goal is to create a new specification file for `${input:SpecPurpose}` related to this CosmosDB PowerShel module.
6+
Your goal is to create a new specification file for `${input:SpecPurpose}` for this PowerShell Module for managing and interacting with Azur Comsos DB.
77
The specification file must define the requirements, constraints, and interfaces for the solution components in a manner that is clear, unambiguous, and structured for effective use by Generative AIs. Follow established documentation standards and ensure the content is machine-readable and self-contained.
88
The specification should be saved in the [/spec/](/spec/) directory and named according to the following convention: `[a-z0-9-]+.md`, where the name should be descriptive of the specification's content and starting with the highlevel purpose, which is one of [schema, tool, data, infrastructure, process, architecture, or design].
99
The file should be formatted in well formed Markdown.
@@ -17,13 +17,20 @@ The file should be formatted in well formed Markdown.
1717
- Include examples and edge cases where applicable.
1818
- Ensure the document is self-contained and does not rely on external context.
1919

20-
The specification must follow the template below, ensuring that all sections are filled out appropriately.
20+
The specification must follow the template below, ensuring that all sections are filled out appropriately. The front matter for the MD should be structured correctly as per the example following:
21+
```Markdown
22+
---
23+
title: [Concise Title Describing the Specification's Focus]
24+
version: [Optional: e.g., 1.0, Date]
25+
date_created: [YYYY-MM-DD]
26+
last_updated: [Optional: YYYY-MM-DD]
27+
owner: [Optional: Team/Individual responsible for this spec]
28+
tags: [Optional: List of relevant tags or categories, e.g., `infrastructure`, `process`, `design`, `app` etc]
29+
---
2130

22-
# Specification: [Concise Title Describing the Specification's Focus]
31+
# Introduction
2332

24-
**Version:** [Optional: e.g., 1.0, Date]
25-
**Last Updated:** [Optional: YYYY-MM-DD]
26-
**Owner:** [Optional: Team/Individual responsible for this spec]
33+
[A short concise introduction to the specification and the goal it is intended to achieve.]
2734

2835
## 1. Purpose & Scope
2936

@@ -37,10 +44,12 @@ The specification must follow the template below, ensuring that all sections are
3744

3845
[Explicitly list all requirements, constraints, rules, and guidelines. Use bullet points or tables for clarity.]
3946

40-
* Requirement 1: ...
41-
* Constraint 1: ...
42-
* Guideline 1: ...
43-
* Pattern to follow: ...
47+
- **REQ-001**: [Requirement 1]
48+
- **SEC-001**: [Security Requirement 1]
49+
- **[3 LETTERS]-001**: [Other Requirement 1]
50+
- **CON-001**: [Constraint 1]
51+
- **GUD-001**: [Guideline 1]
52+
- **PAT-001**: [Pattern to follow 1]
4453

4554
## 4. Interfaces & Data Contracts
4655

@@ -62,5 +71,5 @@ The specification must follow the template below, ensuring that all sections are
6271
6372
## 8. Related Specifications / Further Reading
6473
65-
[Link to related spec 1]
66-
[Link to relevant external documentation]
74+
- [Link to related spec 1]
75+
- [Link to relevant external documentation]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Example structure for `llms.txt`:
1919
**Version:** [Optional: e.g., 1.0, Date]
2020
**Last Updated:** [Optional: YYYY-MM-DD]
2121
**Owner:** [Optional: Team/Individual responsible for this solution]
22-
**GitHub Repository:** https://github.com/PlagueHO/azure-ai-foundry-jumpstart
22+
**GitHub Repository:** https://github.com/PlagueHO/CosmosDB
2323
2424
## 1. Purpose & Scope
2525

.vscode/mcp.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"servers": {
3+
"filesystem": {
4+
"command": "npx",
5+
"args": [
6+
"-y",
7+
"@modelcontextprotocol/server-filesystem",
8+
"${input:baseDirectory}"
9+
],
10+
"type": "stdio",
11+
"env": {}
12+
},
13+
"github": {
14+
"command": "npx",
15+
"args": [
16+
"-y",
17+
"@modelcontextprotocol/server-github"
18+
],
19+
"env": {
20+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
21+
}
22+
}
23+
},
24+
"inputs": [
25+
{
26+
"id": "baseDirectory",
27+
"type": "promptString",
28+
"description": "Enter the base directory path for the server"
29+
},
30+
{
31+
"id": "github_token",
32+
"type": "promptString",
33+
"description": "GitHub Personal Access Token",
34+
"password": true
35+
}
36+
]
37+
}

CHANGELOG.md

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed `Get-CosmosDbEntraIdToken` to return the `SecureString` from
13+
the `Get-AzAccessToken` call rather than generating a new `SecureString`
14+
from the `token` property. This was resulting in a `401 Unauthorized error`
15+
when calling any of the dataplane functions that used the Entra ID token -
16+
fixes [Issue #511](https://github.com/PlagueHO/CosmosDB/issues/511)
17+
- Fixed `Convert-CosmosDbSecureStringToString` to include process block so
18+
that pipelining works correctly.
19+
1020
### Changed
1121

22+
- Changed `Get-CosmosDbEntraIdToken` so that if `Get-AzAccessToken` returns a
23+
`null` or empty token, it will throw an exception rather than returning a
24+
`null` or empty string.
1225
- CHORE: Added .Devcontainer and Dependabot configuration files to the repository
1326
to support development in Visual Studio Code with a Docker container.
1427
- CHORE: Updated Pull Request and Issue templates to use YAML forms in the
1528
`.github/ISSUE_TEMPLATE` folder.
16-
- CHORE: Updated `Az.Accounts` to `4.2.0` only in `requirements.psd1` and
29+
- CHORE: Updated `Az.Accounts` to `5.0.0` or above `requirements.psd1` and
1730
`CosmosDB.psd1` - fixes [Issue #509](https://github.com/PlagueHO/CosmosDB/issues/509)
18-
- CHORE: Updated `Az.Resources` to `7.1.0` and above in `requirements.psd1` and
31+
- CHORE: Updated `Az.Resources` to `8.0.0` or above in `requirements.psd1` and
1932
`CosmosDB.psd1` - fixes [Issue #509](https://github.com/PlagueHO/CosmosDB/issues/509)
2033
- CHORE: Added `copilot-instructions.md` to control Copilot suggestions in the
2134
repository. This file is used to provide instructions to Copilot on how to
@@ -83,20 +96,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8396

8497
### Fixed
8598

86-
- Removed unnecessary quotes from README (works without them in PowerShell and is easier to read)
99+
- Removed unnecessary quotes from README (works without them in PowerShell and
100+
is easier to read)
87101
- Modified README to use splats, which is part of the recommended style guide
88-
- Removed Ubuntu-18.04 testing from build pipeline because it is no longer supported by Microsoft
102+
- Removed Ubuntu-18.04 testing from build pipeline because it is no longer
103+
supported by Microsoft
89104
managed Azure DevOps images - Fixes [Issue #473](https://github.com/PlagueHO/CosmosDB/issues/473).
90105
- Added Ubuntu-22.04 testing to build pipeline - Fixes [Issue #474](https://github.com/PlagueHO/CosmosDB/issues/474).
91-
- Removed MacOS-10.15 testing from build pipeline because it is no longer supported by Microsoft
106+
- Removed MacOS-10.15 testing from build pipeline because it is no longer
107+
supported by Microsoft
92108
managed Azure DevOps images - Fixes [Issue #476](https://github.com/PlagueHO/CosmosDB/issues/476).
93109
- Added macOS-12 testing to build pipeline - Fixes [Issue #477](https://github.com/PlagueHO/CosmosDB/issues/477).
94110
- Changed integration tests to deploy Cosmos DB using Bicep.
95-
- Update `requirements.psd1` to install modules `Az.Accounts` 2.19.0 and `Az.Resources` 6.16.2.
96-
- Renamed `New-CosmosDbAuthorizationToken` to `New-CosmosDbAuthorizationHeader` to better indicate
111+
- Update `requirements.psd1` to install modules `Az.Accounts` 2.19.0 and
112+
`Az.Resources` 6.16.2.
113+
- Renamed `New-CosmosDbAuthorizationToken` to `New-CosmosDbAuthorizationHeader`
114+
to better indicate
97115
actual function return type.
98-
- Refactored `Invoke-CosmosDbRequest` to support getting the EntraIdToken property from the context object
99-
and using it for authentication if it is provided. If the Key property is provided, the EntraIdToken property
116+
- Refactored `Invoke-CosmosDbRequest` to support getting the EntraIdToken property
117+
from the context object and using it for authentication if it is provided. If
118+
the Key property is provided, the EntraIdToken property
100119
will take precendence and the key will be ignored.
101120
- Updated CI pipeline to use `PublishCodeCoverageResults@2` task rather than `PublishCodeCoverageResults@1`
102121
task to support the latest version of the task.
@@ -105,24 +124,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
105124

106125
- BREAKING CHANGE: Updated module to require `Az.Accounts` v2.19.0 or newer and `Az.Resources`
107126
v6.16.2 or newer.
108-
- Renamed `New-CosmosDbAuthorizationHeader` to `Get-CosmosDbAuthorizationHeaderFromContext` to better indicate
109-
actual function behaviour.
110-
- Renamed `Get-CosmosDbAuthorizationHeadersFromContext` to `Get-CosmosDbAuthorizationHeaderFromContextResourceToken` to better
111-
indicate actual function behaviour and align naming convention.
112-
- Refactored `Invoke-CosmosDbRequest` to clean up logic to generate the authorization header.
113-
- Added new utillity function `Get-CosmosDbAuthorizationHeaderFromContextEntraId` to generate the authorization
114-
header when an Entra ID Token is provided in the context. This function is used by `Invoke-CosmosDbRequest` to
115-
generate the authorization header when an Entra ID Token is provided.
127+
- Renamed `New-CosmosDbAuthorizationHeader` to `Get-CosmosDbAuthorizationHeaderFromContext`
128+
to better indicate actual function behaviour.
129+
- Renamed `Get-CosmosDbAuthorizationHeadersFromContext` to `Get-CosmosDbAuthorizationHeaderFromContextResourceToken`
130+
to better indicate actual function behaviour and align naming convention.
131+
- Refactored `Invoke-CosmosDbRequest` to clean up logic to generate the authorization
132+
header.
133+
- Added new utillity function `Get-CosmosDbAuthorizationHeaderFromContextEntraId`
134+
to generate the authorization header when an Entra ID Token is provided in the
135+
context. This function is used by `Invoke-CosmosDbRequest` to generate the
136+
authorization header when an Entra ID Token is provided.
116137
- Changed module import process to load the `Az.Accounts` and `Az.Resources` modules
117-
only if they haven't already been loaded to support saving the module and storing in
118-
folders.
138+
only if they haven't already been loaded to support saving the module and storing
139+
in folders.
119140

120141
### Added
121142

122-
- Added support for setting an Entra Id OAuth2 Token in the `New-CosmosDbContext` - Fixes [Issue #479](https://github.com/PlagueHO/CosmosDB/issues/479).
123-
- Added new `Get-CosmosDbEntraIdToken` function that uses `Get-AzAccessToken` to get an Entra Id Token
124-
for use in Cosmos DB requests. This is used by `New-CosmosDbContext` to set the Entra Id Token in the
125-
context object - Fixes [Issue #479](https://github.com/PlagueHO/CosmosDB/issues/479).
143+
- Added support for setting an Entra Id OAuth2 Token in the
144+
`New-CosmosDbContext` - Fixes [Issue #479](https://github.com/PlagueHO/CosmosDB/issues/479).
145+
- Added new `Get-CosmosDbEntraIdToken` function that uses `Get-AzAccessToken` to
146+
get an Entra Id Token
147+
for use in Cosmos DB requests. This is used by `New-CosmosDbContext` to set the
148+
Entra Id Token in the context object - Fixes [Issue #479](https://github.com/PlagueHO/CosmosDB/issues/479).
126149

127150
## [4.7.0] - 2023-01-29
128151

@@ -332,7 +355,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
332355

333356
### Changed
334357

335-
- Improved badge layout in README.MD and removed CodeCov.io badge - fixes [Issue #336](https://github.com/PlagueHO/CosmosDB/issues/336).
358+
- Improved badge layout in README.MD and removed CodeCov.io
359+
badge - fixes [Issue #336](https://github.com/PlagueHO/CosmosDB/issues/336).
336360
- Removed references to Gitter and Gitter badge - fixes [Issue #337](https://github.com/PlagueHO/CosmosDB/issues/337).
337361
- Removed Azure Pipeline daily build YAML because the main
338362
pipeline build YAML will be used instead.
@@ -405,7 +429,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
405429
- Moved CosmosDB namespace class definitions into C# project to be built
406430
into a .NET Standard 2.0 DLL that can be loaded instead of a CS file.
407431
This is to work around a problem with Azure Functions 2.0 where
408-
types can not be compiled in the runtime (see [this issue](https://github.com/Azure/azure-functions-powershell-worker/issues/220)) -
432+
types can not be compiled in the runtime.
433+
See [this issue](https://github.com/Azure/azure-functions-powershell-worker/issues/220) -
409434
fixes [Issue #290](https://github.com/PlagueHO/CosmosDB/issues/290).
410435

411436
## [3.2.4.376] - 2019-05-30
@@ -554,7 +579,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
554579
`*-CosmosDBUserDefinedFunction*` functions - fixes [Issue #216](https://github.com/PlagueHO/CosmosDB/issues/216).
555580
- Improved validation on Account parameter on `*-CosmosDBUserDefinedFunction*` functions.
556581
- Improved validation on Database parameter on `*-CosmosDBUserDefinedFunction*` functions.
557-
- Improved validation on Collection parameter on `*-CosmosDBUserDefinedFunction*` functions.
582+
- Improved validation on Collection parameter on `*-CosmosDBUserDefinedFunction*`
583+
functions.
558584
- Improved validation on User Id parameter on
559585
`*-CosmosDBUser*` functions - fixes [Issue #217](https://github.com/PlagueHO/CosmosDB/issues/217).
560586
- Improved validation on Account parameter on `*-CosmosDBUser*` functions.
@@ -603,16 +629,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
603629
## [2.1.9.95] - 2018-10-21
604630

605631
- Improved unit test reliability on MacOS and Linux.
606-
- Improved unit tests for account functions to include parameter filters on mock assertions.
607-
- Added `Get-CosmosDbAccountConnectionString` function for retrieving the connection strings
608-
of an existing account in Azure - fixes [Issue #163](https://github.com/PlagueHO/CosmosDB/issues/163).
609-
This function is not currently working due to an issue with the Microsoft\DocumentDB provider
610-
in Azure - see [this issue](https://github.com/Azure/azure-powershell/issues/3650) for more information.
611-
- Fixed 'Unable to find type \[Microsoft.PowerShell.Commands.HttpResponseException\]' exception
612-
being thrown in `Invoke-CosmosDbRequest` when error is returned by Cosmos DB in PowerShell 5.x
613-
or earlier - fixes [Issue #186](https://github.com/PlagueHO/CosmosDB/issues/186).
614-
- Split unit and integration test execution in CI process so that integration tests do
615-
not run when unit tests fail - fixes [Issue #184](https://github.com/PlagueHO/CosmosDB/issues/184).
632+
- Improved unit tests for account functions to include parameter filters on mock
633+
assertions.
634+
- Added `Get-CosmosDbAccountConnectionString` function for retrieving the connection
635+
strings of an existing account in Azure - fixes [Issue #163](https://github.com/PlagueHO/CosmosDB/issues/163).
636+
This function is not currently working due to an issue with the Microsoft\DocumentDB
637+
provider in Azure - see [this issue](https://github.com/Azure/azure-powershell/issues/3650)
638+
for more information.
639+
- Fixed 'Unable to find type \[Microsoft.PowerShell.Commands.HttpResponseException\]'
640+
exception being thrown in `Invoke-CosmosDbRequest` when error is returned by CosmosDB
641+
in PowerShell 5.x or earlier - fixes [Issue #186](https://github.com/PlagueHO/CosmosDB/issues/186).
642+
- Split unit and integration test execution in CI process so that integration tests
643+
do not run when unit tests fail - fixes [Issue #184](https://github.com/PlagueHO/CosmosDB/issues/184).
616644

617645
## [2.1.8.59] - 2018-10-03
618646

@@ -623,7 +651,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
623651
- Rework CI process to simplify code.
624652
- Enabled integration test execution in Azure DevOps Pipelines - fixes [Issue #179](https://github.com/PlagueHO/CosmosDB/issues/179)
625653
- Added artifact publish tasks for Azure Pipeline.
626-
- Refactored module deployment process to occur in Azure DevOps pipeline - fixes [Issue #181](https://github.com/PlagueHO/CosmosDB/issues/181)
654+
- Refactored module deployment process to occur in Azure DevOps pipeline -
655+
fixes [Issue #181](https://github.com/PlagueHO/CosmosDB/issues/181)
627656

628657
## [2.1.7.675] - 2018-09-11
629658

@@ -659,12 +688,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
659688

660689
## [2.1.5.548] - 2018-08-04
661690

662-
- Changed references to `CosmosDB` to `Cosmos DB` in documentation - fixes [Issue #147](https://github.com/PlagueHO/CosmosDB/issues/147)
691+
- Changed references to `CosmosDB` to `Cosmos DB` in documentation -
692+
fixes [Issue #147](https://github.com/PlagueHO/CosmosDB/issues/147)
663693

664694
## [2.1.4.536] - 2018-07-25
665695

666696
- Added `RemoveDefaultTimeToLive` switch parameter to `Set-CosmosDbCollection`
667-
to allow removal of a default time to live setting on a collection - fixes [Issue #144](https://github.com/PlagueHO/CosmosDB/issues/144)
697+
to allow removal of a default time to live setting on a collection -
698+
fixes [Issue #144](https://github.com/PlagueHO/CosmosDB/issues/144)
668699

669700
## [2.1.3.528] - 2018-07-12
670701

@@ -714,9 +745,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
714745

715746
- Fix creation of spatial index by `New-CosmosDbCollectionIncludedPathIndex`
716747
so that precision is not used when passing to `New-CosmosDbCollection`.
717-
- Added support for `-PartitionKey` in `Invoke-CosmosDbStoredProcedure` - See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
718-
- Changed -StoredProcedureParameter from string[] to object[] in `Invoke-CosmosDbStoredProcedure` - See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
719-
- Updated `Invoke-CosmosDbStoredProcedure` to set `x-ms-documentdb-script-enable-logging: true` header and write stored procedure logs to the Verbose Stream when `-Debug` is set - See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
748+
- Added support for `-PartitionKey` in `Invoke-CosmosDbStoredProcedure` -
749+
See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
750+
- Changed -StoredProcedureParameter from string[] to object[] in
751+
`Invoke-CosmosDbStoredProcedure` - See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
752+
- Updated `Invoke-CosmosDbStoredProcedure` to set
753+
`x-ms-documentdb-script-enable-logging: true` header and write stored procedure
754+
logs to the Verbose Stream when `-Debug` is set - See [Issue #116](https://github.com/PlagueHO/CosmosDB/issues/116)
720755

721756
## [2.0.14.439] - 2018-06-12
722757

0 commit comments

Comments
 (0)