Skip to content

Commit af2995e

Browse files
committed
release 0.0.3-beta source code for java
1 parent 1828ac4 commit af2995e

File tree

1,154 files changed

+82128
-1186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,154 files changed

+82128
-1186
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
# 0.0.3-beta 2022-12-27
2+
3+
### G42Cloud SDK AS
4+
5+
- _Features_
6+
- New Support AS
7+
- _Bug Fix_
8+
- None
9+
- _Change_
10+
- None
11+
12+
### G42Cloud SDK BMS
13+
14+
- _Features_
15+
- New Support BMS
16+
- _Bug Fix_
17+
- None
18+
- _Change_
19+
- None
20+
21+
### G42Cloud SDK IMS
22+
23+
- _Features_
24+
- New Support IMS
25+
- _Bug Fix_
26+
- None
27+
- _Change_
28+
- None
29+
30+
### G42Cloud SDK SMN
31+
32+
- _Features_
33+
- New Support SMN
34+
- _Bug Fix_
35+
- None
36+
- _Change_
37+
- None
38+
139
# 0.0.2-beta 2022-11-29
240

341
### G42Cloud SDK CBR

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="https://www.g42cloud.com/"><img style="background-color:black;" width="450px" height="102px" src="https://auth.g42cloud.com//authui/20220614193554/public/custom/images/logo.svg"></a>
2+
<a href="https://www.g42cloud.com/"><img src="https://upload.wikimedia.org/wikipedia/en/4/43/Group_42_Logo.jpg"></a>
33
</p>
44

55
<h1 align="center">G42 Cloud Java Software Development Kit (Java SDK)</h1>
@@ -59,11 +59,11 @@ package com.g42cloud.sdk.test;
5959
import org.slf4j.Logger;
6060
import org.slf4j.LoggerFactory;
6161
// Authentication
62-
import com.huaweicloud.sdk.core.auth.BasicCredentials;
62+
import com.g42cloud.sdk.core.auth.BasicCredentials;
6363
// Service response exception class
64-
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
64+
import com.g42cloud.sdk.core.exception.ServiceResponseException;
6565
// Http Configuration
66-
import com.huaweicloud.sdk.core.http.HttpConfig;
66+
import com.g42cloud.sdk.core.http.HttpConfig;
6767
import com.g42cloud.sdk.vpc.v2.VpcClient;
6868
// Import the request and response classes
6969
import com.g42cloud.sdk.vpc.v2.model.ListVpcsRequest;
@@ -233,14 +233,6 @@ GlobalCredentials globalCredentials = new GlobalCredentials()
233233
.withDomainId(domainId);
234234
```
235235

236-
**Notice**:
237-
238-
- projectId/domainId supports **automatic acquisition**, if you want to use this
239-
feature, you need to provide the ak and sk of your account and the id of the region, and then build your client
240-
instance with method `withRegion()`, detailed example could refer
241-
to [3.2 Initialize the client with specified Region](#32-initialize-the-serviceclient-with-specified-region-recommended-top)
242-
.
243-
244236
#### 2.2 Use Temporary AK&SK [:top:](#user-manual-top)
245237

246238
A temporary access key and securityToken are issued by the system to IAM users, and can be valid for 15 minutes to 24 hours. After the validity period expires, you need to obtain them again. It's required to obtain temporary AK&SK and security token first, which could be obtained through
@@ -531,9 +523,11 @@ condition use the default condition, the code would be like the following:
531523

532524
``` java
533525
// initialize the asychronous client
526+
String endpoint = "{endpoint}";
527+
534528
EcsAsyncClient asyncClient = EcsAsyncClient.newBuilder()
535529
.withCredential(basicCredentials)
536-
.withRegion(EcsRegion.CN_NORTH_4)
530+
.withEndpoint(endpoint)
537531
.withHttpConfig(config)
538532
.build();
539533

