Coder Social home page Coder Social logo

confluent-cloud-sdk's Introduction

Confluent Cloud SDK

SDK to interact with Confluent Cloud API

Installation

pip install confluent-cloud-sdk

Imports

To use Confluent Admin API SDK in a project

from confluent_cloud_sdk.client_factory import ConfluentClient
from confluent_cloud_sdk.confluent_iam_v2 import ApiKey
from confluent_cloud_sdk.confluent_iam_v2 import ServiceAccount

Initialize connection

client = ConfluentClient(
    "cloud_key_key",
    "cloud_key_secret",
)

Example with secret in AWS And list all assets

import json
from os import environ

from boto3.session import Session
from confluent_cloud_sdk.client_factory import ConfluentClient
from confluent_cloud_sdk.confluent_iam_v2 import ServiceAccount
from confluent_cloud_sdk.confluent_org_v2 import ConfluentEnvironment
from confluent_cloud_sdk.confluent_cluster_v2 import KafkaClusterV2

from compose_x_common.aws import get_session


def get_confluent_admin_secret(
    secret_arn: str,
    session: Session = None,
    key_id: str = "ApiKey",
    secret_id: str = "ApiSecret",
) -> ConfluentClient:
    session = get_session(session)
    client = session.client("secretsmanager")
    value = json.loads(client.get_secret_value(SecretId=secret_arn)["SecretString"])
    return ConfluentClient(value[key_id], value[secret_id])


cclient = get_confluent_admin_secret(environ.get("SECRET_ARN"))

envs = cclient.list_all(ConfluentEnvironment)

for env in envs:
    print(env.obj_id)
    clusters = cclient.list_all(KafkaClusterV2, url_args=f"?environment={env.obj_id}")
    for cluster in clusters:
        print(cluster.obj_id)

svc_accounts = cclient.list_all(ServiceAccount)
for svc_account in svc_accounts:
    print(svc_account.obj_id)
    svc_account.import_api_keys()
    print([key.obj_id for key in svc_account.api_keys.values()])

Usage examples

For more details, see docs/usage.rst

confluent-cloud-sdk's People

Contributors

johnpreston avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.