Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
69d70863
Commit
69d70863
authored
Sep 02, 2024
by
SN150021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
引入腾讯云 ecs API
parent
4de233c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
4 deletions
+89
-4
pom.xml
pom.xml
+6
-0
AliEcsClient.java
.../com/edgec/browserbackend/common/client/AliEcsClient.java
+0
-4
TenCentEcsClient.java
.../edgec/browserbackend/common/client/TenCentEcsClient.java
+83
-0
No files found.
pom.xml
View file @
69d70863
...
@@ -194,6 +194,12 @@
...
@@ -194,6 +194,12 @@
<artifactId>
alibabacloud-ecs20140526
</artifactId>
<artifactId>
alibabacloud-ecs20140526
</artifactId>
<version>
5.0.13
</version>
<version>
5.0.13
</version>
</dependency>
</dependency>
<!--腾讯云 云服务器ECS api -->
<dependency>
<groupId>
com.tencentcloudapi
</groupId>
<artifactId>
tencentcloud-sdk-java
</artifactId>
<version>
3.1.830
</version>
</dependency>
</dependencies>
</dependencies>
...
...
src/main/java/com/edgec/browserbackend/common/client/AliEcsClient.java
View file @
69d70863
...
@@ -36,10 +36,6 @@ import org.springframework.stereotype.Service;
...
@@ -36,10 +36,6 @@ import org.springframework.stereotype.Service;
@Slf4j
@Slf4j
public
class
AliEcsClient
{
public
class
AliEcsClient
{
private
final
CloudPlatformConfigRepository
cloudPlatformConfigRepository
;
//access_key_id
//access_key_id
private
static
String
getAccessKeyId
()
{
private
static
String
getAccessKeyId
()
{
return
"LTAI5tEdz1DY4A4oYUawUuNH"
;
return
"LTAI5tEdz1DY4A4oYUawUuNH"
;
...
...
src/main/java/com/edgec/browserbackend/common/client/TenCentEcsClient.java
0 → 100644
View file @
69d70863
package
com
.
edgec
.
browserbackend
.
common
.
client
;
import
com.alibaba.fastjson.JSON
;
import
com.edgec.browserbackend.browser.domain.CloudPlatformConfig
;
import
com.edgec.browserbackend.common.utils.Aes
;
import
com.tencentcloudapi.common.Credential
;
import
com.tencentcloudapi.common.profile.HttpProfile
;
import
com.tencentcloudapi.common.profile.ClientProfile
;
import
com.tencentcloudapi.cvm.v20170312.CvmClient
;
import
com.tencentcloudapi.cvm.v20170312.models.*
;
import
darabonba.core.client.ClientOverrideConfiguration
;
import
java.util.concurrent.CompletableFuture
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
/**
* @Description //腾讯云ECS相关api
* @Date 2024/9/2 14:40
* @Author SN150021
**/
@Service
@RequiredArgsConstructor
@Slf4j
public
class
TenCentEcsClient
{
//SecretId
private
static
String
getSecretId
()
{
return
""
;
}
//SecretKey
private
static
String
getSecretKey
()
{
return
""
;
}
//脚本userData
private
static
String
getUserData
()
{
return
"#!/bin/sh\n"
+
"echo \"users %s:CL:%s\n"
+
"allow %s *\n"
+
"auth strong\n"
+
"proxy -p8880\n"
+
"proxy -p8881 -a\n"
+
"socks -p8882\n"
+
"flush\" | tee /etc/3proxy.cfg\n"
+
"systemctl restart 3proxy"
;
}
private
static
CvmClient
createClient
(
String
regionId
)
{
Credential
cred
=
new
Credential
(
getSecretId
(),
getSecretKey
());
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile
httpProfile
=
new
HttpProfile
();
httpProfile
.
setEndpoint
(
"cvm.tencentcloudapi.com"
);
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile
clientProfile
=
new
ClientProfile
();
clientProfile
.
setHttpProfile
(
httpProfile
);
// 实例化要请求产品的client对象,clientProfile是可选的
return
new
CvmClient
(
cred
,
regionId
,
clientProfile
);
}
/**
* 创建并运行实例
*/
public
static
RunInstancesResponse
runInstances
(
String
owner
,
String
username
,
String
password
,
CloudPlatformConfig
config
)
{
CvmClient
cvmClient
=
createClient
(
config
.
getRegionId
());
RunInstancesResponse
runInstancesResponse
=
null
;
String
userData
=
String
.
format
(
getUserData
(),
username
,
password
,
username
);
try
{
RunInstancesRequest
runInstancesRequest
=
new
RunInstancesRequest
();
log
.
info
(
"调用TenCentEcs创建并运行实例,入参:owner:{},regionId:{}"
,
owner
,
config
.
getRegionId
());
runInstancesResponse
=
cvmClient
.
RunInstances
(
runInstancesRequest
);
log
.
info
(
"调用TenCentEcs创建并运行实例,响应参数:owner:{},response:{}"
,
owner
,
JSON
.
toJSON
(
runInstancesResponse
));
}
catch
(
Exception
e
)
{
log
.
error
(
"fail to tenCentEcs runInstances {}"
,
e
.
getMessage
());
}
return
runInstancesResponse
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment