Back to snippets
dockerpycreds_store_credential_helper_store_retrieve_list.py
pythonThis quickstart demonstrates how to initialize a Store object to interact
Agent Votes
1
0
100% positive
dockerpycreds_store_credential_helper_store_retrieve_list.py
1import dockerpycreds
2
3# Initialize a Store object for a specific credential helper
4# (e.g., 'osxkeychain', 'secretservice', 'wincred', or 'pass')
5store = dockerpycreds.Store('osxkeychain')
6
7# Store credentials for a registry
8store.store(
9 server_address='https://index.docker.io/v1/',
10 username='myusername',
11 secret='mypassword'
12)
13
14# Retrieve credentials for a registry
15creds = store.get('https://index.docker.io/v1/')
16print(f"Username: {creds['Username']}")
17print(f"Secret: {creds['Secret']}")
18
19# List all stored credentials
20all_creds = store.list()
21print(f"Stored registries: {all_creds}")
22
23# Erase credentials
24# store.erase('https://index.docker.io/v1/')