Skip to content

Commit db71dbb

Browse files
fix: Add Did Document Self Service De Registration Config (#2519)
* fix: Add Did Document Self Service De Registration Config * fix: Cast replica count as int * fix: add quote to TX_EDC_DID_SERVICE_SELF_DEREGISTRATION_ENABLED var * fix: Trigger PR Build via empty commit
1 parent 8f5489f commit db71dbb

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

charts/tractusx-connector-memory/templates/deployment-runtime.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ spec:
258258
{{- end }}
259259
- name: "TX_EDC_DID_SERVICE_SELF_REGISTRATION_ENABLED"
260260
value: {{ .Values.iatp.didService.selfRegistration.enabled | quote}}
261-
{{- if .Values.iatp.didService.selfRegistration.enabled }}
261+
- name: "TX_EDC_DID_SERVICE_SELF_DEREGISTRATION_ENABLED"
262+
value: "false"
262263
- name: "TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID"
263-
value: {{ .Values.iatp.didService.selfRegistration.id | required ".Values.iatp.didService.selfRegistration.id is required" | quote }}
264-
{{- end }}
264+
value: {{ .Values.iatp.didService.selfRegistration.id | quote }}
265265
- name: "TX_EDC_DCP_CACHE_ENABLED"
266266
value: {{ .Values.iatp.cache.enabled | quote }}
267267
- name: "TX_EDC_DCP_CACHE_VALIDITY_SECONDS"

charts/tractusx-connector/templates/deployment-controlplane.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ spec:
256256
{{- end }}
257257
- name: "TX_EDC_DID_SERVICE_SELF_REGISTRATION_ENABLED"
258258
value: {{ .Values.iatp.didService.selfRegistration.enabled | quote}}
259-
{{- if .Values.iatp.didService.selfRegistration.enabled }}
259+
- name: "TX_EDC_DID_SERVICE_SELF_DEREGISTRATION_ENABLED"
260+
value: {{ and (eq (int .Values.controlplane.replicaCount) 1) (not .Values.controlplane.autoscaling.enabled) | quote }}
260261
- name: "TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID"
261-
value: {{ .Values.iatp.didService.selfRegistration.id | required ".Values.iatp.didService.selfRegistration.id is required" | quote }}
262-
{{- end }}
262+
value: {{ .Values.iatp.didService.selfRegistration.id | quote }}
263263
- name: "TX_EDC_DCP_CACHE_ENABLED"
264264
value: {{ .Values.iatp.cache.enabled | quote }}
265265
- name: "TX_EDC_DCP_CACHE_VALIDITY_SECONDS"

edc-extensions/did-document/did-document-service-self-registration/src/main/java/org/eclipse/tractusx/edc/did/document/service/self/registration/DidDocumentServiceSelfRegistrationExtension.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
public class DidDocumentServiceSelfRegistrationExtension implements ServiceExtension {
3737

3838
public static final String TX_EDC_DID_SERVICE_SELF_REGISTRATION_ENABLED = "tx.edc.did.service.self.registration.enabled";
39+
public static final String TX_EDC_DID_SERVICE_SELF_DEREGISTRATION_ENABLED = "tx.edc.did.service.self.deregistration.enabled";
3940
public static final String TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID = "tx.edc.did.service.self.registration.id";
4041

4142
public static final String DATA_SERVICE_TYPE = "DataService";
@@ -54,6 +55,9 @@ public class DidDocumentServiceSelfRegistrationExtension implements ServiceExten
5455
@Setting(key = TX_EDC_DID_SERVICE_SELF_REGISTRATION_ENABLED, defaultValue = "false", description = "Enable self-registration of the DID Document Service")
5556
private boolean selfRegistrationEnabled;
5657

58+
@Setting(key = TX_EDC_DID_SERVICE_SELF_DEREGISTRATION_ENABLED, defaultValue = "false", description = "Enable self-deregistration of the DID Document Service")
59+
private boolean selfDeregistrationEnabled;
60+
5761
@Setting(key = TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID, required = false, description = "The Id to use for service self-registration (should be valid URI)")
5862
private String serviceId;
5963

@@ -68,7 +72,7 @@ public void start() {
6872
@Override
6973
public void shutdown() {
7074
Optional.ofNullable(didDocumentServiceClient)
71-
.filter(client -> selfRegistrationEnabled)
75+
.filter(client -> selfDeregistrationEnabled)
7276
.ifPresent(this::selfUnregisterDidDocumentService);
7377
}
7478

@@ -100,7 +104,7 @@ private void selfUnregisterDidDocumentService(@NotNull DidDocumentServiceClient
100104
private Result<String> validatedServiceId(String serviceId) {
101105

102106
if (serviceId == null || serviceId.isBlank()) {
103-
return Result.failure("Service ID for DID Document Service self-registration configured via Property '%s' is missing or blank but self-registration is enabled.".formatted(TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID));
107+
return Result.failure("Service ID for DID Document Service configured via Property '%s' is missing or blank but self-registration / de-registration is enabled.".formatted(TX_EDC_DID_SERVICE_SELF_REGISTRATION_ID));
104108
}
105109
try {
106110
new URI(serviceId);

edc-extensions/did-document/did-document-service-self-registration/src/test/java/org/eclipse/tractusx/edc/did/document/service/self/registration/DidDocumentServiceSelfRegistrationExtensionTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void setup(ServiceExtensionContext context) {
6868
void start_shouldSelfRegister_whenEnabledAndClientPresent(ServiceExtensionContext context, ObjectFactory objectFactory) {
6969

7070
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true",
71+
"tx.edc.did.service.self.deregistration.enabled", "true",
7172
"tx.edc.did.service.self.registration.id", SERVICE_ID);
7273
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
7374
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);
@@ -93,6 +94,7 @@ void start_shouldSelfRegister_whenEnabledAndClientPresent(ServiceExtensionContex
9394
void start_selfRegister_whenEnabledAndClientReturnsFailure(ServiceExtensionContext context, ObjectFactory objectFactory) {
9495

9596
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true",
97+
"tx.edc.did.service.self.deregistration.enabled", "true",
9698
"tx.edc.did.service.self.registration.id", SERVICE_ID);
9799
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
98100
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);
@@ -130,7 +132,7 @@ void start_shouldNotSelfRegister_whenClientNotPresent(ObjectFactory objectFactor
130132
@Test
131133
void start_shouldNotSelfRegister_whenDisabledAndClientPresent(ServiceExtensionContext context, ObjectFactory objectFactory) {
132134

133-
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "false");
135+
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "false", "tx.edc.did.service.self.deregistration.enabled", "false");
134136
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
135137
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);
136138

@@ -147,15 +149,15 @@ void start_shouldNotSelfRegister_whenDisabledAndClientPresent(ServiceExtensionCo
147149
@Test
148150
void start_shouldNotSelfRegister_whenEnabledAndServiceIdMissing(ServiceExtensionContext context, ObjectFactory objectFactory) {
149151

150-
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true");
152+
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true", "tx.edc.did.service.self.deregistration.enabled", "true");
151153
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
152154
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);
153155

154156
var extension = objectFactory.constructInstance(DidDocumentServiceSelfRegistrationExtension.class);
155157
extension.start();
156158

157159
verify(didDocumentServiceClient, never()).update(any(Service.class));
158-
verify(monitor).severe(contains("is missing or blank but self-registration is enabled"));
160+
verify(monitor).severe(contains("is missing or blank but self-registration / de-registration is enabled"));
159161

160162
extension.shutdown();
161163
verify(didDocumentServiceClient, never()).deleteById(anyString());
@@ -167,6 +169,7 @@ void start_shouldNotSelfRegister_whenEnabledAndServiceIdMissing(ServiceExtension
167169
void start_shouldNotSelfRegister_whenEnabledAndServiceIdEmptyOrBlank(String serviceId, ServiceExtensionContext context, ObjectFactory objectFactory) {
168170

169171
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true",
172+
"tx.edc.did.service.self.dregistration.enabled", "true",
170173
"tx.edc.did.service.self.registration.id", serviceId);
171174
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
172175
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);
@@ -175,7 +178,7 @@ void start_shouldNotSelfRegister_whenEnabledAndServiceIdEmptyOrBlank(String serv
175178
extension.start();
176179

177180
verify(didDocumentServiceClient, never()).update(any(Service.class));
178-
verify(monitor).severe(contains("is missing or blank but self-registration is enabled"));
181+
verify(monitor).severe(contains("is missing or blank but self-registration / de-registration is enabled"));
179182

180183
extension.shutdown();
181184
verify(didDocumentServiceClient, never()).deleteById(anyString());
@@ -185,6 +188,7 @@ void start_shouldNotSelfRegister_whenEnabledAndServiceIdEmptyOrBlank(String serv
185188
void start_shouldNotSelfRegister_whenEnabledAndServiceIdInvalid(ServiceExtensionContext context, ObjectFactory objectFactory) {
186189

187190
var settings = Map.of("tx.edc.did.service.self.registration.enabled", "true",
191+
"tx.edc.did.service.self.deregistration.enabled", "true",
188192
"tx.edc.did.service.self.registration.id", "invalid uri");
189193
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(settings));
190194
context.registerService(DidDocumentServiceClient.class, didDocumentServiceClient);

0 commit comments

Comments
 (0)