更新时间:2024-04-18 GMT+08:00
分享

AK/SK认证

  • Java
    import com.huawei.ges.graph.v1.GESGraphClient;
    import com.huawei.ges.graph.v1.auth.aksk.GesGraphAkSkCredentials;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.http.HttpConfig;
    
    // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全
    // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK
    String ak = System.getenv("HUAWEICLOUD_SDK_AK");
    String sk = System.getenv("HUAWEICLOUD_SDK_SK");
    // 此处需要输出您图所在区域和图实例IP
    String regionCode = "{regionCode}";
    String graphEndpoint = "{graphEndpoint}";
    ICredential auth = new GesGraphAkSkCredentials().withAk(ak).withSk(sk).withRegionCode(regionCode);
    HttpConfig httpConfig = new HttpConfig().withIgnoreSSLVerification(true);
    GESGraphClient client = GESGraphClient.newBuilder().withCredential(auth).withEndpoints(Arrays.asList(graphEndpoint)).withHttpConfig(httpConfig).build();
  • Python
    from gesgraphsdk.v1 import GESGraphClient
    from gesgraphsdk.v1.aksk_credentials import GesGraphAkSkCredentials
    from huaweicloudsdkcore.http.http_config import HttpConfig
    
    # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全
    # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK
    ak = os.getenv("HUAWEICLOUD_SDK_AK")
    sk = os.getenv("HUAWEICLOUD_SDK_SK")
    graph_endpoint = "{graphEndpoint}"
    region_code = "{regionCode}"
    auth = GesGraphAkSkCredentials(ak=ak, sk=sk, region_code=region_code)
    http_conf = HttpConfig(ignore_ssl_verification=True, timeout=60)
    client = GESGraphClient.new_builder().with_credentials(auth).with_endpoint(graph_endpoint).with_http_config(http_conf).build()
分享:

    相关文档

    相关产品