Skip to content

Commit

Permalink
refactor(connector-fabric): deployContractGoSourceV1 uses Fabric v2.5.6
Browse files Browse the repository at this point in the history
The deployContractGoSourceV1() method now assumes that the underlying
test ledger is Fabric 2.5 (current LTS).

This will allow us to upgrade the contracts that are being used by the
Supply chain app to Fabric 2.x from Fabric 1.x which will then implicitly
fix a large number of other issues at the same time.

This change is part of laying the foundation for that follow-up work.

Primary changes:
-----------------

1. Added a new, standalone utility function to deploy go source contracts
with the name of `deployContractGoSourceImplFabricV256()`.
2. The code of this function was derived from the original Fabric v1
compatible deployContractGoSourceV1 method of the Fabric connector.
3. 2 organizations are supported for deployment via the endpoint.
4. The endpoint is only used by the supply chain app example at the moment
and there is no test coverage of it due to dependencies that will be
resolved in a follow-up pull request that is coming soon.

Secondary changes:
1. Also extracted the SSH execution function from the fabric connector
into a standalone function that can be used without having to have a
Fabric connector instance created first.
2. Also extracted/abstracted some logic into a utility function for
similar reasons that is used to replace logging configuration environment
variables in shell commands that we use to perform contract deployment
onto the Fabric test ledgers.

Depends on #3054

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Mar 7, 2024
1 parent 1dfcf17 commit ffbcf31
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Checks } from "@hyperledger/cactus-common";

const PATTERN_FABRIC_CORE_LOGGING_LEVEL = new RegExp(
`\\s+(-e|--env)\\s+CORE_LOGGING_LEVEL='?"?\\w+'?"?\\s+`,
"gmi",
);

const PATTERN_FABRIC_LOGGING_SPEC = new RegExp(
`FABRIC_LOGGING_SPEC=('?"?\\w+'?"?)`,
"gmi",
);

export function findAndReplaceFabricLoggingSpec(
input: string,
newLogLevel: string,
): string {
Checks.nonBlankString(input, `findAndReplaceFabricLoggingSpec() arg1`);
Checks.nonBlankString(newLogLevel, `findAndReplaceFabricLoggingSpec() arg2`);
return input
.replace(PATTERN_FABRIC_CORE_LOGGING_LEVEL, " ")
.replace(
PATTERN_FABRIC_LOGGING_SPEC,
" FABRIC_LOGGING_SPEC= ".concat(newLogLevel),
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
NodeSSH,
SSHExecCommandOptions,
SSHExecCommandResponse,
} from "node-ssh";
import { RuntimeError } from "run-time-error-cjs";

import { Logger } from "@hyperledger/cactus-common";

import { isSshExecOk } from "./is-ssh-exec-ok";

export async function sshExec(
ctx: { readonly log: Logger },
cmd: string,
label: string,
ssh: NodeSSH,
sshCmdOptions: SSHExecCommandOptions,
): Promise<SSHExecCommandResponse> {
ctx.log.debug(`${label} CMD: ${cmd}`);
const cmdRes = await ssh.execCommand(cmd, sshCmdOptions);
ctx.log.debug(`${label} CMD Response .code: %o`, cmdRes.code);
ctx.log.debug(`${label} CMD Response .signal: %o`, cmdRes.signal);
ctx.log.debug(`${label} CMD Response .stderr: %s`, cmdRes.stderr);
ctx.log.debug(`${label} CMD Response .stdout: %s`, cmdRes.stdout);

if (!isSshExecOk(cmdRes)) {
throw new RuntimeError(`Expected ${label} cmdRes.code as null or 0`);
}
return cmdRes;
}
Loading

0 comments on commit ffbcf31

Please sign in to comment.