Skip to content

Commit

Permalink
feat(satp-hermes): docker and gateway runner for SATP
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Mateus <[email protected]>

refactor(satp-hermes): gateway container image definition with bundler

Signed-off-by: Peter Somogyvari <[email protected]>

refactor(satp-hermes): merge policies type guard example

Signed-off-by: Peter Somogyvari <[email protected]>

refactor(satp-hermes): type guards for SATP env variables

Signed-off-by: Bruno Mateus <[email protected]>

squash! - peter's fixes for besu connectivity use LAN IP

Instead of hardcoded localhost use the LAN IP of machine so that the
gateway container can access it too.

Why though? Because if you tell the gateway container that it should
access the besu ledger via localhost then it will try to do that through
the container's own localhost, which is different from the host machine's
localhost (where the besu ledger is actually running).

Using the actual IP address of the host machine's primary network interface
resolves the ambiguity between the two differnet localhosts.

Signed-off-by: Peter Somogyvari <[email protected]>

Co-authored-by: Peter Somogyvari <[email protected]>
  • Loading branch information
brunoffmateus and petermetz committed Nov 6, 2024
1 parent 9f1b080 commit 5a6ccc0
Show file tree
Hide file tree
Showing 56 changed files with 5,136 additions and 401 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ httpModule
if (exitCode === 0) {
console.log("%s Healthcheck OK: ", url, statusCode, statusMessage);
} else {
console.error("%s Healthcheck FAIL: ", url, statusCode, statusMessage);
console.error("%s Healthcheck FAIL_1: ", url, statusCode, statusMessage);
}
process.exit(exitCode);
})
.on("error", (ex) => {
console.error("%s Healthcheck FAIL: ", url, ex);
console.error("%s Healthcheck FAIL_2: ", url, ex);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api";
import { PluginFactoryBungeeHermes } from "./plugin-factory-bungee-hermes";

export { isMergePolicyValueArray } from "./view-merging/merge-policies";
export { isPrivacyPolicyValueArray } from "./view-creation/privacy-policies";

export {
PluginBungeeHermes,
IPluginBungeeHermesOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ export interface IPrivacyPolicyValue {
policy: PrivacyPolicyOpts;
policyHash: string;
}

// Type guard for PrivacyPolicyOpts
export function isPrivacyPolicyOpts(
value: unknown,
): value is PrivacyPolicyOpts {
return (
typeof value === "string" &&
Object.values(PrivacyPolicyOpts).includes(value as PrivacyPolicyOpts)
);
}

// Type guard for IPrivacyPolicyValue
export function isPrivacyPolicyValue(obj: unknown): obj is IPrivacyPolicyValue {
return (
typeof obj === "object" &&
obj !== null &&
"policy" in obj && // Ensure 'policy' key exists
isPrivacyPolicyOpts((obj as Record<string, unknown>).policy) && // Check if policy is a valid PrivacyPolicyOpts value
typeof (obj as Record<string, unknown>).policyHash === "string" // Ensure 'policyHash' is a string
);
}

// Type guard for an array of IPrivacyPolicyValue
export function isPrivacyPolicyValueArray(
input: unknown,
): input is Array<IPrivacyPolicyValue> {
return Array.isArray(input) && input.every(isPrivacyPolicyValue);
}

export class PrivacyPolicies {
constructor() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ export interface IMergePolicyValue {
policy: MergePolicyOpts;
policyHash?: string; //undefined if policy is NONE
}

// Type guard for MergePolicyOpts
export function isMergePolicyOpts(value: unknown): value is MergePolicyOpts {
return (
typeof value === "string" &&
Object.values(MergePolicyOpts).includes(value as MergePolicyOpts)
);
}

// Type guard for IMergePolicyValue
export function isMergePolicyValue(obj: unknown): obj is IMergePolicyValue {
return (
typeof obj === "object" &&
obj !== null &&
"policy" in obj && // Ensure 'policy' key exists
isMergePolicyOpts((obj as Record<string, unknown>).policy) && // Check if policy is a valid MergePolicyOpts value
(typeof (obj as Record<string, unknown>).policyHash === "string" ||
typeof (obj as Record<string, unknown>).policyHash === "undefined") // Ensure 'policyHash' is either a string or undefined
);
}

// Type guard for an array of IMergePolicyValue
export function isMergePolicyValueArray(
input: unknown,
): input is IMergePolicyValue[] {
return Array.isArray(input) && input.every(isMergePolicyValue);
}

export class MergePolicies {
constructor() {}

Expand Down
2 changes: 2 additions & 0 deletions packages/cactus-plugin-satp-hermes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
src/main/typescript/fabric-contracts/satp/chaincode-typescript/.yarn/
src/main/typescript/.env
packages/cactus-plugin-satp-hermes/cache/solidity-files-cache.json
src/keys/
src/test/typescript/integration/gateway-info
44 changes: 44 additions & 0 deletions packages/cactus-plugin-satp-hermes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,50 @@ const serverGatewayOptions: IBesuSATPGatewayConstructorOptions = {

Note that these gateways are extensions of the [default SATP Gateway class](https://github.com/hyperledger/cactus/blob/main/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway/plugin-satp-gateway.ts), that implements the gateway functionality. Each of these extensions implements ledger-specific operations.

## Containerization

### Building the container image locally

In the project root directory run these commands on the terminal:

```sh
yarn configure
yarn lerna run build:bundle --scope=@hyperledger/cactus-plugin-satp-hermes
```

Build the image:

```sh
docker build \
--file ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile \
./packages/cactus-plugin-satp-hermes/ \
--tag shg \
--tag satp-hermes-gateway \
--tag ghcr.io/hyperledger/cacti-satp-hermes-gateway:$(date +"%Y-%m-%dT%H-%M-%S" --utc)-dev-$(git rev-parse --short HEAD)
```

Run the image:

```sh
docker run \
-it \
satp-hermes-gateway
```

Alternatively you can use `docker compose up --build` from within the package directory or if you
prefer to run it from the project root directory then:

```sh
docker compose \
--project-directory ./packages/cactus-plugin-satp-hermes/ \
-f ./packages/cactus-plugin-satp-hermes/docker-compose.yml \
up \
--build
```


> The `--build` flag is going to save you 99% of the time from docker compose caching your image builds against your will or knowledge during development.
## Contributing
We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!

Expand Down
Loading

0 comments on commit 5a6ccc0

Please sign in to comment.