Skip to content
Snippets Groups Projects
Commit 7fbcaf7e authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Fixing affiliation definition if not provided

parent 1e94dc62
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,14 @@ const createAttrs = (organization, role, affiliation, email, lang = "es") => [ ...@@ -37,6 +37,14 @@ const createAttrs = (organization, role, affiliation, email, lang = "es") => [
const toValidHfAffiliation = affiliation => const toValidHfAffiliation = affiliation =>
affiliation ? "org1.department1." + affiliation : "org1.department1" affiliation ? "org1.department1." + affiliation : "org1.department1"
const extractAffiliationFromAttrs = attrs => {
const affiliationAttr = attrs.find(attr => attr.name === "affiliation")
if (!!affiliationAttr) {
return toValidHfAffiliation(affiliationAttr.value)
}
// return undefined
}
class SDKHelper { class SDKHelper {
constructor(connectionProfilePath) { constructor(connectionProfilePath) {
this.connectionProfile = loadProfile(connectionProfilePath) this.connectionProfile = loadProfile(connectionProfilePath)
...@@ -128,6 +136,8 @@ class SDKHelper { ...@@ -128,6 +136,8 @@ class SDKHelper {
await wallet.put(userId, x509Identity) await wallet.put(userId, x509Identity)
} }
// Register the user, enroll the user, and import the new identity into the wallet.
// if affiliation is specified by client, the affiliation value must be configured in CA
async createUser( async createUser(
userId, userId,
password, password,
...@@ -145,7 +155,7 @@ class SDKHelper { ...@@ -145,7 +155,7 @@ class SDKHelper {
enrollmentID: userId, enrollmentID: userId,
enrollmentSecret: password, enrollmentSecret: password,
role: "client", // "hf.Type" in the certificate role: "client", // "hf.Type" in the certificate
affiliation: toValidHfAffiliation(affiliation), affiliation: extractAffiliationFromAttrs(extraAttrs),
maxEnrollments: -1, // unlimited maxEnrollments: -1, // unlimited
attrs: updateAttrs( attrs: updateAttrs(
createAttrs(organization, role, email, language), createAttrs(organization, role, email, language),
...@@ -155,10 +165,7 @@ class SDKHelper { ...@@ -155,10 +165,7 @@ class SDKHelper {
adminUser adminUser
) )
// Register the user, enroll the user, and import the new identity into the wallet. await this._enrollUser(userId, password, organization)
// if affiliation is specified by client, the affiliation value must be configured in CA
const secret = await this._register(organization)
await this._enrollUser(userId, secret, organization)
} }
/** /**
...@@ -190,19 +197,12 @@ class SDKHelper { ...@@ -190,19 +197,12 @@ class SDKHelper {
const adminUser = await provider.getUserContext(adminIdentity, "admin") const adminUser = await provider.getUserContext(adminIdentity, "admin")
const identityService = await this.caClient.newIdentityService() const identityService = await this.caClient.newIdentityService()
const affiliationAttr = oldCert.attrs.find(
attr => attr.name === "affiliation"
)
const affiliation = affiliationAttr
? toValidHfAffiliation(affiliationAttr.value)
: undefined
return identityService.update( return identityService.update(
userId, userId,
{ {
enrollmentID: userId, enrollmentID: userId,
secret: password, secret: password,
affiliation, affiliation: extractAffiliationFromAttrs(oldCert.attrs),
role: "client", // "hf.Type" in the certificate role: "client", // "hf.Type" in the certificate
attrs: updateAttrs( attrs: updateAttrs(
createAttrs(organization, role, email), createAttrs(organization, role, email),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment