再直白一点,以下列关键字开头的命令,都是MaxCompute安全相关操作命令:
GRANT/REVOKE ...
SHOW GRANTS/ACL/PACKAGE/LABEL/ROLE/PRINCIPALS
SHOW PRIV/PRIVILEGES
LIST/ADD/REOVE USERS/ROLES/TRUSTEDPROJECTS
DROP/CREATE ROLE
CLEAR EXPIRED GRANTS
DESC/DESCRIBE ROLE/PACKAGE
CREATE/DELETE/DROP PACKAGE
ADD ... TO PACKAGE
REMOVE ... FROM PACKAGE
ALLOW/DISALLOW PROJECT
INSTALL/UNINSTALL PACKAGE
LIST/ADD/REMOVE ACCOUNTPROVIDERS
SET LABLE ...
答案:不可以,这些命令不是 SQL , 不可以通过 SQL Task 来运行。
SecurityManager
类在 odps-sdk-core 中,因此在使用时请添加依赖:<dependency>
<groupId>com.aliyun.odps</groupId>
<artifactId>odps-sdk-core</artifactId>
<version>0.29.11-oversea-public</version>
</dependency>
test_label
列的访问级别为 2,也就是运行命令
SET LABEL 2 TO TABLE test_label(key, value);
。import com.aliyun.odps.Column;
import com.aliyun.odps.Odps;
import com.aliyun.odps.OdpsException;
import com.aliyun.odps.OdpsType;
import com.aliyun.odps.TableSchema;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.security.SecurityManager;
public class test {
public static void main(String [] args) throws OdpsException {
try {
// init odps
Account account = new AliyunAccount("<your_accessid>", "<your_accesskey>");
Odps odps = new Odps(account);
odps.setEndpoint("http://service-corp.odps.aliyun-inc.com/api");
odps.setDefaultProject("<your_project>");
// create test table
// if u already have a table, skip this
TableSchema schema = new TableSchema();
schema.addColumn(new Column("key", OdpsType.STRING));
schema.addColumn(new Column("value", OdpsType.BIGINT));
odps.tables().create("test_label", schema);
// set label 2 to table columns
SecurityManager securityManager = odps.projects().get().getSecurityManager();
String res = securityManager.runQuery("SET LABEL 2 TO TABLE test_label(key, value);", false);
System.out.println(res);
} catch (OdpsException e) {
e.printStackTrace();
}
}
}
运行结果:
程序运行完成后,在 MaxCompute Console 中运行 `desc test_lable;` 命令,可以看到 set label 已经生效了。
其他安全相关的命令,都可以这样子通过 MaxCompute Java SDK 来运行呢,快来试试吧!