-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fabric): serialization of ccp and sshconfig #3578
base: main
Are you sure you want to change the base?
feat(fabric): serialization of ccp and sshconfig #3578
Conversation
f3c02d4
to
a346e83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left two open questions, please have a look :)
connectionProfile?: ConnectionProfile; | ||
connectionProfileBase64Encoded?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we accept connectionProfile
as discriminated union? Something like: {type: "base64", profile: "XXX"}
. I was thinking about adding a method for returning connection profile from a connector (as part of #3554) and this common union type could be used as a return value as well. Also, it will be more extensible if we decide to support more connection profile formats in the future (no need to bloat the options with more optional options). And finally this will simplify checking if connection profile was provided after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@outSH an interesting suggestion in my opinion! If we see the functionality of returning connection profile from the connector itself, in a production grade fabric-network, then I think it will be very hard to create a connection profile as, creation of connection profile will make our connector tightly coupled with the infrastructure where HL Fabric is deployed. This is because, the main problem in publishing such network level configuration always end up in the question of "who will be providing
what part of the information
" and it then messes up with the overall governance.
Maybe we can instead request that information from the underlying ledger itself as a pre-requisite (in our case, straightaway fetch from the AIO itself without having another function for the same in our connector and we do have that function in the test tooling class for fabric aio).
My only point here being, whenever there is a requirement which deals with the entire ledger level information such as who provides what part of that info
, which channel is used to provide that info
and where is such an info stored
like questions, it becomes very challenging to deal with. So integrating such functionality with our connector will pose future challenges to decouple it again.
This is just my point of view, what do you suggest @petermetz @outSH ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For return method: I was thinking about maintaning same format for clarity (even if it's fetched from current ledger state), but now that you've mentioned it, that would be very wastefull way because most information contained in a connection profile are useless from network topology point of view, so I think I'll use different output :)
Nevertheless I think the following still applies:
Also, it will be more extensible if we decide to support more connection profile formats in the future (no need to bloat the options with more optional options). And finally this will simplify checking if connection profile was provided after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ Agreed as well. @jagpreetsinghsasan @outSH
...src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1-serialized.test.ts
Outdated
Show resolved
Hide resolved
a346e83
to
4eec642
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with comments
@@ -219,6 +221,8 @@ export class PluginLedgerConnectorFabric | |||
private readonly peerBinary: string; | |||
private readonly goBinary: string; | |||
private readonly cliContainerGoPath: string; | |||
private readonly sshConfig!: SshConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jagpreetsinghsasan Is there anything preventing us from definitively assigning these fields in the constructor so that we don't need the !
syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I declared that this field cannot be null via !
syntax, then assigned this field in the constuctor from the 2 possible options, either from the usual sshConfig
or from the base64 encoded version of it and finally controlled the flow using Checks.truthy(this.sshConfig != null,
${fnTag}:sshConfig);
I did it in this way as the other way would be to declare the var without !
and then do some workaround to address the issue of variable is used before assigning
In short, leveraged the use of Checks.truthy( )
alongwith var!
to have precise declaration.
Please let me know if this has some flaws/vulnerability or there exists a better way to do the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jagpreetsinghsasan The if conditions can be refactored this way and then the compiler no longer has an issue with us dropping the !
(which should only be used if there is no way to avoid it due it turning off a safety feature of the compiler):
if (this.opts.sshConfig) {
this.sshConfig = this.opts.sshConfig;
} else if (this.opts.sshConfigB64) {
const sshConfigBuffer = Buffer.from(this.opts.sshConfigB64, "base64");
const sshConfigString = sshConfigBuffer.toString("utf-8");
this.sshConfig = JSON.parse(sshConfigString);
} else {
throw new Error("Cannot instantiate Fabric connector without SSH config");
}
I'm guessing the other class member could be refactored the same way so that it does not need the !
.../cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts
Outdated
Show resolved
Hide resolved
connectionProfile?: ConnectionProfile; | ||
connectionProfileBase64Encoded?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ Agreed as well. @jagpreetsinghsasan @outSH
...tor-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts
Outdated
Show resolved
Hide resolved
...tor-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts
Outdated
Show resolved
Hide resolved
4eec642
to
816d14f
Compare
816d14f
to
f6779c6
Compare
@@ -219,6 +221,8 @@ export class PluginLedgerConnectorFabric | |||
private readonly peerBinary: string; | |||
private readonly goBinary: string; | |||
private readonly cliContainerGoPath: string; | |||
private readonly sshConfig!: SshConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jagpreetsinghsasan The if conditions can be refactored this way and then the compiler no longer has an issue with us dropping the !
(which should only be used if there is no way to avoid it due it turning off a safety feature of the compiler):
if (this.opts.sshConfig) {
this.sshConfig = this.opts.sshConfig;
} else if (this.opts.sshConfigB64) {
const sshConfigBuffer = Buffer.from(this.opts.sshConfigB64, "base64");
const sshConfigString = sshConfigBuffer.toString("utf-8");
this.sshConfig = JSON.parse(sshConfigString);
} else {
throw new Error("Cannot instantiate Fabric connector without SSH config");
}
I'm guessing the other class member could be refactored the same way so that it does not need the !
Primary Changes --------------- 1. sshConfig and connectionProfile can now be passed as base64 encoded strings Changes required to incorporate 1) --------------------------------- 2. Added sshConfigBase64Encoded and connectionProfileBase64encoded properties to IPluginLedgerConnectorFabricOptions 3. Added necessary FabricConnector class variables 4. Added a new testcase to demonstrate the same 5. Updated an implementation which fetches sshConfig from class variable Fixes hyperledger-cacti#3577 Signed-off-by: jagpreetsinghsasan <jagpreetsinghsasan@accenture.com>
f6779c6
to
21f4394
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for the updates!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jagpreetsinghsasan We are almost there! Please fix the tests that started failing. I saw this in the logs:
AIL packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts (177.176 s, 1102 MB heap size)
● runs tx on a Fabric v2.5.6 ledger › runs tx on a Fabric v2.5.6 ledger
Cannot instantiate Fabric connector without connection profile.
292 | this.connectionProfile = JSON.parse(connectionProfileString);
293 | } else {
> 294 | throw new Error(
| ^
295 | "Cannot instantiate Fabric connector without connection profile.",
296 | );
297 | }
at new PluginLedgerConnectorFabric (packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts:294:13)
at Object.<anonymous> (packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts:158:20)
Commit to be reviewed
feat(fabric): serialization of ccp and sshconfig
Fixes #3577
Pull Request Requirements
upstream/main
branch and squashed into single commit to help maintainers review it more efficient and to avoid spaghetti git commit graphs that obfuscate which commit did exactly what change, when and, why.-s
flag when usinggit commit
command. You may refer to this link for more information.Character Limit
A Must Read for Beginners
For rebasing and squashing, here's a must read guide for beginners.