jumpserver/apps/accounts/demos/python
fit2bot e05930109b
feat: PAM Service (#14552)
* feat: PAM Service

* perf: import package name

---------

Co-authored-by: jiangweidong <1053570670@qq.com>
2024-12-02 10:32:52 +08:00
..
jms_pam feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00
README.en.md feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00
README.ja.md feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00
README.zh-hans.md feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00
README.zh-hant.md feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00
setup.py feat: PAM Service (#14552) 2024-12-02 10:32:52 +08:00

README.en.md

JumpServer PAM Client

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.

Features

  • Validate parameters before sending requests.
  • Support for both asset and account-based secret retrieval.
  • Easy integration with JumpServer PAM API using HTTP signatures for authentication.

Installation

You can install the package via pip:

pip install jms_pam-0.0.1-py3-none-any.whl

Requirements

  • Python 3.6+
  • requests
  • httpsig

Usage

Initialization

To use the JumpServer PAM client, create an instance by providing the required endpoint, key_id, and key_secret.

from jms_pam import JumpServerPAM, SecretRequest

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.

request = SecretRequest(asset='Linux', account='root')

Sending the Request

Send the request using the send method of the client.

secret_obj = client.send(request)

Handling the Response

Check if the secret was retrieved successfully and handle the response accordingly.

if secret_obj.valid:
    print('Secret: %s' % secret_obj.secret)
else:
    print('Get secret failed: %s' % secret_obj.desc)

Complete Example

Heres a complete example of how to use the client:

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.