core/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<parent>
7+
<groupId>io.github.g42cloud-sdk</groupId>
8+
<version>0.0.3-beta</version>
9+
<artifactId>g42cloud-sdk</artifactId>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<packaging>jar</packaging>
14+
<artifactId>g42cloud-sdk-core</artifactId>
15+
<version>0.0.3-beta</version>
16+
<name>G42 Cloud SDK for Java Core</name>
17+
<description>Core library for G42 Cloud Java SDK</description>
18+
<url>https://github.com/g42cloud-sdk/g42cloud-sdk-java</url>
19+
20+
</project>
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Copyright (c) G42 Technologies Co., Ltd. 2021-2021. All rights reserved.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package com.g42cloud.sdk.core;
23+
24+
import com.g42cloud.sdk.core.auth.AbstractCredentials;
25+
import com.g42cloud.sdk.core.auth.BasicCredentials;
26+
import com.g42cloud.sdk.core.auth.CredentialProviderChain;
27+
import com.g42cloud.sdk.core.auth.ICredential;
28+
import com.g42cloud.sdk.core.exception.SdkException;
29+
import com.g42cloud.sdk.core.http.HttpClient;
30+
import com.g42cloud.sdk.core.http.HttpConfig;
31+
import com.g42cloud.sdk.core.impl.DefaultHttpClient;
32+
import com.g42cloud.sdk.core.region.Region;
33+
34+
import java.util.ArrayList;
35+
import java.util.Arrays;
36+
import java.util.Collections;
37+
import java.util.List;
38+
import java.util.Objects;
39+
import java.util.concurrent.ExecutionException;
40+
import java.util.function.Function;
41+
42+
/**
43+
* @author G42Cloud_SDK
44+
*/
45+
public class ClientBuilder<T> {
46+
private Function<HcClient, T> creator;
47+
48+
private ICredential credential;
49+
50+
private HttpConfig httpConfig;
51+
52+
private Region region;
53+
54+
private String endpoint;
55+
56+
private List<String> credentialType = new ArrayList<>(
57+
Collections.singletonList(BasicCredentials.class.getSimpleName()));
58+
59+
private String derivedAuthServiceName;
60+
61+
public ClientBuilder(Function<HcClient, T> creator) {
62+
this.creator = creator;
63+
}
64+
65+
public ClientBuilder(Function<HcClient, T> creator, String credentialType) {
66+
this.creator = creator;
67+
this.credentialType = Arrays.asList(credentialType.split(","));
68+
}
69+
70+
public ClientBuilder<T> withDerivedAuthServiceName(String derivedAuthServiceName) {
71+
this.derivedAuthServiceName = derivedAuthServiceName;
72+
return this;
73+
}
74+
75+
public ClientBuilder<T> withCredential(ICredential credential) {
76+
this.credential = credential;
77+
return this;
78+
}
79+
80+
public ClientBuilder<T> withHttpConfig(HttpConfig httpConfig) {
81+
this.httpConfig = httpConfig;
82+
return this;
83+
}
84+
85+
public ClientBuilder<T> withRegion(Region region) {
86+
this.region = region;
87+
return this;
88+
}
89+
90+
public ClientBuilder<T> withEndpoint(String endpoint) {
91+
this.endpoint = endpoint;
92+
return this;
93+
}
94+
95+
public T build() {
96+
if (Objects.isNull(httpConfig)) {
97+
httpConfig = HttpConfig.getDefaultHttpConfig();
98+
}
99+
100+
HttpClient httpClient = new DefaultHttpClient(httpConfig);
101+
HcClient hcClient = new HcClient(httpConfig, httpClient);
102+
103+
if (Objects.isNull(credential)) {
104+
CredentialProviderChain providerChain = CredentialProviderChain.getDefaultCredentialProviderChain(
105+
credentialType.get(0));
106+
credential = providerChain.getCredentials();
107+
}
108+
109+
if (Objects.isNull(credential)) {
110+
throw new SdkException(
111+
"credential can not be null, " + credentialType.toString() + "credential objects are required");
112+
}
113+
114+
if (!credentialType.contains(credential.getClass().getSimpleName())) {
115+
throw new SdkException("credential type error, supported credential type is " + credentialType);
116+
}
117+
118+
if (Objects.nonNull(region)) {
119+
endpoint = region.getEndpoint();
120+
try {
121+
hcClient.withCredential(credential);
122+
credential = credential.processAuthParams(hcClient, region.getId()).get();
123+
} catch (InterruptedException | ExecutionException e) {
124+
throw new SdkException(e);
125+
}
126+
127+
if (credential instanceof AbstractCredentials) {
128+
((AbstractCredentials<?>) credential).processDerivedAuthParams(derivedAuthServiceName, region.getId());
129+
}
130+
}
131+
132+
if (!endpoint.startsWith(Constants.HTTP_SCHEME)) {
133+
endpoint = Constants.HTTPS_SCHEME + "://" + endpoint;
134+
}
135+
136+
hcClient.withEndpoint(endpoint).withCredential(credential);
137+
138+
T t = creator.apply(hcClient);
139+
ClientCustomization clientCustomization = loadClientCustomization(t);
140+
if (Objects.nonNull(clientCustomization)) {
141+
clientCustomization.customize(hcClient);
142+
}
143+
144+
return t;
145+
}
146+
147+
private ClientCustomization loadClientCustomization(T t) {
148+
String strClientCustomizationClassName = t.getClass().getName() + Constants.CUSTOMIZATION;
149+
try {
150+
Class<?> customizationClass = Class.forName(strClientCustomizationClassName);
151+
return (ClientCustomization) customizationClass.newInstance();
152+
} catch (ClassNotFoundException e) {
153+
return null;
154+
} catch (InstantiationException | IllegalAccessException e) {
155+
throw new SdkException(e);
156+
}
157+
}
158+
159+
public Function<HcClient, T> getCreator() {
160+
return creator;
161+
}
162+
163+
public ICredential getCredential() {
164+
return credential;
165+
}
166+
167+
public HttpConfig getHttpConfig() {
168+
return httpConfig;
169+
}
170+
171+
public String getEndpoint() {
172+
return endpoint;
173+
}
174+
175+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) G42 Technologies Co., Ltd. 2021-2021. All rights reserved.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package com.g42cloud.sdk.core;
23+
24+
/**
25+
* @author G42Cloud_SDK
26+
*/
27+
public interface ClientCustomization {
28+
/**
29+
* Customized config of client
30+
* @param customizationConfigure CustomizationConfigure
31+
*/
32+
void customize(CustomizationConfigure customizationConfigure);
33+
}

0 commit comments

Comments
 (0)