-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from canonical/tutorial
docs: add login and whoami tutorials for Snap Store
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
********* | ||
Tutorials | ||
********* | ||
|
||
.. tutorial-snap_store_login: | ||
Login to the Snap Store | ||
======================= | ||
|
||
Prerequisites | ||
------------- | ||
|
||
- Python 3.8 or 3.9 | ||
- a clean virtual environment setup | ||
- a text editor | ||
- a developer account on https://snapcraft.io | ||
|
||
|
||
Setup | ||
----- | ||
|
||
Enable the virtual environment and then install Craft Store by running:: | ||
|
||
$ pip install craft-store | ||
|
||
Code | ||
---- | ||
|
||
Write following into a a text editor and save it as ``snap_store_login.py``: | ||
|
||
.. code-block:: python | ||
#!/usr/bin/env python | ||
from craft_store import StoreClient, endpoints | ||
store_client = StoreClient( | ||
base_url="https://dashboard.snapcraft.io", | ||
endpoints=endpoints.SNAP_STORE, | ||
user_agent="Craft Store Tutorial Agent", | ||
application_name="cart-store-tutorial" | ||
) | ||
store_client.login( | ||
permissions=["package_access"], | ||
description="tutorial-client-login", | ||
ttl=1000 | ||
) | ||
Run | ||
--- | ||
|
||
Run the saved python module to login:: | ||
|
||
$ python snap_store_login.py | ||
|
||
|
||
Get Account email and id from the Snap Store | ||
============================================ | ||
|
||
Prerequisites | ||
------------- | ||
|
||
- Completed :ref:`tutorial-snap_store_login` | ||
- Shelled into the virtual environment created in :ref:`tutorial-snap_store_login` | ||
|
||
Code | ||
---- | ||
|
||
Write following into a a text editor and save it as ``snap_store_whoami.py``: | ||
|
||
.. code-block:: python | ||
#!/usr/bin/env python | ||
from craft_store import StoreClient, endpoints | ||
store_client = StoreClient( | ||
base_url="https://dashboard.snapcraft.io", | ||
endpoints=endpoints.SNAP_STORE, | ||
user_agent="Craft Store Tutorial Agent", | ||
application_name="cart-store-tutorial" | ||
) | ||
whoami = store_client.whoami() | ||
print(f"email: {whoami['account']['email']}") | ||
print(f"id: {whoami['account']['id']}") | ||
Run | ||
--- | ||
|
||
Run the saved python module to retrieved the account information for the login:: | ||
|
||
$ python snap_store_login.py |