From 9a1908ff25979de004c048bd3bb27926c699f77a Mon Sep 17 00:00:00 2001 From: Allen Sanborn Date: Sun, 1 Nov 2026 19:24:39 -0600 Subject: [PATCH] fix(rds): report LicenseModel on DB instances (#7232) * fix(rds): report LicenseModel on DB instances DescribeDBInstances and the Create/Modify responses now carry LicenseModel. CreateDBInstance and ModifyDBInstance store a requested LicenseModel; when none was given the engine default is reported (postgresql-license for postgres, general-public-license for mysql/mariadb, license-included for sqlserver). * test(rds): reuse RdsRequests helpers in license model test --- .../floci/services/rds/RdsQueryHandler.java | 6 +- .../floci/services/rds/model/DbInstance.java | 4 ++ .../rds/model/DbInstanceSettings.java | 28 +++++++-- .../rds/RdsLicenseModelIntegrationTest.java | 59 +++++++++++++++++++ 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/rds/RdsLicenseModelIntegrationTest.java diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 307d122df3..0b66439f39 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -871,7 +871,8 @@ public class RdsQueryHandler { includeEncryption ? null : cloudwatchLogsExportChanges(params), optionalInt(params.getFirst("MaxAllocatedStorage")), params.getFirst("StorageType"), - params.getFirst("CACertificateIdentifier")); + params.getFirst("CACertificateIdentifier"), + params.getFirst("LicenseModel")); } /** @@ -1049,7 +1050,7 @@ public class RdsQueryHandler { if (engine != null && engine.regionMatches(true, 0, "sqlserver", 0, 9)) { return "license-included"; } - if (engine != null && engine.equalsIgnoreCase("aurora-mysql")) { + if (engine != null && (engine.toLowerCase().contains("mysql") || engine.equalsIgnoreCase("mariadb"))) { return "general-public-license"; } return "postgresql-license"; @@ -3219,6 +3220,7 @@ public class RdsQueryHandler { .elem("DBInstanceStatus", statusStr) .elem("Engine", engineStr.toLowerCase()) .elem("EngineVersion", i.getEngineVersion()) + .elem("LicenseModel", i.getLicenseModel() != null ? i.getLicenseModel() : licenseModel(engineStr)) .elem("MasterUsername", i.getMasterUsername()); if (i.getDbName() != null && !i.getDbName().isBlank()) { xml.elem("DBName", i.getDbName()); diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java index 49778b0606..a7245d774b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java @@ -28,6 +28,8 @@ public class DbInstance { private String storageType; /** The RDS certificate authority for the instance; null on one stored before it was recorded. */ private String caCertificateIdentifier; + /** The license model the request named; null means the engine's default. */ + private String licenseModel; private DbInstanceStatus status; private DbEndpoint endpoint; private boolean iamDatabaseAuthenticationEnabled; @@ -141,6 +143,8 @@ public class DbInstance { public String getStorageType() { return storageType != null ? storageType : DEFAULT_STORAGE_TYPE; } public void setStorageType(String storageType) { this.storageType = storageType; } + public String getLicenseModel() { return licenseModel; } + public void setLicenseModel(String licenseModel) { this.licenseModel = licenseModel; } public String getCaCertificateIdentifier() { return caCertificateIdentifier; } public void setCaCertificateIdentifier(String caCertificateIdentifier) { this.caCertificateIdentifier = caCertificateIdentifier; diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java index 67be8b29cc..fab161a78f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java @@ -28,7 +28,22 @@ public record DbInstanceSettings(Boolean storageEncrypted, LogExportChanges logExportChanges, Integer maxAllocatedStorage, String storageType, - String caCertificateIdentifier) { + String caCertificateIdentifier, + String licenseModel) { + public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod, + String preferredBackupWindow, String preferredMaintenanceWindow, + Boolean copyTagsToSnapshot, Integer monitoringInterval, String monitoringRoleArn, + Boolean performanceInsightsEnabled, Integer performanceInsightsRetentionPeriod, + String engineLifecycleSupport, List enabledCloudwatchLogsExports, + LogExportChanges logExportChanges, Integer maxAllocatedStorage, String storageType, + String caCertificateIdentifier) { + this(storageEncrypted, kmsKeyId, backupRetentionPeriod, preferredBackupWindow, + preferredMaintenanceWindow, copyTagsToSnapshot, monitoringInterval, monitoringRoleArn, + performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport, + enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType, + caCertificateIdentifier, null); + } + public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod, String preferredBackupWindow, String preferredMaintenanceWindow, Boolean copyTagsToSnapshot, Integer monitoringInterval, String monitoringRoleArn, @@ -201,7 +216,7 @@ public record DbInstanceSettings(Boolean storageEncrypted, monitoringInterval, monitoringRoleArn, performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport, enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType, - caCertificateIdentifier); + caCertificateIdentifier, licenseModel); } public DbInstanceSettings withKmsKeyId(String resolvedKmsKeyId) { @@ -210,7 +225,7 @@ public record DbInstanceSettings(Boolean storageEncrypted, monitoringInterval, monitoringRoleArn, performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport, enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType, - caCertificateIdentifier); + caCertificateIdentifier, licenseModel); } public DbInstanceSettings withStorageType(String resolvedStorageType) { @@ -219,7 +234,7 @@ public record DbInstanceSettings(Boolean storageEncrypted, monitoringInterval, monitoringRoleArn, performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport, enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, resolvedStorageType, - caCertificateIdentifier); + caCertificateIdentifier, licenseModel); } /** The same settings with the CA certificate the service resolved. */ @@ -229,7 +244,7 @@ public record DbInstanceSettings(Boolean storageEncrypted, monitoringInterval, monitoringRoleArn, performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport, enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType, - resolvedCaCertificateIdentifier); + resolvedCaCertificateIdentifier, licenseModel); } public void validateStorageType() { @@ -290,5 +305,8 @@ public record DbInstanceSettings(Boolean storageEncrypted, if (caCertificateIdentifier != null && !caCertificateIdentifier.isBlank()) { instance.setCaCertificateIdentifier(caCertificateIdentifier); } + if (licenseModel != null && !licenseModel.isBlank()) { + instance.setLicenseModel(licenseModel); + } } } diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsLicenseModelIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsLicenseModelIntegrationTest.java new file mode 100644 index 0000000000..c82c334c1b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsLicenseModelIntegrationTest.java @@ -0,0 +1,59 @@ +package io.github.hectorvent.floci.services.rds; + +import io.github.hectorvent.floci.testing.RdsMockProfile; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import org.junit.jupiter.api.Test; + +import static io.github.hectorvent.floci.testing.RdsRequests.deleteInstance; +import static io.github.hectorvent.floci.testing.RdsRequests.rds; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@QuarkusTest +@TestProfile(RdsMockProfile.class) +class RdsLicenseModelIntegrationTest { + + private static RequestSpecification create(String id, String engine) { + return rds("CreateDBInstance").formParam("DBInstanceIdentifier", id) + .formParam("Engine", engine).formParam("DBInstanceClass", "db.t3.micro") + .formParam("MasterUsername", "admin").formParam("MasterUserPassword", "password123") + .formParam("AllocatedStorage", "20"); + } + + private static String described(String id) { + Response read = rds("DescribeDBInstances").formParam("DBInstanceIdentifier", id).post("/"); + assertEquals(200, read.statusCode(), read.asString()); + return read.xmlPath().getString( + "DescribeDBInstancesResponse.DescribeDBInstancesResult.DBInstances.DBInstance.LicenseModel"); + } + + @Test + void omittedLicenseModelReportsTheEngineDefault() { + try { + create("license-default-pg", "postgres").post("/").then().statusCode(200); + create("license-default-mysql", "mysql").post("/").then().statusCode(200); + assertEquals("postgresql-license", described("license-default-pg")); + assertEquals("general-public-license", described("license-default-mysql")); + } finally { + deleteInstance("license-default-pg"); + deleteInstance("license-default-mysql"); + } + } + + @Test + void requestedLicenseModelIsRetainedOnCreateAndModify() { + String id = "license-requested"; + try { + create(id, "postgres").formParam("LicenseModel", "bring-your-own-license") + .post("/").then().statusCode(200); + assertEquals("bring-your-own-license", described(id)); + rds("ModifyDBInstance").formParam("DBInstanceIdentifier", id) + .formParam("LicenseModel", "postgresql-license").post("/").then().statusCode(200); + assertEquals("postgresql-license", described(id)); + } finally { + deleteInstance(id); + } + } +}