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
9fde8bff
Commit
9fde8bff
authored
Jul 25, 2024
by
SN150021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化阿里云ESC api掉用Client
parent
819c7c2a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
2 deletions
+78
-2
pom.xml
pom.xml
+8
-2
AliEcsClient.java
...in/java/com/edgec/browserbackend/client/AliEcsClient.java
+70
-0
No files found.
pom.xml
View file @
9fde8bff
...
...
@@ -140,7 +140,7 @@
<artifactId>
joda-time
</artifactId>
<version>
2.10.3
</version>
</dependency>
<dependency>
<!--
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.0</version>
...
...
@@ -151,7 +151,7 @@
<artifactId>elasticsearch</artifactId>
<version>7.4.0</version>
<scope>provided</scope>
</dependency>
</dependency>
-->
<dependency>
<groupId>
net.javacrumbs.shedlock
</groupId>
<artifactId>
shedlock-spring
</artifactId>
...
...
@@ -188,6 +188,12 @@
<artifactId>
aspectjweaver
</artifactId >
<version>
1.8.7
</version >
</dependency>
<!--阿里云云服务器ECS api -->
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
ecs20140526
</artifactId>
<version>
5.1.9
</version>
</dependency>
</dependencies>
...
...
src/main/java/com/edgec/browserbackend/client/AliEcsClient.java
0 → 100644
View file @
9fde8bff
package
com
.
edgec
.
browserbackend
.
client
;
import
com.aliyun.ecs20140526.Client
;
import
com.aliyun.ecs20140526.models.DescribeInstancesRequest
;
import
com.aliyun.tea.TeaException
;
import
com.aliyun.teaopenapi.models.Config
;
import
com.aliyun.teautil.models.RuntimeOptions
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
/**
* @Description //阿里云ECS相关api
* url:https://next.api.aliyun.com/api-tools/sdk/Ecs?version=2014-05-26&language=java-tea&tab=primer-doc
**/
@Service
@RequiredArgsConstructor
@Slf4j
public
class
AliEcsClient
{
/*
* @Description //创建链接
* @Date 2024/7/25 10:32
**/
private
Client
createClient
()
throws
Exception
{
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
Config
config
=
new
Config
()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.
setAccessKeyId
(
System
.
getenv
(
"ALIBABA_CLOUD_ACCESS_KEY_ID"
))
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.
setAccessKeySecret
(
System
.
getenv
(
"ALIBABA_CLOUD_ACCESS_KEY_SECRET"
));
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config
.
endpoint
=
"ecs.cn-shenzhen.aliyuncs.com"
;
return
new
Client
(
config
);
}
/**
* @Description //查询实列
* @Date 2024/7/25 10:37
**/
public
void
getDescribeInstances
()
throws
Exception
{
java
.
util
.
List
<
String
>
args
=
java
.
util
.
Arrays
.
asList
(
"test"
);
Client
client
=
this
.
createClient
();
DescribeInstancesRequest
describeInstancesRequest
=
new
DescribeInstancesRequest
()
.
setRegionId
(
"cn-shenzhen"
);
RuntimeOptions
runtime
=
new
RuntimeOptions
();
try
{
// 复制代码运行请自行打印 API 的返回值
client
.
describeInstancesWithOptions
(
describeInstancesRequest
,
runtime
);
}
catch
(
TeaException
error
)
{
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System
.
out
.
println
(
error
.
getMessage
());
// 诊断地址
System
.
out
.
println
(
error
.
getData
().
get
(
"Recommend"
));
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
catch
(
Exception
_error
)
{
TeaException
error
=
new
TeaException
(
_error
.
getMessage
(),
_error
);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System
.
out
.
println
(
error
.
getMessage
());
// 诊断地址
System
.
out
.
println
(
error
.
getData
().
get
(
"Recommend"
));
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
}
}
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