-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ayeshLK/dev
Add initial implementation for the AWS Marketplace Entitlement connector
- Loading branch information
Showing
13 changed files
with
753 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?; | ||
|}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?; | ||
|}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
native/src/main/java/io/ballerina/lib/aws/mpe/AwsMpeThreadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.