Skip to content

Commit

Permalink
Merge pull request #2 from ayeshLK/dev
Browse files Browse the repository at this point in the history
Add the package implementation
  • Loading branch information
ayeshLK authored Jan 4, 2025
2 parents 6b8aa68 + d4c3fd1 commit 003464d
Show file tree
Hide file tree
Showing 19 changed files with 1,801 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ secretmanager:Client secretmanager = check new(region = secretmanager:US_EAST_1,

### Step 3: Invoke the connector operation

// todo: complete this
Now, utilize the available connector operations.

```ballerina
secretmanager:DescribeSecretResponse response = check secretManager->describeSecret("<secret-id>");
```

### Step 4: Run the Ballerina application

Expand Down
109 changes: 108 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
dependencies-toml-version = "2"
distribution-version = "2201.10.0"

[[package]]
org = "ballerina"
name = "constraint"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "constraint", moduleName = "constraint"}
]

[[package]]
org = "ballerina"
name = "io"
version = "1.6.3"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]

[[package]]
org = "ballerina"
name = "jballerina.java"
Expand All @@ -15,12 +36,98 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.8.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "os", moduleName = "os"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerina"
name = "time"
version = "2.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "time", moduleName = "time"}
]

[[package]]
org = "ballerinax"
name = "aws.secretmanager"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerinax", packageName = "aws.secretmanager", moduleName = "aws.secretmanager"}
Expand Down
52 changes: 52 additions & 0 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Overview

[AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) is a service that helps you protect sensitive information, such as database credentials, API keys, and other secrets, by securely storing and managing access to them.

The `ballerinax/aws.secretmanager` package provides APIs to interact with AWS Secrets Manager, enabling developers to programmatically manage secrets, including creating, retrieving, updating, and deleting secrets in their applications.

## Setup guide
Before using this connector in your Ballerina application, complete the following:
1. Create an [AWS account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=default&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start)
2. [Obtain tokens](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)

## Quickstart

To use the `aws.secretmanager` connector in your Ballerina project, modify the `.bal` file as follows:

### Step 1: Import the module

Import the `ballerinax/aws.secretmanager` module into your Ballerina project.

```ballerina
import ballerinax/aws.secretmanager;
```

### Step 2: Instantiate a new connector

Create a new `secretmanager:Client` by providing the access key ID, secret access key, and the region.

```ballerina
configurable string accessKeyId = ?;
configurable string secretAccessKey = ?;
secretmanager:Client secretmanager = check new(region = secretmanager:US_EAST_1, auth = {
accessKeyId,
secretAccessKey
});
```

### Step 3: Invoke the connector operation

Now, utilize the available connector operations.

```ballerina
secretmanager:DescribeSecretResponse response = check secretManager->describeSecret("<secret-id>");
```

### Step 4: Run the Ballerina application

Use the following command to compile and run the Ballerina program.

```bash
bal run
```
52 changes: 52 additions & 0 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Overview

[AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) is a service that helps you protect sensitive information, such as database credentials, API keys, and other secrets, by securely storing and managing access to them.

The `ballerinax/aws.secretmanager` package provides APIs to interact with AWS Secrets Manager, enabling developers to programmatically manage secrets, including creating, retrieving, updating, and deleting secrets in their applications.

## Setup guide
Before using this connector in your Ballerina application, complete the following:
1. Create an [AWS account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=default&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start)
2. [Obtain tokens](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)

## Quickstart

To use the `aws.secretmanager` connector in your Ballerina project, modify the `.bal` file as follows:

### Step 1: Import the module

Import the `ballerinax/aws.secretmanager` module into your Ballerina project.

```ballerina
import ballerinax/aws.secretmanager;
```

### Step 2: Instantiate a new connector

Create a new `secretmanager:Client` by providing the access key ID, secret access key, and the region.

```ballerina
configurable string accessKeyId = ?;
configurable string secretAccessKey = ?;
secretmanager:Client secretmanager = check new(region = secretmanager:US_EAST_1, auth = {
accessKeyId,
secretAccessKey
});
```

### Step 3: Invoke the connector operation

Now, utilize the available connector operations.

```ballerina
secretmanager:DescribeSecretResponse response = check secretManager->describeSecret("<secret-id>");
```

### Step 4: Run the Ballerina application

Use the following command to compile and run the Ballerina program.

```bash
bal run
```
132 changes: 132 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) 2025 WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/constraint;
import ballerina/jballerina.java;

