Skip to content

Commit

Permalink
Merge pull request #297 from holashchand/environment-fix
Browse files Browse the repository at this point in the history
Fixed signature v2 environment variables
  • Loading branch information
srprasanna authored Mar 26, 2024
2 parents 2244712 + 32ac0d2 commit f0d8afb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
15 changes: 0 additions & 15 deletions docker-compose-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,8 @@ services:
- sunbird_sso_admin_client_secret=${KEYCLOAK_SECRET}
- claims_enabled=${CLAIMS_ENABLED-false}
- claims_url=http://claim-ms:8082
- did_enabled=${DID_ENABLED-false}
- did_health_check_url=${DID_HEALTH_CHECK_URL-http://identity:3332/health}
- did_generate_url=${DID_GENERATE_URL-http://identity:3332/did/generate}
- did_resolve_url=${DID_RESOLVE_URL-http://identity:3332/did/resolve}
- signature_enabled=${SIGNATURE_ENABLED-false}
- signature_provider=${SIGNATURE_PROVIDER-dev.sunbirdrc.registry.service.impl.SignatureV1ServiceImpl}
- signature_v2_health_check_url=${SIGNATURE_V2_HEALTH_CHECK_URL-http://credential:3000/health}
- signature_v2_issue_url=${SIGNATURE_V2_ISSUE_URL-http://credential:3000/credentials/issue}
- signature_v2_get_url=${SIGNATURE_V2_GET_URL-http://credential:3000/credentials/{id}}
- signature_v2_delete_url=${SIGNATURE_V2_DELETE_URL-http://credential:3000/credentials/{id}}
- signature_v2_verify_url=${SIGNATURE_V2_VERIFY_URL-http://credential:3000/credentials/{id}/verify}
- signature_v2_revocation_list_url=${SIGNATURE_V2_REVOCATION_LIST_URL-http://credential:3000/credentials/revocation-list?issuerId={issuerDid}&page={page}&limit={limit}}
- signature_v2_schema_health_check_url=${SIGNATURE_V2_SCHEMA_HEALTH_CHECK_URL-http://schema:3333/health}
- signature_v2_schema_create_url=${SIGNATURE_V2_SCHEMA_CREATE_URL-http://schema:3333/credential-schema}
- signature_v2_schema_update_url=${SIGNATURE_V2_SCHEMA_UPDATE_URL-http://schema:3333/credential-schema/{id}/{version}}
- signature_v2_schema_get_by_id_and_version_url=${SIGNATURE_V2_SCHEMA_GET_BY_ID_AND_VERSION_URL-http://schema:3333/credential-schema/{id}/{version}
- signature_v2_schema_search_by_tags_url=${SIGNATURE_V2_SCHEMA_GET_BY_TAGS_URL-http://schema:3333/credential-schema?tags={tags}}
- sign_url=http://certificate-signer:8079/sign
- verify_url=http://certificate-signer:8079/verify
- sign_health_check_url=http://certificate-signer:8079/health
Expand Down
32 changes: 18 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,26 @@ services:
- claims_enabled=${CLAIMS_ENABLED-false}
- claims_url=http://claim-ms:8082
- did_enabled=${DID_ENABLED-false}
- did_health_check_url=${DID_HEALTH_CHECK_URL-http://identity:3332/health}
- did_generate_url=${DID_GENERATE_URL-http://identity:3332/did/generate}
- did_resolve_url=${DID_RESOLVE_URL-http://identity:3332/did/resolve}
- did_health_check_url=http://identity:3332/health
- did_generate_url=http://identity:3332/did/generate
- did_resolve_url=http://identity:3332/did/resolve/{id}
- signature_enabled=${SIGNATURE_ENABLED-false}
- signature_provider=${SIGNATURE_PROVIDER-dev.sunbirdrc.registry.service.impl.SignatureV2ServiceImpl}
- signature_v2_health_check_url=${SIGNATURE_V2_HEALTH_CHECK_URL-http://credential:3000/health}
- signature_v2_issue_url=${SIGNATURE_V2_ISSUE_URL-http://credential:3000/credentials/issue}
- signature_v2_get_url=${SIGNATURE_V2_GET_URL-http://credential:3000/credentials/{id}}
- signature_v2_delete_url=${SIGNATURE_V2_DELETE_URL-http://credential:3000/credentials/{id}}
- signature_v2_verify_url=${SIGNATURE_V2_VERIFY_URL-http://credential:3000/credentials/{id}/verify}
- signature_v2_revocation_list_url=${SIGNATURE_V2_REVOCATION_LIST_URL-http://credential:3000/credentials/revocation-list?issuerId={issuerDid}&page={page}&limit={limit}}
- signature_v2_schema_health_check_url=${SIGNATURE_V2_SCHEMA_HEALTH_CHECK_URL-http://credential-schema:3333/health}
- signature_v2_schema_create_url=${SIGNATURE_V2_SCHEMA_CREATE_URL-http://credential-schema:3333/credential-schema}
- signature_v2_schema_update_url=${SIGNATURE_V2_SCHEMA_UPDATE_URL-http://credential-schema:3333/credential-schema/{id}/{version}}
- signature_v2_schema_get_by_id_and_version_url=${SIGNATURE_V2_SCHEMA_GET_BY_ID_AND_VERSION_URL-http://credential-schema:3333/credential-schema/{id}/{version}
- signature_v2_schema_search_by_tags_url=${SIGNATURE_V2_SCHEMA_GET_BY_TAGS_URL-http://credential-schema:3333/credential-schema?tags={tags}}
- signature_v2_credential_did_method=rcw
- signature_v2_issuer_did_method=issuer
- signature_v2_schema_author=Registry
- signature_v2_schema_author_did_method=author
- signature_v2_health_check_url=http://credential:3000/health
- signature_v2_issue_url=http://credential:3000/credentials/issue
- signature_v2_get_url=http://credential:3000/credentials/{id}
- signature_v2_delete_url=http://credential:3000/credentials/{id}
- signature_v2_verify_url=http://credential:3000/credentials/{id}/verify
- signature_v2_revocation_list_url=http://credential:3000/credentials/revocation-list?issuerId={issuerDid}&page={page}&limit={limit}
- signature_v2_schema_health_check_url=http://credential-schema:3333/health
- signature_v2_schema_create_url=http://credential-schema:3333/credential-schema
- signature_v2_schema_update_url=http://credential-schema:3333/credential-schema/{id}/{version}
- signature_v2_schema_get_by_id_and_version_url=http://credential-schema:3333/credential-schema/{id}/{version}
- signature_v2_schema_search_by_tags_url=http://credential-schema:3333/credential-schema?tags={tags}
- sign_url=http://certificate-signer:8079/sign
- verify_url=http://certificate-signer:8079/verify
- sign_health_check_url=http://certificate-signer:8079/health
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public class CredentialSchemaService implements HealthIndicator {
private String getByTagsUrl;

@Autowired(required = false)
dev.sunbirdrc.registry.service.DIDService DIDService;
private DIDService didService;
@Autowired
IDefinitionsManager definitionsManager;

private static final String authorName = "Registry";
private static final String authorDidMethod = "abc";
@Value("${signature.v2.schema.author}")
private String authorName;
@Value("${signature.v2.schema.authorDidMethod}")
private String authorDidMethod;

@Autowired
private RetryRestTemplate retryRestTemplate;
Expand Down Expand Up @@ -111,7 +113,7 @@ public void ensureCredentialSchema(String title, Object credTemplate, String sta
logger.debug("Ensuring credential schema for {}", title);
JsonNode schema = convertCredentialTemplateToSchema(title, credTemplate);
ObjectNode prevSchema = (ObjectNode) getLatestSchemaByTags(Collections.singletonList(title));
String author = DIDService.ensureDidForName(authorName, authorDidMethod);
String author = didService.ensureDidForName(authorName, authorDidMethod);
String authored = Instant.now().toString();
((ObjectNode) schema).set("author", JsonNodeFactory.instance.textNode(author));
((ObjectNode) schema).set("authored", JsonNodeFactory.instance.textNode(authored));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -29,6 +30,7 @@
import static dev.sunbirdrc.registry.middleware.util.Constants.*;

@Component
@ConditionalOnProperty(value = "did.enabled", havingValue = "true")
public class DIDService implements HealthIndicator {
private static final Logger logger = LoggerFactory.getLogger(DIDService.class);
@Value("${did.healthCheckURL}")
Expand Down Expand Up @@ -120,7 +122,7 @@ public String generateDid(String method, Map<String, Object> content) {

public JsonNode resolveDid(String didId) {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(resolveIdUrl + "/" + didId);
ResponseEntity<String> response = retryRestTemplate.getForEntity(resolveIdUrl, didId);
if (response.getStatusCode().is2xxSuccessful()) {
return JSONUtil.convertStringJsonNode(response.getBody());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.sunbirdrc.registry.exception.SignatureException;
import dev.sunbirdrc.registry.middleware.util.JSONUtil;
import dev.sunbirdrc.registry.service.CredentialSchemaService;
import dev.sunbirdrc.registry.service.DIDService;
import dev.sunbirdrc.registry.service.ICertificateService;
import dev.sunbirdrc.registry.service.SignatureService;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -56,8 +57,10 @@ public class SignatureV2ServiceImpl implements SignatureService, ICertificateSer
@Value("${signature.v2.getRevocationListURL}")
private String getRevocationListURL;

private static final String credentialMethod = "rcw";
private static final String credentialIssuerMethod = "abc";
@Value("${signature.v2.credentialDidMethod}")
private String credentialMethod;
@Value("${signature.v2.issuerDidMethod}")
private String credentialIssuerMethod;

@Autowired
protected RetryRestTemplate retryRestTemplate;
Expand All @@ -66,7 +69,7 @@ public class SignatureV2ServiceImpl implements SignatureService, ICertificateSer
@Autowired
private CredentialSchemaService credentialSchemaService;
@Autowired
private dev.sunbirdrc.registry.service.DIDService DIDService;
private DIDService didService;

@Override
public Object sign(Map<String, Object> propertyValue) throws SignatureException.UnreachableException, SignatureException.CreationException {
Expand Down Expand Up @@ -99,7 +102,7 @@ public boolean verify(Object propertyValue) throws SignatureException.Unreachabl

@Override
public String getKey(String keyId) throws SignatureException.UnreachableException, SignatureException.KeyNotFoundException {
ObjectNode didDocument = (ObjectNode) DIDService.resolveDid(keyId);
ObjectNode didDocument = (ObjectNode) didService.resolveDid(keyId);
ArrayNode verificationMethods = (ArrayNode) didDocument.get("verificationMethod");
AtomicReference<JsonNode> verificationMethod = new AtomicReference<>();
verificationMethods.elements().forEachRemaining(vm -> {
Expand Down Expand Up @@ -131,7 +134,7 @@ public Object getCertificate(JsonNode credentialId, String entityName, String en
return getCredentialById(credentialId.asText(), mediaType, templateId, template);
}

private JsonNode issueCredential(String title, Object credentialTemplate, JsonNode input) throws Exception {
public JsonNode issueCredential(String title, Object credentialTemplate, JsonNode input) throws Exception {
// Render the credential using credential template
Handlebars hb = new Handlebars();
String templateJsonString = null;
Expand All @@ -152,7 +155,7 @@ private JsonNode issueCredential(String title, Object credentialTemplate, JsonNo


// ensure issuer did
String issuerDid = DIDService.ensureDidForName(credential.get("issuer").asText(), credentialIssuerMethod);
String issuerDid = didService.ensureDidForName(credential.get("issuer").asText(), credentialIssuerMethod);
credential.set("issuer", JsonNodeFactory.instance.textNode(issuerDid));

// Wire the create credential request payload
Expand Down
6 changes: 5 additions & 1 deletion java/registry/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ did:
enabled: ${did_enabled:false}
healthCheckURL: ${did_health_check_url:http://localhost:3332/health}
generateURL: ${did_generate_url:http://localhost:3332/did/generate}
resolveURL: ${did_resolve_url:http://localhost:3332/did/resolve}
resolveURL: ${did_resolve_url:http://localhost:3332/did/resolve/{id}}

signature:
enabled: ${signature_enabled:false}
Expand All @@ -369,13 +369,17 @@ signature:
keysURL: ${keys_url:http://localhost:8013/keys/}
domain: ${domain_url:https://w3id.org/security/v1/}
v2:
credentialDidMethod: ${signature_v2_credential_did_method:rcw}
issuerDidMethod: ${signature_v2_issuer_did_method:issuer}
healthCheckURL: ${signature_v2_health_check_url:http://localhost:3000/health}
issueCredentialURL: ${signature_v2_issue_url:http://localhost:3000/credentials/issue}
getCredentialByIdURL: ${signature_v2_get_url:http://localhost:3000/credentials/{id}}
deleteCredentialByIdURL: ${signature_v2_delete_url:http://localhost:3000/credentials/{id}}
verifyCredentialURL: ${signature_v2_verify_url:http://localhost:3000/credentials/{id}/verify}
getRevocationListURL: ${signature_v2_revocation_list_url:http://localhost:3000/credentials/revocation-list?issuerId={issuerDid}&page={page}&limit={limit}}
schema:
author: ${signature_v2_schema_author:Registry}
authorDidMethod: ${signature_v2_schema_author_did_method:author}
healthCheckURL: ${signature_v2_schema_health_check_url:http://localhost:3333/health}
createSchemaURL: ${signature_v2_schema_create_url:http://localhost:3333/credential-schema}
updateSchemaURL: ${signature_v2_schema_update_url:http://localhost:3333/credential-schema/{id}/{version}}
Expand Down

0 comments on commit f0d8afb

Please sign in to comment.