Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions e2e/fabloCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,35 @@ describe("version", () => {
expect(commandResult1.output).toEqual(commandResult2.output);
});
});

describe("generate", () => {
beforeEach(() => commands.cleanupWorkdir());

it("should generate Fabric-X network files with custom organization", () => {
// Given
commands.fabloExec(
"init fabric-x --set orgs[0].organization.name=Bank --set orgs[0].organization.domain=bank.fablo.com --set orgs[0].organization.mspName=BankMSP --set channels[0].orgs[0].name=Bank",
);

// When
const commandResult = commands.fabloExec("generate");

// Then
expect(commandResult).toEqual(TestCommands.success());

const fxConfig = commands.getFileContent("fablo-target/fabric-x/fxconfig.yaml");
expect(fxConfig).toContain("localMspID: BankMSP");

const configtx = commands.getFileContent("fablo-target/fabric-x/configtx.yaml");
expect(configtx).toContain("MSPDir: ./crypto/peerOrganizations/bank.fablo.com/msp");

const dockerCompose = commands.getFileContent("fablo-target/fabric-x/docker-compose.yaml");
expect(dockerCompose).toContain("tlsca.bank.fablo.com-cert.pem");
expect(dockerCompose).toContain("User1@bank.fablo.com");
expect(dockerCompose).toContain("committer-bank-coordinator");

const baseFunctions = commands.getFileContent("fablo-target/fabric-x/scripts/base-functions.sh");
expect(baseFunctions).toContain("User1@bank.fablo.com");
expect(baseFunctions).toContain("AND('BankMSP.member')");
});
});
19 changes: 17 additions & 2 deletions src/setup-docker/fabricXDockerWriter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FabloConfigExtended } from "../types/FabloConfigExtended";
import { FabloConfigExtended, OrgConfig } from "../types/FabloConfigExtended";
import { renderTemplate, getTemplatePath, getDestinationPath } from "../utils/templateUtils";
import * as fs from "fs-extra";
import * as path from "path";
Expand All @@ -7,16 +7,31 @@ export class FabricXDockerWriter {
constructor(private templatesDir: string, private outputDir: string, private log: (msg: string) => void) {}

public async write(configExtended: FabloConfigExtended): Promise<void> {
const primaryOrg = this.validateAndExtractContext(configExtended);

this.log("Generating Fabric-X network files...");

const data = configExtended as unknown as Record<string, unknown>;
const primaryOrgSlug = primaryOrg.name.toLowerCase();
const data: Record<string, unknown> = {
...configExtended,
primaryOrg,
primaryOrgSlug,
};
Comment thread
umegbewe marked this conversation as resolved.

await this.renderTemplateFile("fabric-x-docker.sh", data);
await this.renderTemplateDirectory("fabric-x", data);

this.log("Fabric-X network files successfully generated under fabric-x/");
}

private validateAndExtractContext(config: FabloConfigExtended): OrgConfig {
const channel = config.channels?.[0];
if (!channel || !channel.instantiatingOrg) {
throw new Error("Fabric-X generator requires at least one channel with an organization.");
}
return channel.instantiatingOrg;
}

private async renderTemplateFile(file: string, data: Record<string, unknown>): Promise<void> {
const templatePath = getTemplatePath(this.templatesDir, file);
const destPath = getDestinationPath(this.outputDir, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ monitoring:

verifier:
endpoints:
- committer-org1-verifier:5001
- committer-<%= primaryOrgSlug %>-verifier:5001
tls:
mode: mtls
cert-path: /node-tls/server.crt
Expand All @@ -24,7 +24,7 @@ verifier:

validator-committer:
endpoints:
- committer-org1-validator:6001
- committer-<%= primaryOrgSlug %>-validator:6001
tls:
mode: mtls
cert-path: /node-tls/server.crt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ monitoring:

database:
endpoints:
- committer-org1-db:5432
- committer-<%= primaryOrgSlug %>-db:5432
username: fabricx
password: fabricx
database: fabricx
Expand Down
4 changes: 2 additions & 2 deletions src/setup-docker/templates/fabric-x/config/sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ orderer:

- /orderer-cas/Orderer/msp/tlscacerts/tlsca.orderer.example.com-cert.pem
identity:
msp-id: Org1MSP
msp-id: <%= primaryOrg.mspName %>
msp-dir: /msp
bccsp:
Default: SW
Expand All @@ -31,7 +31,7 @@ orderer:
Hash: SHA2

committer:
endpoint: committer-org1-coordinator:9001
endpoint: committer-<%= primaryOrgSlug %>-coordinator:9001
tls: *tlsConfig

ledger:
Expand Down
4 changes: 2 additions & 2 deletions src/setup-docker/templates/fabric-x/config/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ monitoring:

database:
endpoints:
- committer-org1-db:5432
- committer-<%= primaryOrgSlug %>-db:5432
username: fabricx
password: fabricx
database: fabricx
Expand All @@ -32,7 +32,7 @@ resource-limits:
timeout-for-min-transaction-batch-size: 5s

identity:
msp-id: Org1MSP
msp-id: <%= primaryOrg.mspName %>

logging:
logSpec: info:grpc=error
20 changes: 10 additions & 10 deletions src/setup-docker/templates/fabric-x/configtx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ Organizations:



- &Org1MSP
Name: Org1
ID: Org1MSP
MSPDir: ./crypto/peerOrganizations/org1.example.com/msp
- &<%= primaryOrg.mspName %>
Name: <%= primaryOrg.name %>
ID: <%= primaryOrg.mspName %>
MSPDir: ./crypto/peerOrganizations/<%= primaryOrg.domain %>/msp
Policies:
Readers:
Type: Signature
Rule: OR('Org1MSP.member')
Rule: OR('<%= primaryOrg.mspName %>.member')
Writers:
Type: Signature
Rule: OR('Org1MSP.member')
Rule: OR('<%= primaryOrg.mspName %>.member')
Endorsement:
Type: Signature
Rule: OR('Org1MSP.member')
Rule: OR('<%= primaryOrg.mspName %>.member')
Admins:
Type: Signature
Rule: OR('Org1MSP.admin')
Rule: OR('<%= primaryOrg.mspName %>.admin')
AnchorPeers:


Expand Down Expand Up @@ -75,7 +75,7 @@ Application: &ApplicationDefaults
event/FilteredBlock: /Channel/Application/Readers
Organizations:

- *Org1MSP
- *<%= primaryOrg.mspName %>

Policies:
Readers:
Expand All @@ -92,7 +92,7 @@ Application: &ApplicationDefaults
Rule: ANY Endorsement
LifecycleEndorsement:
Type: Signature
Rule: OR('Org1MSP.member')
Rule: OR('<%= primaryOrg.mspName %>.member')
Capabilities:
<<: *ApplicationCapabilities

Expand Down
14 changes: 7 additions & 7 deletions src/setup-docker/templates/fabric-x/crypto-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ OrdererOrgs:

PeerOrgs:

- Name: Org1
Domain: org1.example.com
- Name: <%= primaryOrg.name %>
Domain: <%= primaryOrg.domain %>
EnableNodeOUs: false
CA:
hostname: ca
Expand All @@ -67,39 +67,39 @@ PeerOrgs:
Specs:
- Hostname: committer-sidecar
SANS:
- committer-org1-sidecar
- committer-<%= primaryOrgSlug %>-sidecar
- host.docker.internal
- 0.0.0.0
- localhost
- 127.0.0.1
- ::1
- Hostname: committer-coordinator
SANS:
- committer-org1-coordinator
- committer-<%= primaryOrgSlug %>-coordinator
- host.docker.internal
- 0.0.0.0
- localhost
- 127.0.0.1
- ::1
- Hostname: committer-validator
SANS:
- committer-org1-validator
- committer-<%= primaryOrgSlug %>-validator
- host.docker.internal
- 0.0.0.0
- localhost
- 127.0.0.1
- ::1
- Hostname: committer-verifier
SANS:
- committer-org1-verifier
- committer-<%= primaryOrgSlug %>-verifier
- host.docker.internal
- 0.0.0.0
- localhost
- 127.0.0.1
- ::1
- Hostname: committer-query-service
SANS:
- committer-org1-query-service
- committer-<%= primaryOrgSlug %>-query-service
- host.docker.internal
- 0.0.0.0
- localhost
Expand Down
Loading
Loading