# AWS Secret Manager client.
public isolated client class Client {

# Initialize the Ballerina AWS Secret Manager client.
# ```ballerina
# secretmanager:Client secretmanager = check new(region = secretmanager:US_EAST_1, auth = {
# accessKeyId: "<aws-access-key>",
# secretAccessKey: "<aws-secret-key>"
# });
# ```
#
# + configs - The AWS Secret Manager client configurations
# + return - The `secretmanager:Client` or a `secretmanager:Error` if the initialization failed
public isolated function init(*ConnectionConfig configs) returns Error? {
return self.externInit(configs);
}

isolated function externInit(ConnectionConfig configs) returns Error? =
@java:Method {
name: "init",
'class: "io.ballerina.lib.aws.secretmanager.NativeClientAdaptor"
} external;

# Retrieves the details of a secret. It does not include the encrypted secret value.
# Secrets Manager only returns fields that have a value in the response.
# ```ballerina
# secretmanager:DescribeSecretResponse response = check secretmanager->describeSecret("<aws-secret-id>");
# ```
#
# + secretId - The ARN or name of the secret
# + return - An `secretmanager:DescribeSecretResponse` containing the details of the secret,
# or an `secretmanager:Error` if the request validation or the operation failed
isolated remote function describeSecret(SecretId secretId) returns DescribeSecretResponse|Error {
SecretId|constraint:Error validated = constraint:validate(secretId);
if validated is constraint:Error {
return error Error(string `Request validation failed: ${validated.message()}`);
}
return self.externDescribeSecret(validated);
}

isolated function externDescribeSecret(SecretId secretId) returns DescribeSecretResponse|Error =
@java:Method {
name: "describeSecret",
'class: "io.ballerina.lib.aws.secretmanager.NativeClientAdaptor"
} external;

# Retrieves the contents of the encrypted fields from the specified version of a secret.
# ```ballerina
# secretmanager:SecretValue secret = check secretmanager->getSecretValue("<aws-secret-id>");
# ```
#
# + secretId - The ARN or name of the secret
# + versionSelector - Details for selecting a specific version of the secret
# + return - An `secretmanager:SecretValue` containing the content of the secret, or an
# `secretmanager:Error` if the request validation or the operation failed
isolated remote function getSecretValue(SecretId secretId, *SecretVersionSelector versionSelector) returns SecretValue|Error {
SecretId|constraint:Error validatedSecretId = constraint:validate(secretId);
if validatedSecretId is constraint:Error {
return error Error(string `Request validation failed: ${validatedSecretId.message()}`);
}
SecretVersionSelector|constraint:Error validatedVersionSelector = constraint:validate(versionSelector);
if validatedVersionSelector is constraint:Error {
return error Error(string `Request validation failed: ${validatedVersionSelector.message()}`);
}
return self.externGetSecretValue(validatedSecretId, validatedVersionSelector);
}

isolated function externGetSecretValue(SecretId secretId, SecretVersionSelector versionSelector) returns SecretValue|Error =
@java:Method {
name: "getSecretValue",
'class: "io.ballerina.lib.aws.secretmanager.NativeClientAdaptor"
} external;

# Retrieves the contents of the encrypted fields for up to 20 secrets.
# ```ballerina
# secretmanager:BatchGetSecretValueResponse secret = check secretmanager->batchGetSecretValue(
# secretIds = ["<aws-secret-id>"]);
# ```
#
# + request - The filters or secret IDs used to identify the secrets to retrieve
# + return - An `secretmanager:BatchGetSecretValueResponse` containing the contents of the secrets, or an
# `secretmanager:Error` if the request validation or the operation failed
isolated remote function batchGetSecretValue(*BatchGetSecretValueRequest request) returns BatchGetSecretValueResponse|Error {
BatchGetSecretValueRequest|constraint:Error validated = constraint:validate(request);
if validated is constraint:Error {
return error Error(string `Request validation failed: ${validated.message()}`);
}
if request.filters is () && request.secretIds is () {
return error Error("Either `filters` or `secretIds` must be provided in the request");
}
if request.secretIds is SecretId[] && request.filters is SecretValueFilter[] {
return error Error("The request cannot contain both `filters` and `secretIds` simultaneously");
}
return self.externBatchGetSecretValue(validated);
}

isolated function externBatchGetSecretValue(BatchGetSecretValueRequest request) returns BatchGetSecretValueResponse|Error =
@java:Method {
name: "batchGetSecretValue",
'class: "io.ballerina.lib.aws.secretmanager.NativeClientAdaptor"
} external;

# Closes the AWS Secret Manager client resources.
# ```ballerina
# check secretmanager->close();
# ```
#
# + return - A `secretmanager:Error` if there is an error while closing the client resources or else nil
isolated remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.aws.secretmanager.NativeClientAdaptor"
} external;
}
Loading

0 comments on commit 003464d

Please sign in to comment.