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
Branches
No related tags found
No related merge requests found
......@@ -37,6 +37,14 @@ const createAttrs = (organization, role, affiliation, email, lang = "es") => [
const toValidHfAffiliation = affiliation =>
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 {
constructor(connectionProfilePath) {
this.connectionProfile = loadProfile(connectionProfilePath)
......@@ -128,6 +136,8 @@ class SDKHelper {
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(
userId,
password,
......@@ -145,7 +155,7 @@ class SDKHelper {
enrollmentID: userId,
enrollmentSecret: password,
role: "client", // "hf.Type" in the certificate
affiliation: toValidHfAffiliation(affiliation),
affiliation: extractAffiliationFromAttrs(extraAttrs),
maxEnrollments: -1, // unlimited
attrs: updateAttrs(
createAttrs(organization, role, email, language),
......@@ -155,10 +165,7 @@ class SDKHelper {
adminUser
)
// 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
const secret = await this._register(organization)
await this._enrollUser(userId, secret, organization)
await this._enrollUser(userId, password, organization)
}
/**
......@@ -190,19 +197,12 @@ class SDKHelper {
const adminUser = await provider.getUserContext(adminIdentity, "admin")
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(
userId,
{
enrollmentID: userId,
secret: password,
affiliation,
affiliation: extractAffiliationFromAttrs(oldCert.attrs),
role: "client", // "hf.Type" in the certificate
attrs: updateAttrs(
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