Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
23 changes: 9 additions & 14 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,6 @@ public type ProductVulnerabilitySearchResponse record {|
*entity:Pagination;
|};

# Basic product information.
public type BasicProductInfo record {|
# Product name
@constraint:String {minLength: 1}
string productName;
# Product base version
@constraint:String {minLength: 1}
string productBaseVersion;
# Channel
@constraint:String {minLength: 1}
string channel;
|};

# Recommended update level.
public type RecommendedUpdateLevel record {|
# Product name
Expand Down Expand Up @@ -550,7 +537,15 @@ public type UpdateResponse record {|

# Update payload for listing updates.
public type ListUpdatePayload record {|
*BasicProductInfo;
# Product name
@constraint:String {minLength: 1}
string productName;
# Product version
@constraint:String {minLength: 1}
string productVersion;
# Channel
@constraint:String {minLength: 1}
string channel;
# Starting update level
@constraint:String {minLength: 1}
string startUpdateLevel;
Expand Down
23 changes: 9 additions & 14 deletions apps/customer-portal/backend/modules/updates/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ type ClientCredentialsOauth2Config record {|
string[] scopes = [];
|};

# Basic product information.
public type BasicProductInfo record {|
# Product name
@constraint:String {minLength: 1}
string product\-name;
# Product base version
@constraint:String {minLength: 1}
string product\-base\-version;
# Channel
@constraint:String {minLength: 1}
string channel;
|};

# Recommended update level.
public type RecommendedUpdateLevel record {|
# Product name
Expand Down Expand Up @@ -154,7 +141,15 @@ public type UpdateResponse record {|

# Update payload for listing updates.
public type ListUpdatePayload record {|
*BasicProductInfo;
# Product name
@constraint:String {minLength: 1}
string product\-name;
# Product base version
@constraint:String {minLength: 1}
string product\-version;
# Channel
@constraint:String {minLength: 1}
string channel;
# Starting update level
@constraint:String {minLength: 1}
string start\-update\-level;
Expand Down
9 changes: 4 additions & 5 deletions apps/customer-portal/backend/modules/updates/updates.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public isolated function getRecommendedUpdateLevels(string email) returns Recomm
# + payload - Payload for listing updates
# + return - List of updates, or an error if the operation fails
public isolated function listUpdates(string idToken, ListUpdatePayload payload) returns UpdateResponse|error {
return updatesClient->/updates/list\-updates.post(payload, generateHeaders(idToken), readOnly = true);
return updatesClient->/updates/list\-updates.post(payload, readOnly = true);
}

# Get product update levels based on the provided parameters.
# Get product update levels.
#
# + idToken - ID token for authentication
# + return - List of product update levels, or an error if the operation fails
public isolated function getProductUpdateLevels(string idToken) returns ProductUpdateLevel[]|error {
return updatesClient->/updates/product\-update\-levels.get(generateHeaders(idToken));
public isolated function getProductUpdateLevels() returns ProductUpdateLevel[]|error {
return updatesClient->/updates/product\-update\-levels.get();
}
13 changes: 3 additions & 10 deletions apps/customer-portal/backend/modules/updates/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
// under the License.
import customer_portal.types;

# Generate authorization headers.
#
# + token - ID token for authorization
# + return - Map of headers with authorization
isolated function generateHeaders(string token) returns map<string|string[]> => {"x-jwt-assertion": token};

# Process recommended update levels for a user.
#
# + email - Email of the user
Expand Down Expand Up @@ -53,7 +47,7 @@ public isolated function processListUpdates(string idToken, types:ListUpdatePayl

ListUpdatePayload requestPayload = {
product\-name: payload.productName,
product\-base\-version: payload.productBaseVersion,
product\-version: payload.productVersion,
channel: payload.channel,
start\-update\-level: payload.startUpdateLevel,
end\-update\-level: payload.endUpdateLevel,
Expand Down Expand Up @@ -123,10 +117,9 @@ public isolated function processListUpdates(string idToken, types:ListUpdatePayl

# Process product update levels based on the provided parameters.
#
# + idToken - ID token for authentication
# + return - List of product update levels, or an error if the operation fails
public isolated function processProductUpdateLevels(string idToken) returns types:ProductUpdateLevel[]|error {
ProductUpdateLevel[] productUpdateLevels = check getProductUpdateLevels(idToken);
public isolated function processProductUpdateLevels() returns types:ProductUpdateLevel[]|error {
ProductUpdateLevel[] productUpdateLevels = check getProductUpdateLevels();
return from ProductUpdateLevel level in productUpdateLevels
select {
productName: level.product\-name,
Expand Down
2 changes: 1 addition & 1 deletion apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ service http:InterceptableService / on new http:Listener(9090) {
};
}

types:ProductUpdateLevel[]|error productUpdateLevels = updates:processProductUpdateLevels(userInfo.idToken);
types:ProductUpdateLevel[]|error productUpdateLevels = updates:processProductUpdateLevels();
if productUpdateLevels is error {
string customError = "Failed to get product update levels.";
log:printError(customError, productUpdateLevels);
Expand Down