Skip to content

Commit

Permalink
Integrate review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anjastrunk committed Aug 21, 2024
1 parent 0e8c986 commit 92702cd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 62 deletions.
48 changes: 25 additions & 23 deletions generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
VC_NAME_LOOKUP = {
"lp": "Legal Person",
"lrn": "Legal Registration Number",
"tandc": "Gaia-X Terms and Contitions",
"tandc": "Gaia-X Terms and Conditions",
"cs": "GXDCH Compliance Service",
"so": "Service Offering",
"vmso": "Virtual Machine Service Offering",
Expand Down Expand Up @@ -175,31 +175,33 @@ def create_vmso_vcs(conf: Config, cloud: str, csp_vcs: List[dict], timeout: int

# build Gaia-X Credential for Service Offering
print('Create VC of type "gx:ServiceOffering"...', end='')
so_vc = dict()
so_vc['@context'] = [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT]
so_vc['type'] = "VerifiableCredential"
so_vc['id'] = cred_settings[const.CONFIG_CRED_BASE_CRED_URL] + "/so.json"
so_vc['issuer'] = csp['did']
so_vc['issuanceDate'] = str(datetime.now(tz=timezone.utc).isoformat())
so_vc['credentialSubject'] = {
"type": "gx:ServiceOffering",
"id": cred_settings[const.CONFIG_CRED_BASE_CRED_URL] + "/so_cs.json", # iaas['did'],
"gx:providedBy": {
'id': csp_vcs['lp']['credentialSubject']['id']
},
"gx:termsAndConditions": list(),
"gx:policy": vm_offering.servicePolicy,
"gx:dataAccountExport": {
"gx:requestType": vm_offering.dataAccountExport.requestType.code.text,
"gx:accessType": vm_offering.dataAccountExport.accessType.code.text,
"gx:formatType": "application/" + vm_offering.dataAccountExport.formatType.code.text
so_vc = {
'@context': [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT],
'type': "VerifiableCredential",
'id': cred_settings[const.CONFIG_CRED_BASE_CRED_URL] + "/so.json",
'issuer': csp['did'],
'issuanceDate': str(datetime.now(tz=timezone.utc).isoformat()),
'credentialSubject': {
"type": "gx:ServiceOffering",
"id": cred_settings[const.CONFIG_CRED_BASE_CRED_URL] + "/so_cs.json", # iaas['did'],
"gx:providedBy": {
'id': csp_vcs['lp']['credentialSubject']['id']
},
"gx:termsAndConditions": [
{'gx:URL': s_tac.url, 'gx:hash': s_tac.hash}
for s_tac in vm_offering.serviceOfferingTermsAndConditions],
"gx:policy": vm_offering.servicePolicy,
"gx:dataAccountExport": {
"gx:requestType": vm_offering.dataAccountExport.requestType.code.text,
"gx:accessType": vm_offering.dataAccountExport.accessType.code.text,
"gx:formatType": "application/" + vm_offering.dataAccountExport.formatType.code.text
}
}
}

for s_tac in vm_offering.serviceOfferingTermsAndConditions:
so_vc['credentialSubject']["gx:termsAndConditions"].append({
'gx:URL': s_tac.url,
'gx:hash': s_tac.hash})




# sign service offering credential
so_vc_signed = crypto.sign_cred(cred=so_vc,
Expand Down
60 changes: 31 additions & 29 deletions generator/discovery/csp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ def _sign_gaia_x_terms_and_conditions(self, auto_sign: bool = False) -> dict:
print("Gaia-X terms and conditions were not signed - process aborted!")
return

tandc_vc = dict()
tandc_vc['@context'] = [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT]
tandc_vc['type'] = "VerifiableCredential"
tandc_vc['id'] = self.cred_base_url + "/tandc.json"
tandc_vc['issuer'] = self.csp['did']
tandc_vc['issuanceDate'] = str(datetime.now(tz=timezone.utc).isoformat())
tandc_vc['credentialSubject'] = {
"type": "gx:GaiaXTermsAndConditions",
"gx:termsAndConditions": tand['text'],
"id": self.cred_base_url + "/tandc_cs.json"
tandc_vc = {
'@context': [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT],
'type': "VerifiableCredential",
'id': self.cred_base_url + "/tandc.json",
'issuer': self.csp['did'],
'issuanceDate': str(datetime.now(tz=timezone.utc).isoformat()),
'credentialSubject': {
"type": "gx:GaiaXTermsAndConditions",
"gx:termsAndConditions": tand['text'],
"id": self.cred_base_url + "/tandc_cs.json"
}
}
return crypto.sign_cred(cred=tandc_vc,
key=crypto.load_jwk_from_file(self.cred_settings[const.CONFIG_CRED_KEY]),
Expand All @@ -110,25 +111,26 @@ def _sign_legal_person(self, lrn_cred_id: str):
@param lrn_cred_id: Id of Verifiable Credential attesting CSP's legal registration number.
@return: Gaia-X Credential on CSP as Legal Person as dictionary.
"""
lp_vc = dict()
lp_vc['@context'] = [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT]
lp_vc['type'] = "VerifiableCredential"
lp_vc['id'] = self.cred_base_url + "/legal_person.json"
lp_vc['issuer'] = self.csp['did']
lp_vc['issuanceDate'] = str(datetime.now(tz=timezone.utc).isoformat())
lp_vc['credentialSubject'] = {
"id": self.cred_base_url + "/legal_person_cs.json", # I think "self.csp['did']" is correct, but Gaia-X expects link,
# "id": self.csp['did'],
"type": "gx:LegalParticipant",
"gx:legalName": self.csp['legal-name'],
"gx:legalRegistrationNumber": {
"id": lrn_cred_id
},
"gx:headquarterAddress": {
"gx:countrySubdivisionCode": self.csp['legal-address-country-code']
},
"gx:legalAddress": {
"gx:countrySubdivisionCode": self.csp['headquarter-address-country-code']
lp_vc = {
'@context': [const.VC_CONTEXT, const.JWS_CONTEXT, const.REG_CONTEXT],
'type': "VerifiableCredential",
'id': self.cred_base_url + "/legal_person.json",
'issuer': self.csp['did'],
'issuanceDate': str(datetime.now(tz=timezone.utc).isoformat()),
'credentialSubject': {
"id": self.cred_base_url + "/legal_person_cs.json", # I think "self.csp['did']" is correct, but Gaia-X expects link,
# "id": self.csp['did'],
"type": "gx:LegalParticipant",
"gx:legalName": self.csp['legal-name'],
"gx:legalRegistrationNumber": {
"id": lrn_cred_id
},
"gx:headquarterAddress": {
"gx:countrySubdivisionCode": self.csp['legal-address-country-code']
},
"gx:legalAddress": {
"gx:countrySubdivisionCode": self.csp['headquarter-address-country-code']
}
}
}
return crypto.sign_cred(cred=lp_vc,
Expand Down
19 changes: 9 additions & 10 deletions generator/discovery/gxdch_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ def request_compliance_vc(self, vp: str, vp_id) -> str:
class NotaryService:
""" Wrapper class to connect GXDCH Notary Service. """

def __init__(self, api: str):
if not api:
def __init__(self, api_url: str):
if not api_url:
raise AttributeError("Parameters MUST not be None")
self.api = api
self.api = api_url

# TODO: Support all kind of registration numbers
def request_reg_number_vc(self, csp: dict, cred_id: str, cred_subject_id: str) -> dict:
body = dict()
body['@context'] = const.LRN_CONTEXT
body['type'] = "gx:legalRegistrationNumber"
body['id'] = cred_subject_id # csp['did'] TODO: I think DID is correct here, but Gaia-X requires credential id, instead of credential subject id
body['gx:vatID'] = csp[const.CONFIG_CSP_REG_NUMBER][const.CONFIG_CSP_VAT_ID]

body = {
'@context': const.LRN_CONTEXT,
'type': "gx:legalRegistrationNumber",
'id': cred_subject_id, # csp['did'] TODO: I think DID is correct here, but Gaia-X requires credential id, instead of credential subject id
'gx:vatID': csp[const.CONFIG_CSP_REG_NUMBER][const.CONFIG_CSP_VAT_ID],
}
resp = requests.post(self.api + "/registrationNumberVC?vcid=" + str(cred_id), json=body)

if resp.ok:
Expand All @@ -53,7 +53,6 @@ def __init__(self, api: str):

def get_gx_tandc(self) -> dict:
resp = requests.get(self.api + "/api/termsAndConditions")

if resp.ok:
return resp.json()
else:
Expand Down

0 comments on commit 92702cd

Please sign in to comment.