paramgroup Group, use “DEFAULT_GROUP” if no group specified.
paramcontent Config value.
paramtimeout Timeout for requesting server in seconds.
return True if success or an exception will be raised.
Publish one data item to ACM.
If the data key is not exist, create one first.
If the data key is exist, update to the content specified.
Content can not be set to None, if there is need to delete config item, use function remove instead.
Remove Config
ACMClient.remove(data_id, group, timeout)
paramdata_id Data id.
paramgroup Group, use “DEFAULT_GROUP” if no group specified.
paramtimeout Timeout for requesting server in seconds.
return True if success or an exception will be raised.
Remove one data item from ACM.
Debugging Mode
Debugging mode if useful for getting more detailed log on console.
Debugging mode can be set by:
ACMClient.set_debugging()
# only effective within the current process
CLI Tool
A CLI Tool is along with python SDK to make convenient access and management of config items in ACM server.
You can use acm {subcommand} directly after installation, sub commands available are as following:
add add a namespace
use switch to a namespace
current show current endpoint and namespace
show show all endpoints and namespaces
list get list of dataIds
pull get one config content
push push one config
export export dataIds to local files
import import files to ACM server
Use acm -h to see the detailed manual.
Data Security Options
ACM allows you to encrypt data along with Key Management Service, service provided by Alibaba Cloud (also known as KMS).
To use this feature, you can follow these steps:
Install KMS SDK by pip install aliyun-python-sdk-kms.
Name your data_id with a cipher- prefix.
Get and filling all the needed configuration to ACMClient, info needed are: region_id, kms_ak, kms_secret, key_id.
Just make API calls and SDK will process data encrypt & decrypt automatically.
Example:
c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
c.set_options(kms_enabled=True, kms_ak=KMS_AK, kms_secret=KMS_SECRET, region_id=REGION_ID, key_id=KEY_ID)
# publish an encrypted config item.
c.publish("cipher-dataId", None, "plainText")
# get the content of an encrypted config item.
c.get("cipher-dataId", None)
Use RAM
It is a best practice to use RAM instead of hard coded AccessKey and SecretKey at client side, because it’s much more safe and simple.
Example:
ENDPOINT = "acm.aliyun.com"
NAMESPACE = "9ca*****c1e"
RAM_ROLE_NAME = "ECS-STS-KMS-ACM"
REGION_ID = "cn-shanghai"
KEY_ID="192d****dc"
# use RAM role name for configuration.
a=acm.ACMClient(ENDPOINT, NAMESPACE, ram_role_name=RAM_ROLE_NAME)
a.set_options(kms_enabled=True, region_id=REGION_ID, key_id=KEY_ID)
# call API like the same as before.
a.list_all()
a.get('cipher-dataId','DEFAULT_GROUP')
User Guide
Introduction
Python SDK for ACM.
Features
Supported Python:
Supported ACM version
Change Logs
Installation
For Python 2.7 and above:
For Python 2.6:
Getting Started
Configuration
DEFAULT_TENANTNoneNoneExtra Options
Extra option can be set by
set_options, as following:Configurable options are:
API Reference
Get Config
paramdata_id Data id.paramgroup Group, useDEFAULT_GROUPif no group specified.paramtimeout Timeout for requesting server in seconds.paramno_snapshot Whether to use local snapshot while server is unavailable.returnW Get value of one config item following priority:Step 1 - Get from local failover dir(default:
${cwd}/acm/data).${cwd}/acm/snapshot) in advance.Step 2 - Get from one server until value is got or all servers tried.
Step 3 - Get from snapshot dir.
Add Watchers
paramdata_id Data id.paramgroup Group, useDEFAULT_GROUPif no group specified.paramcb_list List of callback functions to add.returnAdd watchers to a specified config item.
threading.Thread.Remove Watcher
paramdata_id Data id.paramgroup Group, use “DEFAULT_GROUP” if no group specified.paramcb Callback function to delete.paramremove_all Whether to remove all occurrence of the callback or just once.returnRemove watcher from specified key.
List All Config
paramgroup Only dataIds with group match shall be returned, default is None.paramgroup only dataIds startswith prefix shall be returned, default is None Case sensitive.returnList of data items.Get all config items of current namespace, with dataId and group information only.
Publish Config
paramdata_id Data id.paramgroup Group, use “DEFAULT_GROUP” if no group specified.paramcontent Config value.paramtimeout Timeout for requesting server in seconds.returnTrue if success or an exception will be raised.Publish one data item to ACM.
Remove Config
paramdata_id Data id.paramgroup Group, use “DEFAULT_GROUP” if no group specified.paramtimeout Timeout for requesting server in seconds.returnTrue if success or an exception will be raised.Remove one data item from ACM.
Debugging Mode
Debugging mode if useful for getting more detailed log on console.
Debugging mode can be set by:
CLI Tool
A CLI Tool is along with python SDK to make convenient access and management of config items in ACM server.
You can use
acm {subcommand}directly after installation, sub commands available are as following:Use
acm -hto see the detailed manual.Data Security Options
ACM allows you to encrypt data along with Key Management Service, service provided by Alibaba Cloud (also known as KMS).
To use this feature, you can follow these steps:
pip install aliyun-python-sdk-kms.cipher-prefix.ACMClient, info needed are:region_id,kms_ak,kms_secret,key_id.Example:
Use RAM
It is a best practice to use RAM instead of hard coded AccessKey and SecretKey at client side, because it’s much more safe and simple.
Example:
For more information, refer to this document.
Other Resources