Authentication Mode
AK/SK-based Authentication
For how to set ak, sk, regionCode, and graphEndpoint, see Obtaining Initialization Parameters.
import os from gesgraphsdk.v1.aksk_credentials import GesGraphAkSkCredentials from gesgraphsdk.v1.gesgraph_client import GESGraphClient # Memory edition client from gesgraphsdk.v1.persistence.gesgraphpersistence_client import GESGraphPersistenceClient # Database edition client from huaweicloudsdkcore.http.http_config import HttpConfig # Hard-coded or plaintext AK and SK are insecure. So, encrypt your AK and SK and store them in the configuration file or environment variables. # In this example, the AK and SK are stored in environment variables. Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK. ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") region_code = "{regionCode}" graph_endpoint = "{graphEndpoint}" auth = GesGraphAkSkCredentials(ak=ak, sk=sk, region_code=region_code) http_conf = HttpConfig.get_default_config() # Memory edition client ges_graph_client = GESGraphClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build(); # Database edition client ges_graph_persistence_client = GESGraphPersistenceClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build();
Password-based Authentication
For how to set domainName, userName, password, projectId, iamEndPoint, and graphEndpoint, see Obtaining Initialization Parameters.
import os from gesgraphsdk.v1.gesgraph_client import GESGraphClient # Memory edition client from gesgraphsdk.v1.persistence.gesgraphpersistence_client import GESGraphPersistenceClient # Database edition client from gesgraphsdk.v1.token_credentials import GesGraphTokenCredentials from huaweicloudsdkcore.http.http_config import HttpConfig // Hard-coded or plaintext password is insecure. So, encrypt your password and store it in the configuration file or environment variables. // In this example, the password is stored in environment variables. Before running this example, set the environment variable HUAWEICLOUD_SDK_PWD. password = os.getenv("HUAWEICLOUD_SDK_PWD") domain_name = "{domainName}" user_name = "{userName}" project_id = "{projectId}" graph_endpoint = "{graphEndpoint}" iam_endpoint = "{iamEndPoint}" auth = GesGraphTokenCredentials(iam_endpoint=iam_endpoint, domain_name=domain_name, user_name=user_name, password=password, project_id=project_id) http_conf = HttpConfig.get_default_config() # Memory edition client ges_graph_client = GESGraphClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build() # Database edition client ges_graph_persistence_client = GESGraphPersistenceClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build();
Token-based Authentication
For how to set authToken and graphEndpoint, see Obtaining Initialization Parameters.
from gesgraphsdk.v1.gesgraph_client import GESGraphClient # Memory edition client from gesgraphsdk.v1.persistence.gesgraphpersistence_client import GESGraphPersistenceClient # Database edition client from gesgraphsdk.v1.token_credentials import GesGraphTokenCredentials from huaweicloudsdkcore.http.http_config import HttpConfig graph_endpoint = "{graphEndpoint}" token = "{authToken}" auth = GesGraphTokenCredentials(token=token) http_conf = HttpConfig.get_default_config() # Memory edition client ges_graph_client = GESGraphClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build() # Database edition client ges_graph_persistence_client GESGraphPersistenceClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build();
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot