图引擎服务 GES-认证方式:密码认证

时间:2024-11-25 17:24:28

密码认证

参数domainName、userName、password、projectId 、iamEndPoint和graphEndpoint如何填写见初始化参数获取

import os
from gesgraphsdk.v1.gesgraph_client import GESGraphClient  # 内存版客户端
from gesgraphsdk.v1.persistence.gesgraphpersistence_client import GESGraphPersistenceClient  # 持久化版客户端
from gesgraphsdk.v1.token_credentials import GesGraphTokenCredentials
from huaweicloudsdkcore.http.http_config import HttpConfig


// 认证用的密码硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全
// 本示例以密码保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量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()

# 内存版客户端
ges_graph_client = GESGraphClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build()
# 持久化版客户端
ges_graph_persistence_client = GESGraphPersistenceClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build();
support.huaweicloud.com/devg-ges/ges_05_0039.html