ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
137 stars 58 forks source link

Introduce a Ballerina connector for AWS Marketplace Metering service #6865

Closed ayeshLK closed 1 month ago

ayeshLK commented 1 month ago

Description:

$subject

Following APIs should be supported:

Related to: #740

[1] - https://docs.aws.amazon.com/marketplacemetering/latest/APIReference/API_ResolveCustomer.html [2] - https://docs.aws.amazon.com/marketplacemetering/latest/APIReference/API_BatchMeterUsage.html

ayeshLK commented 1 month ago

Initial design for the AWS Marketplace Metering connector

1. Configurations

ConnectionConfig

public type ConnectionConfig record {|
    Region region;
    AuthConfig auth;
|};

Region

public enum Region {
    US_EAST_1 = "us-east-1"
    // other regions
}

AuthConfig

public type AuthConfig record {|
    string accessKeyId;
    string secretAccessKey;
    string sessionToken?;
|};

2. Client API

public type Client distinct client object {

    remote function resolveCustomer(string registrationToken) returns ResolveCustomerResponse|Error;

    remote function batchMeterUsage(*BatchMeterUsageRequest request) returns BatchMeterUsageResponse|Error;
};

3. Types related resolve-customer API

public type ResolveCustomerResponse record {|
    string customerAWSAccountId;
    string customerIdentifier;
    string productCode;
|};

4. Types related to batch-meter-usage API

public type BatchMeterUsageRequest record {|
    @constraint:String {
        pattern: re `^[-a-zA-Z0-9/=:_.@]{1,255}$`
    }
    string productCode;
    @constraint:Array {
        maxLength: 25
    }
    UsageRecord[] usageRecords = [];
|};

public type UsageRecord record {|
    @constraint:String {
        pattern: re `[\s\S]{1,255}$`
    }
    string customerIdentifier;
    @constraint:String {
        pattern: re `[\s\S]{1,255}$`
    }
    string dimension;
    time:Utc timestamp;
    @constraint:Int {
        minValue: 0,
        maxValue: 2147483647
    }
    int quantity?;
    @constraint:Array {
        minLength: 1,
        maxLength: 2500
    }
    UsageAllocation[] usageAllocations?;
|};

public type UsageAllocation record {|
    @constraint:Int {
        minValue: 0,
        maxValue: 2147483647
    }
    int allocatedUsageQuantity;
    @constraint:Array {
        minLength: 1,
        maxLength: 5
    }
    Tag[] tags;
|};

public type Tag record {|
    string 'key;
    string value;
|};

public type BatchMeterUsageResponse record {|
    UsageRecordResult[] results;
    UsageRecord[] unprocessedRecords;
|};

public type UsageRecordResult record {|
    string meteringRecordId?;
    UsageRecordStatus status?;
    UsageRecord usageRecord?;
|};

public enum UsageRecordStatus {
    SUCCESS = "Success",
    CUSTOMER_NOT_SUBSCRIBED = "CustomerNotSubscribed",
    DUPLICATE_RECORD = "DuplicateRecord"
}

5. Errors

public type Error distinct error;
ayeshLK commented 1 month ago

Completed this with the following PRs. Hence, closing.