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

Adds 'spe container get' command. Closes #6083 #6421

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ff8cbad
spe container get
nanddeepn Oct 9, 2024
486deaf
review comments
nanddeepn Nov 25, 2024
330ba95
Merge branch 'main' into issue-6083
nanddeepn Nov 25, 2024
d233e8c
Moves 'spo folder copy' to new endpoint. Closes #6310
milanholemans Oct 18, 2024
def156c
Removes deprecated option from 'entra m365group user remove'. Closes …
milanholemans Oct 18, 2024
4bd7faa
Updates 'spo userprofile get' command docs.
mc2rcanarslan Oct 18, 2024
c6297ed
Updates release notes
Adam-it Oct 24, 2024
bc324dc
Adds new command 'spo page publish'. Closes #6420
Saurabh7019 Oct 18, 2024
563ff82
Updates release notes
milanholemans Oct 25, 2024
cb46a5e
Renames command 'spo site list' to 'spo tenant site list'. Closes #6143
ktskumar Sep 22, 2024
8fde5f4
Adds command 'viva engage community user list'. Closes #6295
Jwaegebaert Sep 20, 2024
7668a3b
Adds command 'spo folder sharinglink set'. Closes #5964
Saurabh7019 May 3, 2024
f991f0c
Updates release notes
MathijsVerbeeck Oct 26, 2024
74c7a94
Updates 'teams cache remove' command to support the new client. Close…
MathijsVerbeeck Sep 20, 2024
7e0914e
Updates release notes
Adam-it Oct 30, 2024
9f71bd6
Updates version to v10.1.0
Adam-it Oct 31, 2024
15d55a1
Adds command 'm365 spe container list'. Closes #6082
nanddeepn Oct 6, 2024
52f2eaa
Adds command 'spe containertype get'. Closes #5991
reshmee011 Aug 8, 2024
0d10ddc
Fixes using env var for login command. Closes #6469
waldekmastykarz Nov 5, 2024
f32e5f1
Updates v10 upgrade guidance. Closes #6363
milanholemans Nov 1, 2024
fc5c2f7
Updates release notes
Adam-it Nov 5, 2024
c94236f
Fixes missing 'sp' alias in 'enterpriseapp' commands. Closes #6476
Adam-it Nov 6, 2024
f447faf
Updates release notes
martinlingstuyl Nov 8, 2024
59ae248
Updates entra m365group commands to accept displayName option. Closes…
MartinM85 Aug 9, 2024
a51d625
Adds command 'viva engage community set'. Closes #6279
MartinM85 Aug 29, 2024
2716e3a
Speeds up linting. Closes #6348
waldekmastykarz Sep 15, 2024
cf847f5
Enhances 'entra m365group get' with additional properties. Closes #6148
ktskumar Sep 25, 2024
d90637c
Enhances spo contenttype commands with Parent expand. Closes #6329
MathijsVerbeeck Sep 26, 2024
4bf19f4
Updates the docs on how to log in to CLI. Closes #6343
Jwaegebaert Oct 2, 2024
db83805
Enhances 'graph subscription add' command with additional options. Cl…
MartinM85 Sep 27, 2024
2c0cb7a
Fixes syntax highlighting
milanholemans Oct 25, 2024
55df91e
Updates release notes
Adam-it Nov 15, 2024
e212386
Replaces csv parser. Closes #5825
brugh Aug 9, 2024
ff5cef7
Adds new contributor
milanholemans Nov 24, 2024
5b3a3c1
Replaces deprecated methods. Closes #6244
MartinM85 Aug 13, 2024
d4fadc1
Adds copilot alias to chatbot commands. Closes #6261
ktskumar Sep 25, 2024
c6a5de6
Adds command 'spp model remove'. Closes #6118
mkm17 Oct 3, 2024
8c29adc
Allows case-insensitive column names in 'spo listitem batch remove'. …
Saurabh7019 Oct 12, 2024
ff9ac4e
Enhances 'spo site admin' commands to retrieve site ID as admin. Clos…
mkm17 Oct 22, 2024
5b471f3
Fixes XML character escaping in 'spo listitem batch set'. Closes #6430
Saurabh7019 Oct 30, 2024
0a51b5f
Updates all sample scripts to align with v10. Closes #6369
Adam-it Nov 17, 2024
cd9d42a
Updates release notes
milanholemans Nov 24, 2024
4082580
Merge branch 'issue-6083' of https://github.com/nanddeepn/cli-microso…
nanddeepn Nov 25, 2024
b39133d
review comments
nanddeepn Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions docs/docs/cmd/spe/container/container-get.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# spe container get

Gets a container of a specific container type

## Usage

```sh
m365 spe container get [options]
```

## Options

```md definition-list
`-i, --id <id>`
: The Id of the container instance.
```

<Global />

## Examples

Gets a container of a specific type.

```sh
m365 spe container get --id "b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z"
```

## Response

