All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksyun.api.sdk.regions.KscEndpointsParser Maven / Gradle / Ivy

There is a newer version: 2.1.8
Show newest version
package com.ksyun.api.sdk.regions;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.ksyun.api.sdk.auth.Credential;
import com.ksyun.api.sdk.client.DefaultKscProfile;
import com.ksyun.api.sdk.client.IClientProfile;
import com.ksyun.api.sdk.exceptions.ClientException;
import com.ksyun.api.sdk.utils.PlaceholderResolver;

public class KscEndpointsParser implements IEndpointsProvider {

    private DescribeEndpointService               describeEndpointService;

    public void setDescribeEndpointService(DescribeEndpointService describeEndpointService) {
        this.describeEndpointService = describeEndpointService;
    }

    public static KscEndpointsParser initRemoteEndpointsParser() {
        KscEndpointsParser parser = new KscEndpointsParser();
        parser.setDescribeEndpointService(new DescribeEndpointServiceImpl());
        return parser;
    }

    @Override
    public Endpoint getEndpoint(String regionId, String product) throws ClientException {
        throw new UnsupportedOperationException();
    }

    @Override
    public Endpoint getEndpoint(String regionId, String product, String serviceCode, String endpointType,
                                Credential credential, LocationConfig locationConfig) throws ClientException {
        if (serviceCode == null) {
            return null;
        }
        String host = PlaceholderResolver.productDomainResolver(serviceCode, locationConfig.getRegionId());
        Set regions = new HashSet<>();
        regions.add(locationConfig.getRegionId());
        Endpoint endpoint = new Endpoint(serviceCode, regions, Arrays.asList(new ProductDomain(serviceCode,host)));
        return endpoint;
    }

    public static void main(String[] args) throws ClientException {

        IClientProfile profile= DefaultKscProfile.getProfile("cn-qingdao", "account", "secret");
        List list = profile.getEndpoints("Ecs", "cn-qingdao", "ecs", "");
        System.out.println(list.get(0));

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy