public IAcsClient getAcsClient()

in src/main/java/com/aliyun/cloudops/acs/AcsClient.java [69:91]


    public IAcsClient getAcsClient() throws ClientException {
        if (StringUtils.isEmpty(this.ramRoleArn)) {
            return this.rawClient;
        }
        if (System.currentTimeMillis() < tokenExpireTime) {
            return this.roleClient;
        }

        AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
        assumeRoleRequest.setRoleArn(this.ramRoleArn);
        assumeRoleRequest.setRoleSessionName("");
        assumeRoleRequest.setDurationSeconds(3600L);
        AssumeRoleResponse response = this.rawClient.getAcsResponse(assumeRoleRequest);

        Credentials credentials = response.getCredentials();
        String newKeyId = credentials.getAccessKeyId();
        String newSecret = credentials.getAccessKeySecret();
        String newStsToken = credentials.getSecurityToken();
        DefaultProfile roleProfile = DefaultProfile.getProfile(regionId, newKeyId, newSecret, newStsToken);
        this.tokenExpireTime = System.currentTimeMillis() + 3600 * 1000 - 60 * 100; //TODO: readExpireTime;
        this.roleClient = new DefaultAcsClient(roleProfile);
        return this.roleClient;
    }