<Tabs>
<TabItem value="JSON">

```json
{
"id": "b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z",
"displayName": "My Application Storage Container",
"description": "Description of My Application Storage Container",
"containerTypeId": "91710488-5756-407f-9046-fbe5f0b4de73",
"status": "active",
"createdDateTime": "2021-11-24T15:41:52.347Z",
"settings": {
"isOcrEnabled": false
}
}
```

</TabItem>
<TabItem value="Text">

```text
id : b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z
displayName : My Application Storage Container
description : Description of My Application Storage Container
containerTypeId : 91710488-5756-407f-9046-fbe5f0b4de73
status : active
createdDateTime : 2021-11-24T15:41:52.347Z
```

</TabItem>
<TabItem value="CSV">

```csv
id,displayName,description,containerTypeId,status,createdDateTime
b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z,My Application Storage Container,Description of My Application Storage Container,91710488-5756-407f-9046-fbe5f0b4de73,active,2021-11-24T15:41:52.347Z
```

</TabItem>
<TabItem value="Markdown">

```md
# spe container get --id "b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z"

Date: 14/03/2024

## My Application Storage Container (b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z)

Property | Value
---------|-------
id | b!ISJs1WRro0y0EWgkUYcktDa0mE8zSlFEqFzqRn70Zwp1CEtDEBZgQICPkRbil_5Z
displayName | My Application Storage Container
description | Description of My Application Storage Container
containerTypeId | 91710488-5756-407f-9046-fbe5f0b4de73
status | active
createdDateTime | 2021-11-24T15:41:52.347Z
```

</TabItem>
</Tabs>
14 changes: 14 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,20 @@ const sidebars: SidebarsConfig = {
},
{
'SharePoint Embedded (spe)': [
{
container: [
{
type: 'doc',
label: 'container get',
id: 'cmd/spe/container/container-get'
},
{
type: 'doc',
label: 'container list',
id: 'cmd/spe/container/container-list'
}
]
},
{
container: [
{
Expand Down
1 change: 1 addition & 0 deletions src/m365/spe/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const prefix: string = 'spe';

export default {
CONTAINER_GET: `${prefix} container get`,
CONTAINER_LIST: `${prefix} container list`,
CONTAINERTYPE_ADD: `${prefix} containertype add`,
CONTAINERTYPE_GET: `${prefix} containertype get`,
Expand Down
99 changes: 99 additions & 0 deletions src/m365/spe/commands/container/container-get.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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 './container-get.js';

describe(commands.CONTAINER_GET, () => {
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.CONTAINER_GET);
});

it('has a description', () => {
assert.notStrictEqual(command.description, null);
});

it('correctly handles error', async () => {
const errorMessage = 'Bad request.';
sinon.stub(request, 'get').rejects({
error: {
message: errorMessage
}
});

await assert.rejects(command.action(logger, { options: { id: 'invalid', verbose: true } } as any),
new CommandError(errorMessage));
});

it('gets container by id', async () => {
const containerId = 'eyJfdHlwZSI6Ikdyb3VwIiwiaWQiOiIxNTU1MjcwOTQyNzIifQ';
const response = {
id: containerId,
displayName: "My Application Storage Container",
description: "Description of My Application Storage Container",
containerTypeId: "91710488-5756-407f-9046-fbe5f0b4de73",
status: "active",
createdDateTime: "2021-11-24T15:41:52.347Z",
settings: {
isOcrEnabled: false
}
};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/storage/fileStorage/containers/${containerId}`) {
return response;
}

throw 'Invalid Request';
});

await command.action(logger, { options: { id: containerId } } as any);
assert.deepStrictEqual(loggerLogSpy.lastCall.args[0], response);
});
});
65 changes: 65 additions & 0 deletions src/m365/spe/commands/container/container-get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import GlobalOptions from '../../../../GlobalOptions.js';
import { Logger } from '../../../../cli/Logger.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import request, { CliRequestOptions } from '../../../../request.js';
import { ContainerProperties } from '../../ContainerProperties.js';

interface CommandArgs {
options: Options;
}

interface Options extends GlobalOptions {
id: string;
}

class SpeContainerGetCommand extends GraphCommand {
public get name(): string {
return commands.CONTAINER_GET;
}

public get description(): string {
return 'Gets a container of a specific container type';
}

constructor() {
super();

this.#initOptions();
this.#initTypes();
}

#initOptions(): void {
this.options.unshift(
{ option: '-i, --id <id>' }
);
}

#initTypes(): void {
this.types.string.push('id');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Getting a container with id '${args.options.id}'...`);
}

const requestOptions: CliRequestOptions = {
url: `${this.resource}/v1.0/storage/fileStorage/containers/${args.options.id}`,
headers: {
accept: 'application/json;odata.metadata=none'
},
responseType: 'json'
};

try {
const res = await request.get<ContainerProperties>(requestOptions);
await logger.log(res);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new SpeContainerGetCommand();