Skip to content

Commit 4fcca56

Browse files
♻️ [Maintenance]: Rename ConvertTo-ConfluenceCloudId to Get-ConfluenceCloudId; record token scopes on connect
- Rename ConvertTo-ConfluenceCloudId to Get-ConfluenceCloudId: the function performs a GET against /_edge/tenant_info, so a Get- verb is accurate. Help, examples, the Connect-Confluence reference, and the surface test are updated. - Connect-Confluence now collects the token's scopes from the accessible-resources endpoint and stores them on the context (Scopes), so callers can see what the token can do. Collection is best-effort and never fails the connection.
1 parent 4e867fc commit 4fcca56

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

src/functions/public/Auth/Connect-Confluence.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Connect-Confluence {
4646
[string]$Site,
4747

4848
# The Confluence Cloud ID - a faster alternative to -Site that skips the lookup.
49-
# Find it with `ConvertTo-ConfluenceCloudId` or `Get-ConfluenceAccessibleResource`.
49+
# Find it with `Get-ConfluenceCloudId` or `Get-ConfluenceAccessibleResource`.
5050
[Parameter(Mandatory, ParameterSetName = 'CloudId')]
5151
[string]$CloudId,
5252

@@ -70,7 +70,7 @@ function Connect-Confluence {
7070

7171
if ($PSCmdlet.ParameterSetName -eq 'Site') {
7272
# Resolve a site name/host/URL to its cloud ID via the public tenant_info endpoint.
73-
$CloudId = ConvertTo-ConfluenceCloudId -Site $Site
73+
$CloudId = Get-ConfluenceCloudId -Site $Site
7474
}
7575
# The scoped-token gateway base is always api.atlassian.com/ex/confluence/<cloudId>.
7676
$ApiBaseUri = 'https://api.atlassian.com/ex/confluence/{0}' -f $CloudId
@@ -100,6 +100,7 @@ function Connect-Confluence {
100100
Username = $Username
101101
Token = $Token
102102
SpaceKey = $SpaceKey
103+
Scopes = @()
103104
}
104105

105106
if (-not $PSCmdlet.ShouldProcess($Name, 'Connect to Confluence and store credential context')) {
@@ -118,6 +119,19 @@ function Connect-Confluence {
118119
Write-Warning "Token authenticated but lacks read:space; space listing is unavailable for context '$Name'."
119120
}
120121

122+
# Best-effort: record the scopes the token holds for this site (from the
123+
# accessible-resources endpoint) so the stored context reflects what we can do.
124+
# Never fail the connection if scope discovery is unavailable for this token.
125+
try {
126+
$resource = Get-ConfluenceAccessibleResource -Token $Token | Where-Object { $_.id -eq $CloudId } | Select-Object -First 1
127+
if ($resource -and $resource.scopes) {
128+
$context['Scopes'] = @($resource.scopes)
129+
Write-Verbose "Recorded $($context['Scopes'].Count) scope(s) for context '$Name'."
130+
}
131+
} catch {
132+
Write-Verbose "Could not resolve token scopes from accessible-resources: $($_.Exception.Message)"
133+
}
134+
121135
$stored = Set-Context -ID $Name -Context $context -Vault $script:Confluence.ContextVault -PassThru
122136
Set-ConfluenceConfig -Name 'DefaultContext' -Value $Name
123137

src/functions/public/Site/ConvertTo-ConfluenceCloudId.ps1 renamed to src/functions/public/Site/Get-ConfluenceCloudId.ps1

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
#SkipTest:FunctionTest:Resolves the cloud ID from the public tenant_info endpoint; covered by integration tests.
2-
function ConvertTo-ConfluenceCloudId {
2+
function Get-ConfluenceCloudId {
33
<#
44
.SYNOPSIS
5-
Resolve a Confluence Cloud site to its cloud ID.
5+
Get the cloud ID for a Confluence Cloud site.
66
77
.DESCRIPTION
88
Looks up the cloud ID for an Atlassian Confluence Cloud site from the
9-
public `/_edge/tenant_info` endpoint, so a caller can supply a site name or
10-
URL instead of the cloud ID. Accepts a bare subdomain (`myorg`), a host
11-
(`myorg.atlassian.net`), or any URL on the site
9+
public `/_edge/tenant_info` endpoint (a GET request), so a caller can supply
10+
a site name or URL instead of the cloud ID. Accepts a bare subdomain
11+
(`myorg`), a host (`myorg.atlassian.net`), or any URL on the site
1212
(`https://myorg.atlassian.net/wiki/...`). No authentication is required.
1313
1414
.EXAMPLE
1515
```powershell
16-
ConvertTo-ConfluenceCloudId -Site 'msxorg'
16+
Get-ConfluenceCloudId -Site 'msxorg'
1717
```
1818
1919
Returns the cloud ID for `https://msxorg.atlassian.net`.
2020
2121
.EXAMPLE
2222
```powershell
23-
'https://msxorg.atlassian.net/wiki/spaces/DOCS' | ConvertTo-ConfluenceCloudId
23+
'https://msxorg.atlassian.net/wiki/spaces/DOCS' | Get-ConfluenceCloudId
2424
```
2525
2626
Resolves the cloud ID from a full site URL supplied through the pipeline.
2727
2828
.EXAMPLE
2929
```powershell
30-
$cloudId = ConvertTo-ConfluenceCloudId -Site 'msxorg'
31-
Connect-Confluence -ApiBaseUri "https://api.atlassian.com/ex/confluence/$cloudId" -Username $user -Token $token
30+
Connect-Confluence -CloudId (Get-ConfluenceCloudId -Site 'msxorg') -Username $user -Token $token
3231
```
3332
34-
Uses the resolved cloud ID to build the API-gateway base URI for `Connect-Confluence`,
35-
so the caller only needs the site name.
33+
Uses the resolved cloud ID to connect, so the caller only needs the site name.
3634
3735
.OUTPUTS
3836
System.String
3937
4038
.LINK
41-
https://psmodule.io/Confluence/Functions/Site/ConvertTo-ConfluenceCloudId/
39+
https://psmodule.io/Confluence/Functions/Site/Get-ConfluenceCloudId/
4240
4341
.LINK
4442
https://developer.atlassian.com/cloud/confluence/rest/v2/intro/#about

tests/Confluence.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Describe 'Confluence' {
3939
'Invoke-ConfluenceRestMethod'
4040
'Get-ConfluenceSpace'
4141
'Get-ConfluenceSiteInfo'
42-
'ConvertTo-ConfluenceCloudId'
42+
'Get-ConfluenceCloudId'
4343
'Get-ConfluenceAccessibleResource'
4444
'New-ConfluencePage'
4545
'Get-ConfluencePage'

0 commit comments

Comments
 (0)