Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial implementation for the AWS Marketplace Entitlement connector #2

Merged
merged 34 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
968b0e1
AWS MPE sdk to the project
ayeshLK Aug 16, 2024
604a267
Updte trive and graalvm workflows to use workflow templates
ayeshLK Aug 16, 2024
a99be06
Update WSO2 licensing header
ayeshLK Aug 16, 2024
6b251ce
Add ballerina files for types, clients, and errors
ayeshLK Aug 16, 2024
9563159
Add the distinct error type for AWS MPE connector
ayeshLK Aug 16, 2024
69572bb
Add the basic types for AWS MPE connector
ayeshLK Aug 16, 2024
1c7e0c1
Add basic structure for the interop calls
ayeshLK Aug 16, 2024
2d6c561
Merge branch 'master' into dev
ayeshLK Aug 16, 2024
c61d089
Fix compilation failures
ayeshLK Aug 16, 2024
d3b52a2
[Automated] Update the toml files
ayeshLK Aug 16, 2024
b713d14
Fix interop function build failure
ayeshLK Aug 16, 2024
a3e53fa
Update package comments
ayeshLK Aug 16, 2024
1941fb5
Add functionality to initialize the entitlement-client
ayeshLK Aug 16, 2024
2d4c366
Merge branch 'master' into dev
ayeshLK Aug 18, 2024
fe8f138
Fix checkstyle build failure
ayeshLK Aug 18, 2024
8a4a2fb
Restructure connection config retrieval logic
ayeshLK Aug 18, 2024
8e14575
Update AWS MPE ballerina API with the implementation details
ayeshLK Aug 19, 2024
c3b7f01
Update constraints for the ballerian record
ayeshLK Aug 19, 2024
ac9456a
Implement the get-entitlements functionality at the native level
ayeshLK Aug 19, 2024
129639f
Add support to convert Java Instant to Ballerina Utc
ayeshLK Aug 19, 2024
7730142
[Automated] Update the toml files
ayeshLK Aug 19, 2024
382d60c
Fix checkstyle violation
ayeshLK Aug 19, 2024
86e9e6e
Fix formatting issues
ayeshLK Aug 19, 2024
9520e48
Remove unwanted gradle build file
ayeshLK Aug 19, 2024
8215340
Add missing doc comments
ayeshLK Aug 19, 2024
35531a1
Merge remote-tracking branch 'upstream/main' into dev
ayeshLK Aug 20, 2024
9c7a092
Use Ballerina time-native package to resolve UTC timestamps
ayeshLK Aug 20, 2024
94b75ef
Fix invalid type mapping
ayeshLK Aug 20, 2024
451ed12
Remove unwanted build configurations
ayeshLK Aug 20, 2024
4432d1a
Fix API doc
ayeshLK Aug 20, 2024
98819dc
Update ballerina/types.bal
NipunaRanasinghe Aug 20, 2024
b1d5fb8
Fix doc comment issues
ayeshLK Aug 20, 2024
a1ab715
Merge branch 'dev' of github.com:ayeshLK/module-ballerinax-aws.market…
ayeshLK Aug 20, 2024
e752f6e
Refactor the java interop class name
ayeshLK Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
69 changes: 69 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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;
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
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.AwsMpeClient"
} 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.AwsMpeClient"
} external;

remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.aws.mpe.AwsMpeClient"
} external;
}
31 changes: 31 additions & 0 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 error<ErrorDetails>;
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved

# The error details type for the AWS MPE module.
#
# + httpStatusCode - The HTTP status code for the error
# + httpStatusText - The HTTP status text returned from the service
# + errorCode - The error code associated with the response
# + errorMessage - The human-readable error message provided by the service
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
public type ErrorDetails record {|
int httpStatusCode?;
string httpStatusText?;
string errorCode?;
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 The AWS secret access key, used to authenticate the user interacting with AWS
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
string secretAccessKey;
# The AWS session token, retrieved from an AWS token service, used for authenticating that
# this user has received temporary permission to access some resource
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
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
NipunaRanasinghe marked this conversation as resolved.
Show resolved Hide resolved
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|decimal|int|string value?;
|};
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ testngVersion=7.6.1
eclipseLsp4jVersion=0.12.0
ballerinaGradlePluginVersion=2.2.4
ballerinaLangVersion=2201.9.2

awsMpEntitlementSdkVersion=2.27.6
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml

This file was deleted.

3 changes: 3 additions & 0 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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: 'software.amazon.awssdk', name: 'marketplaceentitlement', version: "${awsMpEntitlementSdkVersion}"

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

tasks.withType(JavaCompile) {
Expand Down
Loading