数智融合计算服务 DATAARTSFABRIC-客户端初始化:永久AK/SK认证方式样例代码
永久AK/SK认证方式样例代码
- 方法定义
DwsRestClient(String endpoint, String accessKey, String secretKey)
- 参数说明
参数名
是否必填
描述
endpoint
是
FabricSQL提供的服务地址。
accessKey
是
接入键标识
secretKey
是
安全接入键
- 代码样例
// 从环境变量读取参数(推荐方式) String endpoint = "example.com"; String accessKey = System.getenv("FABRICLSQL_AC CES S_KEY"); String secretKey = System.getenv("FABRICLSQL_SECRET_KEY"); // 验证参数是否为空(可选) if (endpoint == null || accessKey == null || secretKey == null) { throw new IllegalArgumentException("Missing required environment variables"); } DwsRestClient client = new DwsRestClient(endpoint, accessKey, secretKey);

认证用的AK和SK硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。
本示例以AK和SK保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量FABRICLSQL_ACCESS_KEY和FABRICLSQL_SECRET_KEY。