云服务器内容精选

  • Token认证 参数authToken和graphEndpoint如何填写见初始化参数获取。 import com.huawei.ges.graph.v1.GESGraphClient; // 内存版客户端 import com.huawei.ges.graph.v1.persistence.GESGraphPersistenceClient; // 持久化版客户端 import com.huawei.ges.graph.v1.auth.token.GesGraphTokenCredentials; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.http.HttpConfig; import java.util.Arrays; String authToken = ""; String graphEndpoint = ""; ICredential auth = new GesGraphTokenCredentials().withXAuthToken(authToken); HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig(); // 内存版客户端 GESGraphClient gesGraphClient = GESGraphClient.newBuilder().withCredential(auth).withEndpoints(Arrays.asList(graphEndpoint)).withHttpConfig(httpConfig).build(); // 持久化版客户端 GESGraphPersistenceClient gesGraphPersistenceClient = GESGraphPersistenceClient.newBuilder().withCredential(auth).withEndpoints(Arrays.asList(graphEndpoint)).withHttpConfig(httpConfig).build();
  • 密码认证 参数domainName、userName、password、projectId 、iamEndPoint和graphEndpoint如何填写见初始化参数获取。 import com.huawei.ges.graph.v1.GESGraphClient; // 内存版客户端 import com.huawei.ges.graph.v1.persistence.GESGraphPersistenceClient; // 持久化版客户端 import com.huawei.ges.graph.v1.auth.password.GesGraphPasswordCredentials; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.http.HttpConfig; import java.util.Arrays; // 认证用的密码硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以密码保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_PWD String password = System.getenv("HUAWEICLOUD_SDK_PWD"); String domainName = ""; String userName = ""; String projectId = ""; String iamEndPoint = ""; String graphEndpoint = ""; ICredential auth = new GesGraphPasswordCredentials(userName, domainName, password, projectId, Arrays.asList(iamEndPoint)); HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig(); // 内存版客户端 GESGraphClient gesGraphClient = GESGraphClient.newBuilder().withCredential(auth).withEndpoints(Arrays.asList(graphEndpoint)).withHttpConfig(httpConfig).build(); // 持久化版客户端 GESGraphPersistenceClient gesGraphPersistenceClient = GESGraphPersistenceClient.newBuilder().withCredential(auth).withEndpoints(Arrays.asList(graphEndpoint)).withHttpConfig(httpConfig).build();