Skip to content

Commit

Permalink
Merge pull request #2 from ayeshLK/dev
Browse files Browse the repository at this point in the history
Add initial implementation for the AWS Marketplace Entitlement connector
  • Loading branch information
ayeshLK authored Aug 21, 2024
2 parents 5b9a8fa + e752f6e commit aa0ab3a
Show file tree
Hide file tree
Showing 13 changed files with 753 additions and 6 deletions.
26 changes: 25 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
dependencies-toml-version = "2"
distribution-version = "2201.9.2"

[[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 = "jballerina.java"
Expand All @@ -15,12 +26,25 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

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

[[package]]
org = "ballerinax"
name = "aws.marketplace.mpe"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerinax", packageName = "aws.marketplace.mpe", moduleName = "aws.marketplace.mpe"}
Expand Down
5 changes: 0 additions & 5 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ task commitTomlFiles {
}
}

clean {
delete 'build'
delete 'lib'
}

build.dependsOn copyToLib
build.dependsOn ":${packageName}-native:build"

Expand Down
75 changes: 75 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2024 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 Marketplace entitlement client.
public isolated client class Client {

# Initialize the Ballerina AWS MPE client.
# ```ballerina
# mpe:Client mpe = check new(region = mpe:US_EAST_1, auth = {
# accessKeyId: "<aws-access-key>",
# secretAccessKey: "<aws-secret-key>"
# });
# ```
#
# + configs - The AWS MPE client configurations
# + return - The `mpe:Client` or an `mpe: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.mpe.NativeClientAdaptor"
} external;

# Retrieves the entitlement values for a given product.
# ```ballerina
# mpe:EntitlementsResponse response = check mpe->getEntitlements(productCode = "<aws-product-code>");
# ```
#
# + request - The `mpe:GetEntitlements` request with relevant details
# + return - An `mpe:EntitlementsResponse` containing the entitlement details,
# or an `mpe:Error` if the request validation or the operation failed.
remote function getEntitlements(*EntitlementsRequest request) returns EntitlementsResponse|Error {
EntitlementsRequest|constraint:Error validated = constraint:validate(request);
if validated is constraint:Error {
return error Error(string `Request validation failed: ${validated.message()}`);
}
return self.externGetEntitlements(validated);
}

isolated function externGetEntitlements(EntitlementsRequest request) returns EntitlementsResponse|Error =
@java:Method {
name: "getEntitlements",
'class: "io.ballerina.lib.aws.mpe.NativeClientAdaptor"
} external;

# Closes the AWS MPE client resources.
# ```ballerina
# check mpe->close();
# ```
#
# + return - A `mpe:Error` if there is an error while closing the client resources or else nil.
remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.aws.mpe.NativeClientAdaptor"
} external;
}
30 changes: 30 additions & 0 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024 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.

# Represents a AWS Marketplace Entitlement distinct error.
public type Error distinct error<ErrorDetails>;

# The error details type for the AWS MPE module.
public type ErrorDetails record {|
# The HTTP status code for the error
int httpStatusCode?;
# The HTTP status text returned from the service
string httpStatusText?;
# The error code associated with the response
string errorCode?;
# The human-readable error message provided by the service
string errorMessage?;
|};
139 changes: 139 additions & 0 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) 2024 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/time;

# Represents the Client configurations for AWS Marketplace Entitlement service.
public type ConnectionConfig record {|
# The AWS region with which the connector should communicate
Region region;
# The authentication configurations for the AWS Marketplace Entitlement service
AuthConfig auth;
|};

