mirror of https://github.com/jumpserver/jumpserver
perf: merge with remote
commit
eb87e76b4b
|
@ -27,6 +27,12 @@ class IntegrationApplicationViewSet(OrgBulkModelViewSet):
|
||||||
'get_account_secret': 'accounts.view_integrationapplication'
|
'get_account_secret': 'accounts.view_integrationapplication'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def read_file(self, path):
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path, 'r', encoding='utf-8') as file:
|
||||||
|
return file.read()
|
||||||
|
return ''
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
['GET'], detail=False, url_path='sdks',
|
['GET'], detail=False, url_path='sdks',
|
||||||
permission_classes=[IsValidUser]
|
permission_classes=[IsValidUser]
|
||||||
|
@ -36,21 +42,18 @@ class IntegrationApplicationViewSet(OrgBulkModelViewSet):
|
||||||
'python': 'py',
|
'python': 'py',
|
||||||
'java': 'java',
|
'java': 'java',
|
||||||
'go': 'go',
|
'go': 'go',
|
||||||
'javascript': 'js',
|
'node': 'js',
|
||||||
'php': 'php',
|
'curl': 'sh',
|
||||||
}
|
}
|
||||||
sdk_language = request.query_params.get('language','python')
|
sdk_language = request.query_params.get('language','python')
|
||||||
sdk_path = os.path.join(settings.APPS_DIR, 'accounts', 'demos', sdk_language)
|
sdk_path = os.path.join(settings.APPS_DIR, 'accounts', 'demos', sdk_language)
|
||||||
readme_path = os.path.join(sdk_path, f'readme.{get_language()}.md')
|
readme_path = os.path.join(sdk_path, f'readme.{get_language()}.md')
|
||||||
demo_path = os.path.join(sdk_path, f'demo.{code_suffix_mapper[sdk_language]}')
|
demo_path = os.path.join(sdk_path, f'demo.{code_suffix_mapper[sdk_language]}')
|
||||||
|
|
||||||
def read_file(path):
|
readme_content = self.read_file(readme_path)
|
||||||
if os.path.exists(path):
|
demo_content = self.read_file(demo_path)
|
||||||
with open(path, 'r', encoding='utf-8') as f:
|
|
||||||
return f.read()
|
|
||||||
return ''
|
|
||||||
|
|
||||||
return Response(data={'readme': read_file(readme_path), 'code': read_file(demo_path)})
|
return Response(data={'readme': readme_content, 'code': demo_content})
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
['GET'], detail=True, url_path='secret',
|
['GET'], detail=True, url_path='secret',
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Instructions
|
||||||
|
|
||||||
|
## 1. Introduction
|
||||||
|
|
||||||
|
This API provides PAM asset account viewing service, supports RESTful style calls, and returns data in JSON format.
|
||||||
|
|
||||||
|
## 2. Environment Requirements
|
||||||
|
|
||||||
|
- `cURL`
|
||||||
|
|
||||||
|
## 3. Usage
|
||||||
|
|
||||||
|
**Request Method**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**Request Parameters**
|
||||||
|
|
||||||
|
| Parameter Name | Type | Required | Description |
|
||||||
|
|----------------|------|----------|-------------------|
|
||||||
|
| asset | str | Yes | Asset ID / Name |
|
||||||
|
| account | str | Yes | Account ID / Name |
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
|
Q: How to obtain the API Key?
|
||||||
|
|
||||||
|
A: You can create an application in PAM - Application Management to generate KEY_ID and KEY_SECRET.
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
|
||||||
|
| Version | Changes | Date |
|
||||||
|
|---------|------------------------|------------|
|
||||||
|
| 1.0.0 | Initial version | 2025-02-11 |
|
|
@ -0,0 +1,42 @@
|
||||||
|
# 使用方法
|
||||||
|
|
||||||
|
## 1. 概要
|
||||||
|
|
||||||
|
本 API は PAM 資産アカウントサービスの表示を提供し、RESTful スタイルの呼び出しをサポートし、データは JSON 形式で返されます。
|
||||||
|
|
||||||
|
## 2. 環境要件
|
||||||
|
|
||||||
|
- `cURL`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**リクエスト方法**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**リクエストパラメータ**
|
||||||
|
|
||||||
|
| パラメータ名 | タイプ | 必須 | 説明 |
|
||||||
|
|-------------|------|----|----------------|
|
||||||
|
| asset | str | はい | 資産 ID / 資産名 |
|
||||||
|
| account | str | はい | アカウント ID / アカウント名 |
|
||||||
|
|
||||||
|
|
||||||
|
**レスポンス例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## よくある質問(FAQ)
|
||||||
|
|
||||||
|
Q: APIキーはどのように取得しますか?
|
||||||
|
|
||||||
|
A: PAM - アプリケーション管理でアプリケーションを作成し、KEY_IDとKEY_SECRETを生成できます。
|
||||||
|
|
||||||
|
## バージョン履歴(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| バージョン | 変更内容 | 日付 |
|
||||||
|
| -------- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初期バージョン | 2025-02-11 |
|
|
@ -0,0 +1,40 @@
|
||||||
|
# 使用说明
|
||||||
|
|
||||||
|
## 1. 简介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看资产账号服务,支持 RESTful 风格的调用,返回数据采用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 环境要求
|
||||||
|
|
||||||
|
- `cURL`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**请求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**请求参数**
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 资产 ID / 资产名称 |
|
||||||
|
| account | str | 是 | 账号 ID / 账号名称 |
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见问题(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何获取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 应用管理 创建应用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本历史(Changelog)
|
||||||
|
|
||||||
|
| 版本号 | 变更内容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,39 @@
|
||||||
|
## 1. 簡介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看資產賬號服務,支持 RESTful 風格的調用,返回數據採用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 環境要求
|
||||||
|
|
||||||
|
- `cURL`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**請求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**請求參數**
|
||||||
|
|
||||||
|
| 參數名 | 類型 | 必填 | 說明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 資產 ID / 資產名稱 |
|
||||||
|
| account | str | 是 | 賬號 ID / 賬號名稱 |
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常見問題(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何獲取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 應用管理 創建應用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本歷史(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| 版本號 | 變更內容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 配置参数
|
||||||
|
API_URL=${API_URL:-"http://127.0.0.1:8080"}
|
||||||
|
KEY_ID=${API_KEY_ID:-"72b0b0aa-ad82-4182-a631-ae4865e8ae0e"}
|
||||||
|
KEY_SECRET=${API_KEY_SECRET:-"6fuSO7P1m4cj8SSlgaYdblOjNAmnxDVD7tr8"}
|
||||||
|
ORG_ID=${ORG_ID:-"00000000-0000-0000-0000-000000000002"}
|
||||||
|
|
||||||
|
# 查询参数
|
||||||
|
ASSET="ubuntu_docker"
|
||||||
|
ACCOUNT="root"
|
||||||
|
QUERY_STRING="asset=${ASSET}&account=${ACCOUNT}"
|
||||||
|
|
||||||
|
# 计算时间戳
|
||||||
|
DATE=$(date -u +"%a, %d %b %Y %H:%M:%S GMT")
|
||||||
|
|
||||||
|
# 计算 (request-target) 需要包含查询参数
|
||||||
|
REQUEST_TARGET="get /api/v1/accounts/integration-applications/account-secret/?${QUERY_STRING}"
|
||||||
|
|
||||||
|
# 生成签名字符串
|
||||||
|
SIGNING_STRING="(request-target): $REQUEST_TARGET
|
||||||
|
accept: application/json
|
||||||
|
date: $DATE
|
||||||
|
x-jms-org: $ORG_ID"
|
||||||
|
|
||||||
|
# 计算 HMAC-SHA256 签名
|
||||||
|
SIGNATURE=$(echo -n "$SIGNING_STRING" | openssl dgst -sha256 -hmac "$KEY_SECRET" -binary | base64)
|
||||||
|
|
||||||
|
# 发送请求
|
||||||
|
curl -G "$API_URL/api/v1/accounts/integration-applications/account-secret/" \
|
||||||
|
-H "Accept: application/json" \
|
||||||
|
-H "Date: $DATE" \
|
||||||
|
-H "X-JMS-ORG: $ORG_ID" \
|
||||||
|
-H "X-Source: jms-pam" \
|
||||||
|
-H "Authorization: Signature keyId=\"$KEY_ID\",algorithm=\"hmac-sha256\",headers=\"(request-target) accept date x-jms-org\",signature=\"$SIGNATURE\"" \
|
||||||
|
--data-urlencode "asset=$ASSET" \
|
||||||
|
--data-urlencode "account=$ACCOUNT"
|
|
@ -1,133 +1,45 @@
|
||||||
# JumpServer PAM Client
|
# Instructions
|
||||||
|
|
||||||
This package provides a Go client for interacting with the JumpServer PAM API to retrieve secrets for various assets. It simplifies the process of sending requests and handling responses.
|
## 1. Introduction
|
||||||
|
|
||||||
## Features
|
This API provides the PAM asset account service, supports RESTful style calls, and returns data in JSON format.
|
||||||
|
|
||||||
- Validate parameters before sending requests.
|
## 2. Environment Requirements
|
||||||
- Support for both asset and account-based secret retrieval.
|
|
||||||
- Easy integration with JumpServer PAM API using HMAC-SHA256 signatures for authentication.
|
|
||||||
|
|
||||||
## Usage Instructions
|
|
||||||
|
|
||||||
1. **Download Go Code Files**:
|
|
||||||
Download the code files into your project directory.
|
|
||||||
|
|
||||||
2. **Import the Package**:
|
|
||||||
Import the package in your Go file, and you can directly use its functionalities.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- `Go 1.16+`
|
- `Go 1.16+`
|
||||||
- `github.com/google/uuid`
|
- `crypto/hmac`
|
||||||
- `gopkg.in/twindagger/httpsig.v1`
|
- `crypto/sha256`
|
||||||
|
- `encoding/base64`
|
||||||
|
- `net/http`
|
||||||
|
|
||||||
## Usage
|
## 3. Usage
|
||||||
|
|
||||||
### Initialization
|
**Request Method**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
To use the JumpServer PAM client, create an instance by providing the required `endpoint`, `keyID`, and `keySecret`.
|
**Request Parameters**
|
||||||
|
|
||||||
```go
|
| Parameter Name | Type | Required | Description |
|
||||||
package main
|
|----------------|------|----------|-------------------|
|
||||||
|
| asset | str | Yes | Asset ID / Asset Name |
|
||||||
|
| account | str | Yes | Account ID / Account Name |
|
||||||
|
|
||||||
import (
|
**Response Example**:
|
||||||
"fmt"
|
```json
|
||||||
|
{
|
||||||
"your_module_path/jms_pam"
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
)
|
"secret": "123456"
|
||||||
|
|
||||||
func main() {
|
|
||||||
client := jms_pam.NewJumpServerPAM(
|
|
||||||
"http://127.0.0.1", // Replace with your JumpServer endpoint
|
|
||||||
"your-key-id", // Replace with your actual Key ID
|
|
||||||
"your-key-secret", // Replace with your actual Key Secret
|
|
||||||
"", // Leave empty for default organization ID
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating a Secret Request
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
You can create a request for a secret by specifying the asset or account information.
|
Q: How to obtain the API Key?
|
||||||
|
|
||||||
```go
|
A: You can create an application in PAM - Application Management to generate KEY_ID and KEY_SECRET.
|
||||||
request, err := jms_pam.NewSecretRequest("Linux", "", "root", "")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error creating request:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sending the Request
|
## Changelog
|
||||||
|
|
||||||
Send the request using the `Send` method of the client.
|
|
||||||
|
|
||||||
```go
|
| Version | Changes | Date |
|
||||||
secretObj, err := client.Send(request)
|
|---------|------------------------|------------|
|
||||||
if err != nil {
|
| 1.0.0 | Initial version | 2025-02-11 |
|
||||||
fmt.Println("Error sending request:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Handling the Response
|
|
||||||
|
|
||||||
Check if the secret was retrieved successfully and handle the response accordingly.
|
|
||||||
|
|
||||||
```go
|
|
||||||
if secretObj.Valid {
|
|
||||||
fmt.Println("Secret:", secretObj.Secret)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Get secret failed:", string(secretObj.Desc))
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Complete Example
|
|
||||||
|
|
||||||
Here’s a complete example of how to use the client:
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"your_module_path/jms_pam"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
client := jms_pam.NewJumpServerPAM(
|
|
||||||
"http://127.0.0.1",
|
|
||||||
"your-key-id",
|
|
||||||
"your-key-secret",
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
|
|
||||||
request, err := jms_pam.NewSecretRequest("Linux", "", "root", "")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error creating request:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
secretObj, err := client.Send(request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error sending request:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if secretObj.Valid {
|
|
||||||
fmt.Println("Secret:", secretObj.Secret)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Get secret failed:", string(secretObj.Desc))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Error Handling
|
|
||||||
|
|
||||||
The library returns errors for invalid parameters when creating a `SecretRequest`. This includes checks for valid UUIDs and ensuring that required parameters are provided.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
|
|
||||||
|
|
|
@ -1,133 +1,45 @@
|
||||||
# JumpServer PAM クライアント
|
# 使用方法
|
||||||
|
|
||||||
このパッケージは、JumpServer PAM API と対話し、さまざまな資産のパスワードを取得するための Go クライアントを提供します。リクエストの送信とレスポンスの処理を簡素化します。
|
## 1. 概要
|
||||||
|
|
||||||
## 機能
|
このAPIは、PAMの資産アカウントサービスの表示を提供し、RESTfulスタイルの呼び出しをサポートし、データはJSON形式で返されます。
|
||||||
|
|
||||||
- リクエスト送信前にパラメータを検証します。
|
## 2. 環境要件
|
||||||
- 資産およびアカウントに基づくパスワード取得をサポートします。
|
|
||||||
- HMAC-SHA256 署名を使用して認証を行い、JumpServer PAM API との統合を容易にします。
|
|
||||||
|
|
||||||
## 使用手順
|
|
||||||
|
|
||||||
1. **Go コードファイルのダウンロード**:
|
|
||||||
コードファイルをプロジェクトディレクトリにダウンロードします。
|
|
||||||
|
|
||||||
2. **パッケージのインポート**:
|
|
||||||
Go ファイルにパッケージをインポートすると、その機能を直接使用できます。
|
|
||||||
|
|
||||||
## 要件
|
|
||||||
|
|
||||||
- `Go 1.16+`
|
- `Go 1.16+`
|
||||||
- `github.com/google/uuid`
|
- `crypto/hmac`
|
||||||
- `gopkg.in/twindagger/httpsig.v1`
|
- `crypto/sha256`
|
||||||
|
- `encoding/base64`
|
||||||
|
- `net/http`
|
||||||
|
|
||||||
## 使用方法
|
## 3. 使用方法
|
||||||
|
|
||||||
### 初期化
|
**リクエスト方法**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
JumpServer PAM クライアントを使用するには、必要な `endpoint`、`keyID`、および `keySecret` を提供してインスタンスを作成します。
|
**リクエストパラメータ**
|
||||||
|
|
||||||
```go
|
| パラメータ名 | タイプ | 必須 | 説明 |
|
||||||
package main
|
|-------------|-------|----|--------------|
|
||||||
|
| asset | str | はい | 資産ID / 資産名 |
|
||||||
|
| account | str | はい | アカウントID / アカウント名 |
|
||||||
|
|
||||||
import (
|
**レスポンス例**:
|
||||||
"fmt"
|
```json
|
||||||
|
{
|
||||||
"your_module_path/jms_pam"
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
)
|
"secret": "123456"
|
||||||
|
|
||||||
func main() {
|
|
||||||
client := jms_pam.NewJumpServerPAM(
|
|
||||||
"http://127.0.0.1", // あなたの JumpServer エンドポイントに置き換えてください
|
|
||||||
"your-key-id", // 実際の Key ID に置き換えてください
|
|
||||||
"your-key-secret", // 実際の Key Secret に置き換えてください
|
|
||||||
"", // デフォルトの組織 ID を使用するには空のままにします
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### パスワードリクエストの作成
|
## よくある質問(FAQ)
|
||||||
|
|
||||||
資産またはアカウント情報を指定してリクエストを作成できます。
|
Q: APIキーはどのように取得しますか?
|
||||||
|
|
||||||
```go
|
A: PAM - アプリケーション管理でアプリケーションを作成し、KEY_IDとKEY_SECRETを生成できます。
|
||||||
request, err := jms_pam.NewSecretRequest("Linux", "", "root", "")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("リクエスト作成中にエラー:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### リクエストの送信
|
## バージョン履歴(Changelog)
|
||||||
|
|
||||||
クライアントの `Send` メソッドを使用してリクエストを送信します。
|
|
||||||
|
|
||||||
```go
|
| バージョン | 変更内容 | 日付 |
|
||||||
secretObj, err := client.Send(request)
|
| -------- | ----------------- |------------|
|
||||||
if err != nil {
|
| 1.0.0 | 初期バージョン | 2025-02-11 |
|
||||||
fmt.Println("リクエスト送信中にエラー:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### レスポンスの処理
|
|
||||||
|
|
||||||
パスワードが正常に取得されたかどうかを確認し、それに応じてレスポンスを処理します。
|
|
||||||
|
|
||||||
```go
|
|
||||||
if secretObj.Valid {
|
|
||||||
fmt.Println("パスワード:", secretObj.Secret)
|
|
||||||
} else {
|
|
||||||
fmt.Println("パスワードの取得に失敗:", string(secretObj.Desc))
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 完全な例
|
|
||||||
|
|
||||||
以下は、クライアントの使用方法に関する完全な例です。
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"your_module_path/jms_pam"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
client := jms_pam.NewJumpServerPAM(
|
|
||||||
"http://127.0.0.1",
|
|
||||||
"your-key-id",
|
|
||||||
"your-key-secret",
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
|
|
||||||
request, err := jms_pam.NewSecretRequest("Linux", "", "root", "")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("リクエスト作成中にエラー:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
secretObj, err := client.Send(request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("リクエスト送信中にエラー:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if secretObj.Valid {
|
|
||||||
fmt.Println("パスワード:", secretObj.Secret)
|
|
||||||
} else {
|
|
||||||
fmt.Println("パスワードの取得に失敗:", string(secretObj.Desc))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## エラーハンドリング
|
|
||||||
|
|
||||||
このライブラリは、`SecretRequest` を作成する際に無効なパラメータに対するエラーを返します。これには、有効な UUID の確認や、必要なパラメータが提供されていることの確認が含まれます。
|
|
||||||
|
|
||||||
## 貢献
|
|
||||||
|
|
||||||
貢献を歓迎します!改善やバグ修正のために問題を提起したり、プルリクエストを送信してください。
|
|
||||||
|
|
|
@ -1,26 +1,46 @@
|
||||||
# JumpServer PAM 客戶端
|
## 1. 簡介
|
||||||
|
|
||||||
該包提供了一個 Go 客戶端,用於與 JumpServer PAM API 交互,以檢索各種資產的密碼。它簡化了發送請求和處理響應的過程。
|
本 API 提供了 PAM 查看資產賬號服務,支持 RESTful 風格的調用,返回數據採用 JSON 格式。
|
||||||
|
|
||||||
## 功能
|
## 2. 環境要求
|
||||||
|
|
||||||
- 在發送請求之前驗證參數。
|
|
||||||
- 支持基於資產和帳戶的密碼檢索。
|
|
||||||
- 使用 HMAC-SHA256 簽名進行身份驗證,方便與 JumpServer PAM API 集成。
|
|
||||||
|
|
||||||
## 使用說明
|
|
||||||
|
|
||||||
1. **下載 Go 代碼文件**:
|
|
||||||
將代碼文件下載到您的項目目錄中。
|
|
||||||
|
|
||||||
2. **導入包**:
|
|
||||||
在您的 Go 文件中導入該包,您即可直接使用其功能。
|
|
||||||
|
|
||||||
## 需求
|
|
||||||
|
|
||||||
- `Go 1.16+`
|
- `Go 1.16+`
|
||||||
- `github.com/google/uuid`
|
- `crypto/hmac`
|
||||||
- `gopkg.in/twindagger/httpsig.v1`
|
- `crypto/sha256`
|
||||||
|
- `encoding/base64`
|
||||||
|
- `net/http`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**請求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**請求參數**
|
||||||
|
|
||||||
|
| 參數名 | 類型 | 必填 | 說明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 資產 ID / 資產名稱 |
|
||||||
|
| account | str | 是 | 賬號 ID / 賬號名稱 |
|
||||||
|
|
||||||
|
**響應示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常見問題(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何獲取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 應用管理 創建應用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本歷史(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| 版本號 | 變更內容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Base64;
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
public class Demo {
|
||||||
|
private static final String API_URL = System.getenv().getOrDefault("API_URL", "http://127.0.0.1:8080");
|
||||||
|
private static final String KEY_ID = System.getenv().getOrDefault("API_KEY_ID", "72b0b0aa-ad82-4182-a631-ae4865e8ae0e");
|
||||||
|
private static final String KEY_SECRET = System.getenv().getOrDefault("API_KEY_SECRET", "6fuSO7P1m4cj8SSlgaYdblOjNAmnxDVD7tr8");
|
||||||
|
private static final String ORG_ID = System.getenv().getOrDefault("ORG_ID", "00000000-0000-0000-0000-000000000002");
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
APIClient client = new APIClient();
|
||||||
|
String result = client.getAccountSecret("ubuntu_docker", "root");
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class APIClient {
|
||||||
|
private final HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
public String getAccountSecret(String asset, String account) throws Exception {
|
||||||
|
// 编码 URL 参数
|
||||||
|
String queryString = "asset=" + URLEncoder.encode(asset, StandardCharsets.UTF_8) +
|
||||||
|
"&account=" + URLEncoder.encode(account, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
// 完整的 URL(带参数)
|
||||||
|
String url = API_URL + "/api/v1/accounts/integration-applications/account-secret/?" + queryString;
|
||||||
|
|
||||||
|
// 获取当前 UTC 时间
|
||||||
|
String date = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME);
|
||||||
|
|
||||||
|
// 构造 (request-target),包括查询参数
|
||||||
|
String requestTarget = "get /api/v1/accounts/integration-applications/account-secret/?" + queryString;
|
||||||
|
|
||||||
|
// 生成签名字符串
|
||||||
|
String signingString = "(request-target): " + requestTarget + "\n" +
|
||||||
|
"accept: application/json\n" +
|
||||||
|
"date: " + date + "\n" +
|
||||||
|
"x-jms-org: " + ORG_ID;
|
||||||
|
String signature = sign(signingString, KEY_SECRET);
|
||||||
|
|
||||||
|
// 构造 HTTP 请求
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("Date", date)
|
||||||
|
.header("X-JMS-ORG", ORG_ID)
|
||||||
|
.header("X-Source", "jms-pam")
|
||||||
|
.header("Authorization", "Signature keyId=\"" + KEY_ID + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) accept date x-jms-org\",signature=\"" + signature + "\"")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
if (response.statusCode() == 200) {
|
||||||
|
return response.body();
|
||||||
|
} else {
|
||||||
|
System.err.println("API 请求失败: " + response.statusCode());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HMAC-SHA256 签名计算
|
||||||
|
private String sign(String data, String key) throws Exception {
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA256");
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
||||||
|
mac.init(secretKeySpec);
|
||||||
|
byte[] rawHmac = mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
|
||||||
|
return Base64.getEncoder().encodeToString(rawHmac);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Instructions
|
||||||
|
|
||||||
|
## 1. Introduction
|
||||||
|
|
||||||
|
This API provides PAM asset account viewing service, supports RESTful style calls, and returns data in JSON format.
|
||||||
|
|
||||||
|
## 2. Environment Requirements
|
||||||
|
|
||||||
|
- `Java 8+`
|
||||||
|
- `HttpClient`
|
||||||
|
|
||||||
|
## 3. Usage
|
||||||
|
|
||||||
|
**Request Method**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**Request Parameters**
|
||||||
|
|
||||||
|
| Parameter Name | Type | Required | Description |
|
||||||
|
|----------------|------|----------|-------------------|
|
||||||
|
| asset | str | Yes | Asset ID / Name |
|
||||||
|
| account | str | Yes | Account ID / Name |
|
||||||
|
|
||||||
|
**Response Example**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
|
Q: How to obtain the API Key?
|
||||||
|
|
||||||
|
A: You can create an application in PAM - Application Management to generate KEY_ID and KEY_SECRET.
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
|
||||||
|
| Version | Changes | Date |
|
||||||
|
|---------|------------------------|------------|
|
||||||
|
| 1.0.0 | Initial version | 2025-02-11 |
|
|
@ -0,0 +1,42 @@
|
||||||
|
# 使用方法
|
||||||
|
|
||||||
|
## 1. 概要
|
||||||
|
|
||||||
|
本 API は PAM 資産アカウントサービスの表示を提供し、RESTful スタイルの呼び出しをサポートし、データは JSON 形式で返されます。
|
||||||
|
|
||||||
|
## 2. 環境要件
|
||||||
|
|
||||||
|
- `Java 8+`
|
||||||
|
- `HttpClient`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**リクエスト方法**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**リクエストパラメータ**
|
||||||
|
|
||||||
|
| パラメータ名 | タイプ | 必須 | 説明 |
|
||||||
|
|-------------|------|----|----------------|
|
||||||
|
| asset | str | はい | 資産 ID / 資産名 |
|
||||||
|
| account | str | はい | アカウント ID / アカウント名 |
|
||||||
|
|
||||||
|
**レスポンス例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## よくある質問(FAQ)
|
||||||
|
|
||||||
|
Q: APIキーはどのように取得しますか?
|
||||||
|
|
||||||
|
A: PAM - アプリケーション管理でアプリケーションを作成し、KEY_IDとKEY_SECRETを生成できます。
|
||||||
|
|
||||||
|
## バージョン履歴(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| バージョン | 変更内容 | 日付 |
|
||||||
|
| -------- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初期バージョン | 2025-02-11 |
|
|
@ -0,0 +1,41 @@
|
||||||
|
# 使用说明
|
||||||
|
|
||||||
|
## 1. 简介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看资产账号服务,支持 RESTful 风格的调用,返回数据采用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 环境要求
|
||||||
|
|
||||||
|
- `Java 8+`
|
||||||
|
- `HttpClient`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**请求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**请求参数**
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 资产 ID / 资产名称 |
|
||||||
|
| account | str | 是 | 账号 ID / 账号名称 |
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见问题(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何获取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 应用管理 创建应用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本历史(Changelog)
|
||||||
|
|
||||||
|
| 版本号 | 变更内容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,40 @@
|
||||||
|
## 1. 簡介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看資產賬號服務,支持 RESTful 風格的調用,返回數據採用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 環境要求
|
||||||
|
|
||||||
|
- `Java 8+`
|
||||||
|
- `HttpClient`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**請求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**請求參數**
|
||||||
|
|
||||||
|
| 參數名 | 類型 | 必填 | 說明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 資產 ID / 資產名稱 |
|
||||||
|
| account | str | 是 | 賬號 ID / 賬號名稱 |
|
||||||
|
|
||||||
|
**響應示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常見問題(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何獲取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 應用管理 創建應用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本歷史(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| 版本號 | 變更內容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Instructions
|
||||||
|
|
||||||
|
## 1. Introduction
|
||||||
|
|
||||||
|
This API provides PAM asset account viewing service, supports RESTful style calls, and returns data in JSON format.
|
||||||
|
|
||||||
|
## 2. Environment Requirements
|
||||||
|
|
||||||
|
- `Node.js 16+`
|
||||||
|
- `axios ^1.7.9`
|
||||||
|
- `moment ^2.30.1`
|
||||||
|
|
||||||
|
## 3. Usage
|
||||||
|
|
||||||
|
**Request Method**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**Request Parameters**
|
||||||
|
|
||||||
|
| Parameter Name | Type | Required | Description |
|
||||||
|
|----------------|------|----------|-------------------|
|
||||||
|
| asset | str | Yes | Asset ID / Name |
|
||||||
|
| account | str | Yes | Account ID / Name |
|
||||||
|
|
||||||
|
**Response Example**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
|
Q: How to obtain the API Key?
|
||||||
|
|
||||||
|
A: You can create an application in PAM - Application Management to generate KEY_ID and KEY_SECRET.
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
|
||||||
|
| Version | Changes | Date |
|
||||||
|
|---------|------------------------|------------|
|
||||||
|
| 1.0.0 | Initial version | 2025-02-11 |
|
|
@ -0,0 +1,41 @@
|
||||||
|
# 使用方法
|
||||||
|
|
||||||
|
## 1. 概要
|
||||||
|
|
||||||
|
本 API は PAM 資産アカウントサービスの表示を提供し、RESTful スタイルの呼び出しをサポートし、データは JSON 形式で返されます。
|
||||||
|
|
||||||
|
## 2. 環境要件
|
||||||
|
|
||||||
|
- `Node.js 16+`
|
||||||
|
- `axios ^1.7.9`
|
||||||
|
- `moment ^2.30.1`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**リクエスト方法**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**リクエストパラメータ**
|
||||||
|
|
||||||
|
| パラメータ名 | タイプ | 必須 | 説明 |
|
||||||
|
|-------------|------|----|----------------|
|
||||||
|
| asset | str | はい | 資産 ID / 資産名 |
|
||||||
|
| account | str | はい | アカウント ID / アカウント名 |
|
||||||
|
|
||||||
|
**レスポンス例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
よくある質問(FAQ)
|
||||||
|
|
||||||
|
Q: API キーはどのように取得しますか?
|
||||||
|
|
||||||
|
A: PAM - アプリケーション管理でアプリケーションを作成し、KEY_ID と KEY_SECRET を生成できます。
|
||||||
|
|
||||||
|
バージョン履歴(Changelog)
|
||||||
|
|
||||||
|
| バージョン | 変更内容 | 日付 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,42 @@
|
||||||
|
# 使用说明
|
||||||
|
|
||||||
|
## 1. 简介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看资产账号服务,支持 RESTful 风格的调用,返回数据采用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 环境要求
|
||||||
|
|
||||||
|
- `Node.js 16+`
|
||||||
|
- `axios ^1.7.9`
|
||||||
|
- `moment ^2.30.1`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**请求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**请求参数**
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 必填 | 说明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 资产 ID / 资产名称 |
|
||||||
|
| account | str | 是 | 账号 ID / 账号名称 |
|
||||||
|
|
||||||
|
**响应示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见问题(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何获取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 应用管理 创建应用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本历史(Changelog)
|
||||||
|
|
||||||
|
| 版本号 | 变更内容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,41 @@
|
||||||
|
## 1. 簡介
|
||||||
|
|
||||||
|
本 API 提供了 PAM 查看資產賬號服務,支持 RESTful 風格的調用,返回數據採用 JSON 格式。
|
||||||
|
|
||||||
|
## 2. 環境要求
|
||||||
|
|
||||||
|
- `Node.js 16+`
|
||||||
|
- `axios ^1.7.9`
|
||||||
|
- `moment ^2.30.1`
|
||||||
|
|
||||||
|
## 3. 使用方法
|
||||||
|
|
||||||
|
**請求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
|
**請求參數**
|
||||||
|
|
||||||
|
| 參數名 | 類型 | 必填 | 說明 |
|
||||||
|
|----------|------|-----|---------------|
|
||||||
|
| asset | str | 是 | 資產 ID / 資產名稱 |
|
||||||
|
| account | str | 是 | 賬號 ID / 賬號名稱 |
|
||||||
|
|
||||||
|
**響應示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常見問題(FAQ)
|
||||||
|
|
||||||
|
Q: API Key 如何獲取?
|
||||||
|
|
||||||
|
A: 你可以在 PAM - 應用管理 創建應用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
|
## 版本歷史(Changelog)
|
||||||
|
|
||||||
|
|
||||||
|
| 版本號 | 變更內容 | 日期 |
|
||||||
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
|
@ -0,0 +1,56 @@
|
||||||
|
const axios = require('axios');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
|
const API_URL = process.env.API_URL || "http://127.0.0.1:8080";
|
||||||
|
const KEY_ID = process.env.API_KEY_ID || "72b0b0aa-ad82-4182-a631-ae4865e8ae0e";
|
||||||
|
const KEY_SECRET = process.env.API_KEY_SECRET || "6fuSO7P1m4cj8SSlgaYdblOjNAmnxDVD7tr8";
|
||||||
|
const ORG_ID = process.env.ORG_ID || "00000000-0000-0000-0000-000000000002";
|
||||||
|
|
||||||
|
class APIClient {
|
||||||
|
constructor() {
|
||||||
|
this.apiUrl = API_URL;
|
||||||
|
this.keyId = KEY_ID;
|
||||||
|
this.keySecret = KEY_SECRET;
|
||||||
|
this.orgId = ORG_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
signRequest(method, url, params, headers) {
|
||||||
|
const date = moment().utc().format('ddd, DD MMM YYYY HH:mm:ss [GMT]');
|
||||||
|
const queryString = Object.keys(params).length ? `?${new URLSearchParams(params).toString()}` : "";
|
||||||
|
const requestTarget = `${method.toLowerCase()} ${url}${queryString}`;
|
||||||
|
headers['Date'] = date;
|
||||||
|
headers['X-JMS-ORG'] = this.orgId;
|
||||||
|
const signingString = `(request-target): ${requestTarget}\naccept: application/json\ndate: ${date}\nx-jms-org: ${this.orgId}`;
|
||||||
|
const signature = crypto.createHmac('sha256', this.keySecret).update(signingString).digest('base64');
|
||||||
|
headers['Authorization'] = `Signature keyId="${this.keyId}",algorithm="hmac-sha256",headers="(request-target) accept date x-jms-org",signature="${signature}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAccountSecret(asset, account) {
|
||||||
|
const url = `/api/v1/accounts/integration-applications/account-secret/`;
|
||||||
|
const params = { asset: asset, account: account };
|
||||||
|
const headers = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-Source': 'jms-pam'
|
||||||
|
};
|
||||||
|
this.signRequest('GET', url, params, headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${this.apiUrl}${url}`, {
|
||||||
|
headers: headers,
|
||||||
|
params: params,
|
||||||
|
timeout: 10000
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`API 请求失败: ${error}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const client = new APIClient();
|
||||||
|
const result = await client.getAccountSecret("ubuntu_docker", "root");
|
||||||
|
console.log(result);
|
||||||
|
})();
|
|
@ -1,96 +1,42 @@
|
||||||
# JumpServer PAM Client
|
# Instructions
|
||||||
|
|
||||||
This package provides a Python client for interacting with the JumpServer PAM API to retrieve secrets for various assets. It simplifies the process of sending requests and handling responses.
|
## 1. Introduction
|
||||||
|
|
||||||
## Features
|
This API provides the PAM asset account service, supports RESTful style calls, and returns data in JSON format.
|
||||||
|
|
||||||
- Validate parameters before sending requests.
|
## 2. Environment Requirements
|
||||||
- Support for both asset and account-based secret retrieval.
|
|
||||||
- Easy integration with JumpServer PAM API using HTTP signatures for authentication.
|
|
||||||
|
|
||||||
## Installation
|
- `Python 3.11+`
|
||||||
|
- `requests==2.31.0`
|
||||||
|
- `httpsig==1.3.0`
|
||||||
|
|
||||||
You can install the package via pip:
|
## 3. Usage
|
||||||
|
**Request Method**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
```bash
|
**Request Parameters**
|
||||||
pip install jms_pam-0.0.1-py3-none-any.whl
|
|
||||||
|
| Parameter Name | Type | Required | Description |
|
||||||
|
|----------------|------|----------|-------------------|
|
||||||
|
| asset | str | Yes | Asset ID / Asset Name |
|
||||||
|
| account | str | Yes | Account ID / Account Name |
|
||||||
|
|
||||||
|
**Response Example**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requirements
|
## Frequently Asked Questions (FAQ)
|
||||||
|
|
||||||
- `Python 3.6+`
|
Q: How to obtain the API Key?
|
||||||
- `requests`
|
|
||||||
- `httpsig`
|
|
||||||
|
|
||||||
## Usage
|
A: You can create an application in PAM - Application Management to generate KEY_ID and KEY_SECRET.
|
||||||
|
|
||||||
### Initialization
|
## Changelog
|
||||||
|
|
||||||
To use the JumpServer PAM client, create an instance by providing the required `endpoint`, `key_id`, and `key_secret`.
|
|
||||||
|
|
||||||
```python
|
| Version | Changes | Date |
|
||||||
from jms_pam import JumpServerPAM, SecretRequest
|
|---------|------------------------|------------|
|
||||||
|
| 1.0.0 | Initial version | 2025-02-11 |
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Creating a Secret Request
|
|
||||||
|
|
||||||
You can create a request for a secret by specifying the asset or account information.
|
|
||||||
|
|
||||||
```python
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sending the Request
|
|
||||||
|
|
||||||
Send the request using the `send` method of the client.
|
|
||||||
|
|
||||||
```python
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Handling the Response
|
|
||||||
|
|
||||||
Check if the secret was retrieved successfully and handle the response accordingly.
|
|
||||||
|
|
||||||
```python
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('Secret: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('Get secret failed: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Complete Example
|
|
||||||
|
|
||||||
Here’s a complete example of how to use the client:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from jumpserver_pam_client import JumpServerPAM, SecretRequest
|
|
||||||
|
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('Secret: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('Get secret failed: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Error Handling
|
|
||||||
|
|
||||||
The library raises `RequestParamsError` if the parameters provided do not meet the validation requirements. This includes checks for valid UUIDs and interdependencies between parameters.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
|
|
||||||
|
|
|
@ -1,96 +1,42 @@
|
||||||
# JumpServer PAM クライアント
|
# 使用方法
|
||||||
|
|
||||||
このパッケージは、JumpServer PAM API と対話し、さまざまなアセットのシークレットを取得するための Python クライアントを提供します。リクエストを送信し、レスポンスを処理するプロセスを簡素化します。
|
## 1. 概要
|
||||||
|
|
||||||
## 特徴
|
このAPIは、PAMの資産アカウントサービスの表示を提供し、RESTfulスタイルの呼び出しをサポートし、データはJSON形式で返されます。
|
||||||
|
|
||||||
- リクエストを送信する前にパラメータを検証します。
|
## 2. 環境要件
|
||||||
- アセットおよびアカウントベースのシークレット取得をサポートします。
|
|
||||||
- HTTP 署名を使用して JumpServer PAM API と簡単に統合できます。
|
|
||||||
|
|
||||||
## インストール
|
- `Python 3.11+`
|
||||||
|
- `requests==2.31.0`
|
||||||
|
- `httpsig==1.3.0`
|
||||||
|
|
||||||
以下のコマンドを使用して、パッケージを pip でインストールできます:
|
## 3. 使用方法
|
||||||
|
**リクエスト方法**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
```bash
|
**リクエストパラメータ**
|
||||||
pip install jms_pam-0.0.1-py3-none-any.whl
|
|
||||||
|
| パラメータ名 | タイプ | 必須 | 説明 |
|
||||||
|
|-------------|-------|----|--------------|
|
||||||
|
| asset | str | はい | 資産ID / 資産名 |
|
||||||
|
| account | str | はい | アカウントID / アカウント名 |
|
||||||
|
|
||||||
|
**レスポンス例**:
|
||||||
|
```json
|
||||||
|
{fi
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 要件
|
## よくある質問(FAQ)
|
||||||
|
|
||||||
- `Python 3.6+`
|
Q: APIキーはどのように取得しますか?
|
||||||
- `requests`
|
|
||||||
- `httpsig`
|
|
||||||
|
|
||||||
## 使用方法
|
A: PAM - アプリケーション管理でアプリケーションを作成し、KEY_IDとKEY_SECRETを生成できます。
|
||||||
|
|
||||||
### 初期化
|
## バージョン履歴(Changelog)
|
||||||
|
|
||||||
JumpServer PAM クライアントを使用するには、必要な `endpoint`、`key_id`、および `key_secret` を提供してインスタンスを作成します。
|
|
||||||
|
|
||||||
```python
|
| バージョン | 変更内容 | 日付 |
|
||||||
from jms_pam import JumpServerPAM, SecretRequest
|
| -------- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初期バージョン | 2025-02-11 |
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### シークレットリクエストの作成
|
|
||||||
|
|
||||||
アセットまたはアカウント情報を指定して、シークレットのリクエストを作成できます。
|
|
||||||
|
|
||||||
```python
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
```
|
|
||||||
|
|
||||||
### リクエストの送信
|
|
||||||
|
|
||||||
クライアントの `send` メソッドを使用してリクエストを送信します。
|
|
||||||
|
|
||||||
```python
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
```
|
|
||||||
|
|
||||||
### レスポンスの処理
|
|
||||||
|
|
||||||
シークレットが正常に取得されたかどうかを確認し、レスポンスを適切に処理します。
|
|
||||||
|
|
||||||
```python
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('秘密: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('シークレットの取得に失敗しました: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 完全な例
|
|
||||||
|
|
||||||
以下は、クライアントの使用方法の完全な例です:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from jumpserver_pam_client import JumpServerPAM, SecretRequest
|
|
||||||
|
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('秘密: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('シークレットの取得に失敗しました: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
## エラーハンドリング
|
|
||||||
|
|
||||||
ライブラリは、提供されたパラメータが検証要件を満たしていない場合に `RequestParamsError` を発生させます。これには、有効な UUID の確認やパラメータ間の相互依存性のチェックが含まれます。
|
|
||||||
|
|
||||||
## 貢献
|
|
||||||
|
|
||||||
貢献を歓迎します!改善やバグ修正のために、問題を開くかプルリクエストを送信してください。
|
|
||||||
|
|
|
@ -1,96 +1,42 @@
|
||||||
# JumpServer PAM 客戶端
|
# 使用說明
|
||||||
|
|
||||||
此套件提供了一個 Python 客戶端,用於與 JumpServer PAM API 互動,以檢索各種資產的秘密。它簡化了發送請求和處理響應的過程。
|
## 1. 簡介
|
||||||
|
|
||||||
## 特性
|
本 API 提供了 PAM 查看資產賬號服務,支持 RESTful 風格的調用,返回數據採用 JSON 格式。
|
||||||
|
|
||||||
- 在發送請求之前驗證參數。
|
## 2. 環境要求
|
||||||
- 支持基於資產和帳戶的秘密檢索。
|
|
||||||
- 通過 HTTP 簽名輕鬆集成 JumpServer PAM API。
|
|
||||||
|
|
||||||
## 安裝
|
- `Python 3.11+`
|
||||||
|
- `requests==2.31.0`
|
||||||
|
- `httpsig==1.3.0`
|
||||||
|
|
||||||
您可以通過 pip 安裝此套件:
|
## 3. 使用方法
|
||||||
|
**請求方式**: `GET api/v1/accounts/integration-applications/account-secret/`
|
||||||
|
|
||||||
```bash
|
**請求參數**
|
||||||
pip install jms_pam-0.0.1-py3-none-any.whl
|
|
||||||
|
| 參數名 | 類型 | 必填 | 說明 |
|
||||||
|
|------------|------|----|--------------|
|
||||||
|
| asset | str | 是 | 資產 ID / 資產名稱 |
|
||||||
|
| account | str | 是 | 賬號 ID / 賬號名稱 |
|
||||||
|
|
||||||
|
**響應示例**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "72b0b0aa-ad82-4182-a631-ae4865e8ae0e",
|
||||||
|
"secret": "123456"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 需求
|
## 常見問題(FAQ)
|
||||||
|
|
||||||
- `Python 3.6+`
|
Q: API Key 如何獲取?
|
||||||
- `requests`
|
|
||||||
- `httpsig`
|
|
||||||
|
|
||||||
## 使用方法
|
A: 你可以在 PAM - 應用管理 創建應用生成 KEY_ID 和 KEY_SECRET。
|
||||||
|
|
||||||
### 初始化
|
## 版本歷史(Changelog)
|
||||||
|
|
||||||
要使用 JumpServer PAM 客戶端,通過提供所需的 `endpoint`、`key_id` 和 `key_secret` 創建一個實例。
|
|
||||||
|
|
||||||
```python
|
| 版本號 | 變更內容 | 日期 |
|
||||||
from jms_pam import JumpServerPAM, SecretRequest
|
| ----- | ----------------- |------------|
|
||||||
|
| 1.0.0 | 初始版本 | 2025-02-11 |
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 創建秘密請求
|
|
||||||
|
|
||||||
您可以通過指定資產或帳戶信息來創建一個秘密請求。
|
|
||||||
|
|
||||||
```python
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
```
|
|
||||||
|
|
||||||
### 發送請求
|
|
||||||
|
|
||||||
使用客戶端的 `send` 方法發送請求。
|
|
||||||
|
|
||||||
```python
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 處理響應
|
|
||||||
|
|
||||||
檢查秘密是否成功檢索,並相應地處理響應。
|
|
||||||
|
|
||||||
```python
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('秘密: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('獲取秘密失敗: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 完整示例
|
|
||||||
|
|
||||||
以下是如何使用該客戶端的完整示例:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from jumpserver_pam_client import JumpServerPAM, SecretRequest
|
|
||||||
|
|
||||||
client = JumpServerPAM(
|
|
||||||
endpoint='http://127.0.0.1',
|
|
||||||
key_id='your-key-id',
|
|
||||||
key_secret='your-key-secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
request = SecretRequest(asset='Linux', account='root')
|
|
||||||
secret_obj = client.send(request)
|
|
||||||
|
|
||||||
if secret_obj.valid:
|
|
||||||
print('秘密: %s' % secret_obj.secret)
|
|
||||||
else:
|
|
||||||
print('獲取秘密失敗: %s' % secret_obj.desc)
|
|
||||||
```
|
|
||||||
|
|
||||||
## 錯誤處理
|
|
||||||
|
|
||||||
如果提供的參數不符合驗證要求,該庫將引發 `RequestParamsError`。這包括對有效 UUID 的檢查和參數之間的相互依賴性檢查。
|
|
||||||
|
|
||||||
## 貢獻
|
|
||||||
|
|
||||||
歡迎貢獻!請打開一個問題或提交拉取請求,以進行任何增強或修復錯誤。
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
"AccountBackupDetail": "Backup account details",
|
"AccountBackupDetail": "Backup account details",
|
||||||
"AccountBackupList": "Backup account",
|
"AccountBackupList": "Backup account",
|
||||||
"AccountBackupUpdate": "Update account backup",
|
"AccountBackupUpdate": "Update account backup",
|
||||||
"AccountChangeSecret": "Change account secret",
|
|
||||||
"AccountChangeSecretDetail": "Change account secret details",
|
"AccountChangeSecretDetail": "Change account secret details",
|
||||||
"AccountDeleteConfirmMsg": "Delete account, continue?",
|
"AccountDeleteConfirmMsg": "Delete account, continue?",
|
||||||
"AccountDiscoverDetail": "Gather account details",
|
"AccountDiscoverDetail": "Gather account details",
|
||||||
|
@ -1401,7 +1400,7 @@
|
||||||
"WebUpdate": "Update the asset - web",
|
"WebUpdate": "Update the asset - web",
|
||||||
"Wednesday": "Wed",
|
"Wednesday": "Wed",
|
||||||
"Week": "Week",
|
"Week": "Week",
|
||||||
"WeekAdd": "Weekly add",
|
"WeekAdd": "New this week",
|
||||||
"WeekOrTime": "Day/time",
|
"WeekOrTime": "Day/time",
|
||||||
"WildcardsAllowed": "Allowed wildcards",
|
"WildcardsAllowed": "Allowed wildcards",
|
||||||
"WindowsPushHelpText": "Windows assets temporarily do not support key push",
|
"WindowsPushHelpText": "Windows assets temporarily do not support key push",
|
||||||
|
@ -1464,5 +1463,8 @@
|
||||||
"FailCount": "Failure Count",
|
"FailCount": "Failure Count",
|
||||||
"ChangeSecretFailAccounts": "Secret Change Failed Accounts",
|
"ChangeSecretFailAccounts": "Secret Change Failed Accounts",
|
||||||
"OngoingPwdChange": "Ongoing Secret Change",
|
"OngoingPwdChange": "Ongoing Secret Change",
|
||||||
"AccountResult": "Account Success/Failure"
|
"AccountResult": "Account Success/Failure",
|
||||||
|
"ResetSecret": "Reset secret",
|
||||||
|
"Connectable": "Connectable",
|
||||||
|
"AccountRecord": "Account record"
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@
|
||||||
"AccountBackupDetail": "账号备份详情",
|
"AccountBackupDetail": "账号备份详情",
|
||||||
"AccountBackupList": "账号备份列表",
|
"AccountBackupList": "账号备份列表",
|
||||||
"AccountBackupUpdate": "更新账号备份",
|
"AccountBackupUpdate": "更新账号备份",
|
||||||
"AccountChangeSecret": "账号改密",
|
|
||||||
"AccountChangeSecretDetail": "账号改密详情",
|
"AccountChangeSecretDetail": "账号改密详情",
|
||||||
"AccountDeleteConfirmMsg": "删除账号,是否继续?",
|
"AccountDeleteConfirmMsg": "删除账号,是否继续?",
|
||||||
"AccountDiscoverDetail": "账号发现详情",
|
"AccountDiscoverDetail": "账号发现详情",
|
||||||
|
@ -1469,5 +1468,13 @@
|
||||||
"FailCount": "失败数",
|
"FailCount": "失败数",
|
||||||
"ChangeSecretFailAccounts": "改密失败账号",
|
"ChangeSecretFailAccounts": "改密失败账号",
|
||||||
"OngoingPwdChange": "当前正在改密情况",
|
"OngoingPwdChange": "当前正在改密情况",
|
||||||
"AccountResult": "账号成功/失败情况"
|
"AccountResult": "账号成功/失败情况",
|
||||||
|
"ResetSecret": "可改密",
|
||||||
|
"Connectable": "可连接",
|
||||||
|
"AccountRecord": "账号记录",
|
||||||
|
"RiskDetection": "风险检测",
|
||||||
|
"DetectResults": "检测结果",
|
||||||
|
"DetectTasks": "检测任务",
|
||||||
|
"DetectEngines": "检测引擎",
|
||||||
|
"ChangeSecret": "账号改密"
|
||||||
}
|
}
|
Loading…
Reference in New Issue