Skip to content

New Sample: Ensure the Site Assets library is created#1447

Closed
phillipharding wants to merge 1 commit intopnp:devfrom
phillipharding:sample-ensuresiteassetslibrary
Closed

New Sample: Ensure the Site Assets library is created#1447
phillipharding wants to merge 1 commit intopnp:devfrom
phillipharding:sample-ensuresiteassetslibrary

Conversation

@phillipharding
Copy link
Copy Markdown

Ensure the Site Assets library is created

There are occasions when creating a new modern SharePoint site using the CLI/REST API that the Site Assets library isn't created, use this script to ensure that the Site Assets library is created.

Reference: 'ensure' commands #1427

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 9636297 on phillipharding:sample-ensuresiteassetslibrary into f7f194d on pnp:dev.

@waldekmastykarz
Copy link
Copy Markdown
Member

Thank you! We'll review it shortly! 👏

Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Let's clarify one thing and then we can get it in 👍


try {
$resource = ($siteUrl -split "/")[2]
$accessToken = o365 util accesstoken get --new --resource "https://$resource/"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason why you always retrieve a new access token here rather than using one retrieved previously if still valid?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, just being cautious and not understanding when/how access tokens are refreshed by the CLI, this function could be called at some point during a long provisioning pipeline which may not have included SharePoint to that point - happy to remove it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, we should do better job explaining the details in our docs. The way it works, is that each time you request a token, the CLI will check if the previously available token is still valid. If it is, it returns it. If it expired, it will automatically retrieve a new one. So in practice, you should need the --new switch only if you granted additional permissions or need a different token.


try {
$resource = ($siteUrl -split "/")[2]
$accessToken = o365 util accesstoken get --new --resource "https://$resource/"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAD resources, with one exception, typically don't have a trailing slash. In this case it doesn't matter, but there are cases in which it returns an invalid access token

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, shall I remove it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it when merging the PR. No problem 👍

@waldekmastykarz
Copy link
Copy Markdown
Member

Merged manually. Thank you! Welcome to the crew! 👏 🍾 🎉

@phillipharding phillipharding deleted the sample-ensuresiteassetslibrary branch April 12, 2020 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants