-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
docs/docs/cmd/entra/resourcenamespace/resourcenamespace-list.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import Global from '/docs/cmd/_global.mdx'; | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# entra resourcenamespace list | ||
|
||
Get a list of the RBAC resource namespaces and their properties | ||
|
||
## Usage | ||
|
||
```sh | ||
m365 entra resourcenamespace list [options] | ||
``` | ||
|
||
## Options | ||
|
||
<Global /> | ||
|
||
## Remarks | ||
|
||
:::warning | ||
|
||
The command is based on an API that is currently in preview and is subject to change once the API reached general availability. | ||
|
||
::: | ||
|
||
## Examples | ||
|
||
Retrieve all resource namespaces. | ||
|
||
```sh | ||
m365 entra resourcenamespace list | ||
``` | ||
|
||
## Response | ||
|
||
<Tabs> | ||
<TabItem value="JSON"> | ||
|
||
```json | ||
[ | ||
{ | ||
"id": "microsoft.directory", | ||
"name": "microsoft.directory" | ||
}, | ||
{ | ||
"id": "microsoft.aad.b2c", | ||
"name": "microsoft.aad.b2c" | ||
} | ||
] | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Text"> | ||
|
||
```text | ||
id name | ||
-------------------- -------------------- | ||
microsoft.directory microsoft.directory | ||
microsoft.aad.b2c microsoft.aad.b2c | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="CSV"> | ||
|
||
```csv | ||
id,name | ||
microsoft.directory,microsoft.directory | ||
microsoft.aad.b2c,microsoft.aad.b2c | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Markdown"> | ||
|
||
```md | ||
# entra resourcenamespace list | ||
|
||
Date: 1/31/2025 | ||
|
||
## microsoft.directory (microsoft.directory) | ||
|
||
Property | Value | ||
---------|------- | ||
id | microsoft.directory | ||
name | microsoft.directory | ||
|
||
## microsoft.aad.b2c (microsoft.aad.b2c) | ||
|
||
Property | Value | ||
---------|------- | ||
id | microsoft.aad.b2c | ||
name | microsoft.aad.b2c | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/m365/entra/commands/resourcenamespace/resourcenamespace-list.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import auth from '../../../../Auth.js'; | ||
import { Logger } from '../../../../cli/Logger.js'; | ||
import { CommandError } from '../../../../Command.js'; | ||
import request from '../../../../request.js'; | ||
import { telemetry } from '../../../../telemetry.js'; | ||
import { pid } from '../../../../utils/pid.js'; | ||
import { session } from '../../../../utils/session.js'; | ||
import { sinonUtil } from '../../../../utils/sinonUtil.js'; | ||
import commands from '../../commands.js'; | ||
import command from './resourcenamespace-list.js'; | ||
|
||
|
||
describe(commands.RESOURCENAMESPACE_LIST, () => { | ||
let log: string[]; | ||
let logger: Logger; | ||
let loggerLogSpy: sinon.SinonSpy; | ||
|
||
before(() => { | ||
sinon.stub(auth, 'restoreAuth').resolves(); | ||
sinon.stub(telemetry, 'trackEvent').returns(); | ||
sinon.stub(pid, 'getProcessName').returns(''); | ||
sinon.stub(session, 'getId').returns(''); | ||
auth.connection.active = true; | ||
}); | ||
|
||
beforeEach(() => { | ||
log = []; | ||
logger = { | ||
log: async (msg: string) => { | ||
log.push(msg); | ||
}, | ||
logRaw: async (msg: string) => { | ||
log.push(msg); | ||
}, | ||
logToStderr: async (msg: string) => { | ||
log.push(msg); | ||
} | ||
}; | ||
loggerLogSpy = sinon.spy(logger, 'log'); | ||
}); | ||
|
||
afterEach(() => { | ||
sinonUtil.restore([ | ||
request.get | ||
]); | ||
}); | ||
|
||
after(() => { | ||
sinon.restore(); | ||
auth.connection.active = false; | ||
}); | ||
|
||
it('has correct name', () => { | ||
assert.strictEqual(command.name, commands.RESOURCENAMESPACE_LIST); | ||
}); | ||
|
||
it('has a description', () => { | ||
assert.notStrictEqual(command.description, null); | ||
}); | ||
|
||
it('defines correct properties for the default output', () => { | ||
assert.deepStrictEqual(command.defaultProperties(), ['id', 'name']); | ||
}); | ||
|
||
it(`should get a list of resource namespaces`, async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if (opts.url === `https://graph.microsoft.com/beta/roleManagement/directory/resourceNamespaces`) { | ||
return { | ||
value: [ | ||
{ | ||
"id": "microsoft.directory", | ||
"name": "microsoft.directory" | ||
}, | ||
{ | ||
"id": "microsoft.aad.b2c", | ||
"name": "microsoft.aad.b2c" | ||
} | ||
] | ||
}; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { | ||
options: { verbose: true } | ||
}); | ||
|
||
assert( | ||
loggerLogSpy.calledWith([ | ||
{ | ||
"id": "microsoft.directory", | ||
"name": "microsoft.directory" | ||
}, | ||
{ | ||
"id": "microsoft.aad.b2c", | ||
"name": "microsoft.aad.b2c" | ||
} | ||
]) | ||
); | ||
}); | ||
|
||
it('handles error when retrieving a list of resource namespaces failed', async () => { | ||
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if (opts.url === `https://graph.microsoft.com/beta/roleManagement/directory/resourceNamespaces`) { | ||
throw { error: { message: 'An error has occurred' } }; | ||
} | ||
throw `Invalid request`; | ||
}); | ||
|
||
await assert.rejects( | ||
command.action(logger, { options: {} } as any), | ||
new CommandError('An error has occurred') | ||
); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/m365/entra/commands/resourcenamespace/resourcenamespace-list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Logger } from '../../../../cli/Logger.js'; | ||
import { odata } from '../../../../utils/odata.js'; | ||
import GraphCommand from '../../../base/GraphCommand.js'; | ||
import commands from '../../commands.js'; | ||
|
||
class ResourceNamespaceListCommand extends GraphCommand { | ||
public get name(): string { | ||
return commands.RESOURCENAMESPACE_LIST; | ||
} | ||
|
||
public get description(): string { | ||
return 'Get a list of the RBAC resource namespaces and their properties'; | ||
} | ||
|
||
public defaultProperties(): string[] | undefined { | ||
return ['id', 'name']; | ||
} | ||
|
||
public async commandAction(logger: Logger): Promise<void> { | ||
if (this.verbose) { | ||
await logger.logToStderr('Getting a list of the RBAC resource namespaces and their properties...'); | ||
} | ||
|
||
try { | ||
const results = await odata.getAllItems<{ id: string, name: string }>(`${this.resource}/beta/roleManagement/directory/resourceNamespaces`); | ||
await logger.log(results); | ||
} | ||
catch (err: any) { | ||
this.handleRejectedODataJsonPromise(err); | ||
} | ||
} | ||
} | ||
|
||
export default new ResourceNamespaceListCommand(); |