# An Amazon Web Services region that hosts a set of Amazon services.
public enum Region {
AF_SOUTH_1 = "af-south-1",
AP_EAST_1 = "ap-east-1",
AP_NORTHEAST_1 = "ap-northeast-1",
AP_NORTHEAST_2 = "ap-northeast-2",
AP_NORTHEAST_3 = "ap-northeast-3",
AP_SOUTH_1 = "ap-south-1",
AP_SOUTH_2 = "ap-south-2",
AP_SOUTHEAST_1 = "ap-southeast-1",
AP_SOUTHEAST_2 = "ap-southeast-2",
AP_SOUTHEAST_3 = "ap-southeast-3",
AP_SOUTHEAST_4 = "ap-southeast-4",
AWS_CN_GLOBAL = "aws-cn-global",
AWS_GLOBAL = "aws-global",
AWS_ISO_GLOBAL = "aws-iso-global",
AWS_ISO_B_GLOBAL = "aws-iso-b-global",
AWS_US_GOV_GLOBAL = "aws-us-gov-global",
CA_WEST_1 = "ca-west-1",
CA_CENTRAL_1 = "ca-central-1",
CN_NORTH_1 = "cn-north-1",
CN_NORTHWEST_1 = "cn-northwest-1",
EU_CENTRAL_1 = "eu-central-1",
EU_CENTRAL_2 = "eu-central-2",
EU_ISOE_WEST_1 = "eu-isoe-west-1",
EU_NORTH_1 = "eu-north-1",
EU_SOUTH_1 = "eu-south-1",
EU_SOUTH_2 = "eu-south-2",
EU_WEST_1 = "eu-west-1",
EU_WEST_2 = "eu-west-2",
EU_WEST_3 = "eu-west-3",
IL_CENTRAL_1 = "il-central-1",
ME_CENTRAL_1 = "me-central-1",
ME_SOUTH_1 = "me-south-1",
SA_EAST_1 = "sa-east-1",
US_EAST_1 = "us-east-1",
US_EAST_2 = "us-east-2",
US_GOV_EAST_1 = "us-gov-east-1",
US_GOV_WEST_1 = "us-gov-west-1",
US_ISOB_EAST_1 = "us-isob-east-1",
US_ISO_EAST_1 = "us-iso-east-1",
US_ISO_WEST_1 = "us-iso-west-1",
US_WEST_1 = "us-west-1",
US_WEST_2 = "us-west-2"
}

# Represents the Authentication configurations for AWS Marketplace Entitlement service.
public type AuthConfig record {|
# The AWS access key, used to identify the user interacting with AWS
string accessKeyId;
# The AWS secret access key, used to authenticate the user interacting with AWS
string secretAccessKey;
# The AWS session token, retrieved from an AWS token service, used for authenticating
# a user with temporary permission to a resource
string sessionToken?;
|};

# Represents the parameters used for the `GetEntitlements` operation.
public type EntitlementsRequest record {|
# Product code is used to uniquely identify a product in AWS Marketplace
@constraint:String {
minLength: 1,
maxLength: 255
}
string productCode;
# A parameter which is used to filter out entitlements for a specific customer or a specific dimension
EntitlementFilter filter?;
# The maximum number of results to return in a single call
int maxResults?;
# The token for pagination to retrieve the next set of results
@constraint:String {
pattern: re `\S+`
}
string nextToken?;
|};

# Represents the filters used for `GetEntitlements` operation.
public type EntitlementFilter record {|
# Customer identifier based filter
@constraint:Array {
minLength: 1
}
string[] customerIdentifier?;
# Product dimension based filter
@constraint:Array {
minLength: 1
}
string[] dimension?;
|};

# Represents the results retrieved from `GetEntitlements` operation.
public type EntitlementsResponse record {|
# The set of entitlements found through the GetEntitlements operation.
# If the result contains an empty set of entitlements, NextToken might still be present and should be used.
Entitlement[] entitlements;
# The token for pagination to retrieve the next set of results
string nextToken?;
|};

# Represents the capacity in a product owned by the customer.
public type Entitlement record {|
# The product code for which the given entitlement applies
string productCode?;
# The dimension for which the given entitlement applies
string dimension?;
# The customer identifier is a handle to each unique customer in an application
string customerIdentifier?;
# The expiration date represents the minimum date through which this entitlement is expected to remain valid
time:Utc expirationDate?;
# The amount of capacity that the customer is entitled to for the product
boolean|float|int|string value?;
|};
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ testngVersion=7.6.1
eclipseLsp4jVersion=0.12.0
ballerinaGradlePluginVersion=2.2.4
ballerinaLangVersion=2201.9.2

stdlibTimeVersion=2.4.0
awsMpEntitlementSdkVersion=2.27.6
4 changes: 4 additions & 0 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ dependencies {
implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}"
implementation group: 'io.ballerina.stdlib', name: 'time-native', version: "${stdlibTimeVersion}"
implementation group: 'software.amazon.awssdk', name: 'marketplaceentitlement', version: "${awsMpEntitlementSdkVersion}"

dist group: 'software.amazon.awssdk', name: 'marketplaceentitlement', version: "${awsMpEntitlementSdkVersion}"
}

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, 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.
*/

package io.ballerina.lib.aws.mpe;

import java.util.concurrent.ThreadFactory;

/**
* A {@link ThreadFactory} object that creates new threads on demand for AWS MPE client network actions.
*/
public class AwsMpeThreadFactory implements ThreadFactory {

@Override
public Thread newThread(Runnable runnable) {
Thread networkThread = new Thread(runnable);
networkThread.setName("balx-awsmpe-client-network-thread");
return networkThread;
}
}
Loading

0 comments on commit aa0ab3a

Please sign in to comment.