Skip to content

Commit

Permalink
feat: setup client VPC and associated endpoint for accessing the network
Browse files Browse the repository at this point in the history
  • Loading branch information
vponselvan committed Feb 12, 2022
1 parent f66ac4f commit 16efcc9
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 1 deletion.
148 changes: 148 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,93 @@

## Constructs <a name="Constructs" id="constructs"></a>

### HyperledgerFabricClient <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient" id="cdkhyperledgerfabricnetworkhyperledgerfabricclient"></a>

Creates a VPC and endpoint that allows Hyperledger Fabric client to interact with the Hyperledger Fabric endpoints that Amazon Managed Blockchain exposes for the member and network resources.

#### Initializers <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.Initializer" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientinitializer"></a>

```typescript
import { HyperledgerFabricClient } from 'cdk-hyperledger-fabric-network'

new HyperledgerFabricClient(scope: HyperledgerFabricNetwork, id: string, props?: HyperledgerFabricClientProps)
```

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| [`scope`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterscope)<span title="Required">*</span> | [`cdk-hyperledger-fabric-network.HyperledgerFabricNetwork`](#cdk-hyperledger-fabric-network.HyperledgerFabricNetwork) | *No description.* |
| [`id`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterid)<span title="Required">*</span> | `string` | *No description.* |
| [`props`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterprops) | [`cdk-hyperledger-fabric-network.HyperledgerFabricClientProps`](#cdk-hyperledger-fabric-network.HyperledgerFabricClientProps) | *No description.* |

---

##### `scope`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.parameter.scope" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterscope"></a>

- *Type:* [`cdk-hyperledger-fabric-network.HyperledgerFabricNetwork`](#cdk-hyperledger-fabric-network.HyperledgerFabricNetwork)

---

##### `id`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.parameter.id" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterid"></a>

- *Type:* `string`

---

##### `props`<sup>Optional</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.parameter.props" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientparameterprops"></a>

- *Type:* [`cdk-hyperledger-fabric-network.HyperledgerFabricClientProps`](#cdk-hyperledger-fabric-network.HyperledgerFabricClientProps)

---



#### Properties <a name="Properties" id="properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| [`secretsManagerVpcEndpoint`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertysecretsmanagervpcendpoint)<span title="Required">*</span> | [`aws-cdk-lib.aws_ec2.VpcEndpoint`](#aws-cdk-lib.aws_ec2.VpcEndpoint) | VPC endpoint to access Secret Manager. |
| [`vpc`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertyvpc)<span title="Required">*</span> | [`aws-cdk-lib.aws_ec2.IVpc`](#aws-cdk-lib.aws_ec2.IVpc) | The client VPC that has endpoint to access the Amazon Managed Blockchain. |
| [`vpcEndpoint`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertyvpcendpoint)<span title="Required">*</span> | [`aws-cdk-lib.aws_ec2.VpcEndpoint`](#aws-cdk-lib.aws_ec2.VpcEndpoint) | Managed Blockchain network VPC endpoint. |

---

##### `secretsManagerVpcEndpoint`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.property.secretsManagerVpcEndpoint" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertysecretsmanagervpcendpoint"></a>

```typescript
public readonly secretsManagerVpcEndpoint: VpcEndpoint;
```

- *Type:* [`aws-cdk-lib.aws_ec2.VpcEndpoint`](#aws-cdk-lib.aws_ec2.VpcEndpoint)

VPC endpoint to access Secret Manager.

---

##### `vpc`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.property.vpc" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertyvpc"></a>

```typescript
public readonly vpc: IVpc;
```

- *Type:* [`aws-cdk-lib.aws_ec2.IVpc`](#aws-cdk-lib.aws_ec2.IVpc)

The client VPC that has endpoint to access the Amazon Managed Blockchain.

---

##### `vpcEndpoint`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClient.property.vpcEndpoint" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientpropertyvpcendpoint"></a>

```typescript
public readonly vpcEndpoint: VpcEndpoint;
```

- *Type:* [`aws-cdk-lib.aws_ec2.VpcEndpoint`](#aws-cdk-lib.aws_ec2.VpcEndpoint)

Managed Blockchain network VPC endpoint.

---


### HyperledgerFabricNetwork <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetwork" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetwork"></a>

Creates a Hyperledger Fabric network on Amazon Managed Blockchain.
Expand Down Expand Up @@ -50,6 +137,7 @@ new HyperledgerFabricNetwork(scope: Construct, id: string, props: HyperledgerFab
| [`adminPrivateKeySecret`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyadminprivatekeysecret)<span title="Required">*</span> | [`aws-cdk-lib.aws_secretsmanager.Secret`](#aws-cdk-lib.aws_secretsmanager.Secret) | Secret for Hyperledger Fabric admin private key. |
| [`adminSignedCertSecret`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyadminsignedcertsecret)<span title="Required">*</span> | [`aws-cdk-lib.aws_secretsmanager.Secret`](#aws-cdk-lib.aws_secretsmanager.Secret) | Secret for Hyperledger Fabric admin signed certificate. |
| [`caEndpoint`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertycaendpoint)<span title="Required">*</span> | `string` | Managed Blockchain member CA endpoint. |
| [`client`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyclient)<span title="Required">*</span> | [`cdk-hyperledger-fabric-network.HyperledgerFabricClient`](#cdk-hyperledger-fabric-network.HyperledgerFabricClient) | The client network to interact with the Hyperledger Fabric network. |
| [`enableCaLogging`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyenablecalogging)<span title="Required">*</span> | `boolean` | The configuration to enable or disable certificate authority logging. |
| [`frameworkVersion`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyframeworkversion)<span title="Required">*</span> | [`cdk-hyperledger-fabric-network.FrameworkVersion`](#cdk-hyperledger-fabric-network.FrameworkVersion) | Hyperledger Fabric framework version. |
| [`memberDescription`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertymemberdescription)<span title="Required">*</span> | `string` | Managed Blockchain member description. |
Expand Down Expand Up @@ -116,6 +204,18 @@ Managed Blockchain member CA endpoint.

---

##### `client`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetwork.property.client" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyclient"></a>

```typescript
public readonly client: HyperledgerFabricClient;
```

- *Type:* [`cdk-hyperledger-fabric-network.HyperledgerFabricClient`](#cdk-hyperledger-fabric-network.HyperledgerFabricClient)

The client network to interact with the Hyperledger Fabric network.

---

##### `enableCaLogging`<sup>Required</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetwork.property.enableCaLogging" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropertyenablecalogging"></a>

```typescript
Expand Down Expand Up @@ -519,6 +619,40 @@ public readonly eventEndpoint: string;

## Structs <a name="Structs" id="structs"></a>

### HyperledgerFabricClientProps <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClientProps" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientprops"></a>

Construct properties for `HyperledgerFabricVpc`.

#### Initializer <a name="[object Object].Initializer" id="object-objectinitializer"></a>

```typescript
import { HyperledgerFabricClientProps } from 'cdk-hyperledger-fabric-network'

const hyperledgerFabricClientProps: HyperledgerFabricClientProps = { ... }
```

#### Properties <a name="Properties" id="properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| [`vpc`](#cdkhyperledgerfabricnetworkhyperledgerfabricclientpropspropertyvpc) | [`aws-cdk-lib.aws_ec2.IVpc`](#aws-cdk-lib.aws_ec2.IVpc) | Client VPC to create the endpoints. |

---

##### `vpc`<sup>Optional</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricClientProps.property.vpc" id="cdkhyperledgerfabricnetworkhyperledgerfabricclientpropspropertyvpc"></a>

```typescript
public readonly vpc: IVpc;
```

- *Type:* [`aws-cdk-lib.aws_ec2.IVpc`](#aws-cdk-lib.aws_ec2.IVpc)

Client VPC to create the endpoints.

If not provided, VPC will be created with the default properties (CIDR-`10.0.0.0/16` and subnets of type `PRIVATE_ISOLATED`)

---

### HyperledgerFabricNetworkProps <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetworkProps" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetworkprops"></a>

Construct properties for `HyperledgerFabricNetwork`.
Expand All @@ -537,6 +671,7 @@ const hyperledgerFabricNetworkProps: HyperledgerFabricNetworkProps = { ... }
| --- | --- | --- |
| [`memberName`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertymembername)<span title="Required">*</span> | `string` | Managed Blockchain member name. |
| [`networkName`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertynetworkname)<span title="Required">*</span> | `string` | Managed Blockchain network name. |
| [`client`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertyclient) | [`cdk-hyperledger-fabric-network.HyperledgerFabricClientProps`](#cdk-hyperledger-fabric-network.HyperledgerFabricClientProps) | The Client network to interact with the Hyperledger Fabric network. |
| [`enableCaLogging`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertyenablecalogging) | `boolean` | The configuration to enable or disable certificate authority logging. |
| [`frameworkVersion`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertyframeworkversion) | [`cdk-hyperledger-fabric-network.FrameworkVersion`](#cdk-hyperledger-fabric-network.FrameworkVersion) | Hyperledger Fabric framework version. |
| [`memberDescription`](#cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertymemberdescription) | `string` | Managed Blockchain member description. |
Expand Down Expand Up @@ -573,6 +708,19 @@ Managed Blockchain network name.

---

##### `client`<sup>Optional</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetworkProps.property.client" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertyclient"></a>

```typescript
public readonly client: HyperledgerFabricClientProps;
```

- *Type:* [`cdk-hyperledger-fabric-network.HyperledgerFabricClientProps`](#cdk-hyperledger-fabric-network.HyperledgerFabricClientProps)
- *Default:* Client network with Default properties (CIDR-`10.0.0.0/16` and subnets of type `PRIVATE_ISOLATED`)

The Client network to interact with the Hyperledger Fabric network.

---

##### `enableCaLogging`<sup>Optional</sup> <a name="cdk-hyperledger-fabric-network.HyperledgerFabricNetworkProps.property.enableCaLogging" id="cdkhyperledgerfabricnetworkhyperledgerfabricnetworkpropspropertyenablecalogging"></a>

```typescript
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ is planned for future releases:
* Enroll users, storing their credentials in Secrets Manager
* Create channels on nodes
* Instantiate chaincode on nodes
* Set up a VPC and associated endpoint for accessing the network


## Installation
Expand Down
69 changes: 69 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as constructs from 'constructs';

import * as network from './network';

/**
* Construct properties for `HyperledgerFabricVpc`
*/
export interface HyperledgerFabricClientProps {
/**
* Client VPC to create the endpoints. If not provided,
* VPC will be created with the default properties
* (CIDR-`10.0.0.0/16` and subnets of type `PRIVATE_ISOLATED`)
*
*/
readonly vpc?: ec2.IVpc;

}

/**
* Creates a VPC and endpoint that allows Hyperledger Fabric client to
* interact with the Hyperledger Fabric endpoints that Amazon Managed Blockchain
* exposes for the member and network resources.
*/
export class HyperledgerFabricClient extends constructs.Construct {

/**
* The client VPC that has endpoint to access the Amazon Managed Blockchain
*/
public readonly vpc: ec2.IVpc;

/**
* VPC endpoint to access Secret Manager
*/
public readonly secretsManagerVpcEndpoint: ec2.VpcEndpoint;

/**
* Managed Blockchain network VPC endpoint
*/
public readonly vpcEndpoint: ec2.VpcEndpoint;

constructor(scope: network.HyperledgerFabricNetwork, id: string, props?: HyperledgerFabricClientProps) {
super(scope, id);

// Collect metadata on the stack
const region = cdk.Stack.of(this).region;

// Populate instance variables from input properties, using defaults if values not provided
if (typeof props === 'undefined') props = {};
this.vpc = props.vpc ?? new ec2.Vpc(this, 'ClientVpc', { subnetConfiguration: [{ name: 'Private', subnetType: ec2.SubnetType.PRIVATE_ISOLATED }] });
const vpcEndpointServiceName = scope.vpcEndpointServiceName.replace(`com.amazonaws.${region}.`, '');

// Add VPC FlowLogs with the default setting of trafficType:ALL and destination: CloudWatch Logs
this.vpc.addFlowLog('FlowLog');

// Add a VPC endpoint to access the Managed Blockchain
const vpcService = new ec2.InterfaceVpcEndpointService( vpcEndpointServiceName );
this.vpcEndpoint = this.vpc.addInterfaceEndpoint('LedgerEndpoint', { service: vpcService, open: false });

// Add VPC endpoint to access the Secrets Manager
this.secretsManagerVpcEndpoint = this.vpc.addInterfaceEndpoint('SecretsManagerEndpoint', { service: ec2.InterfaceVpcEndpointAwsService.SECRETS_MANAGER });

}

}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

export * from './network';
export * from './node';
export * from './client';

export { SUPPORTED_REGIONS, SUPPORTED_AVAILABILITY_ZONES } from './utilities';
16 changes: 16 additions & 0 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
import * as customresources from 'aws-cdk-lib/custom-resources';
import * as constructs from 'constructs';

import * as client from './client';
import * as node from './node';
import * as utilities from './utilities';

Expand Down Expand Up @@ -113,6 +114,13 @@ export interface HyperledgerFabricNetworkProps {
*/
readonly nodes?: Array<node.HyperledgerFabricNodeProps>;

/**
* The Client network to interact with the Hyperledger Fabric network
* @default - Client network with Default properties
* (CIDR-`10.0.0.0/16` and subnets of type `PRIVATE_ISOLATED`)
*/
readonly client?: client.HyperledgerFabricClientProps;

}


Expand Down Expand Up @@ -217,6 +225,11 @@ export class HyperledgerFabricNetwork extends constructs.Construct {
*/
public readonly nodes: Array<node.HyperledgerFabricNode>;

/**
* The client network to interact with the Hyperledger Fabric network
*/
public readonly client: client.HyperledgerFabricClient;


constructor(scope: constructs.Construct, id: string, props: HyperledgerFabricNetworkProps) {

Expand Down Expand Up @@ -390,6 +403,9 @@ export class HyperledgerFabricNetwork extends constructs.Construct {
n.fetchData(sdkCallPolicy);
}

// Build out the client VPC construct
this.client = new client.HyperledgerFabricClient(this, 'Client', props.client);

}

}
75 changes: 75 additions & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

import * as cdk from 'aws-cdk-lib';
import * as assertions from 'aws-cdk-lib/assertions';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

import * as hyperledger from '../src';


const DEFAULT_ENV = { env: { region: 'us-east-1' } };

const TOKEN_REGEXP = /^\$\{Token\[TOKEN\.[0-9]+\]\}$/;

describe('HyperledgerFabricClient', () => {

test('Create a client network with default properties', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'TestStack', DEFAULT_ENV);
const network = new hyperledger.HyperledgerFabricNetwork(stack, 'TestHyperledgerFabricNetwork', {
networkName: 'TestNetwork',
memberName: 'TestMember',
});

const template = assertions.Template.fromStack(stack);
template.resourceCountIs('AWS::EC2::VPC', 1);
template.hasResource('AWS::EC2::VPC', {
Properties: {
CidrBlock: '10.0.0.0/16',
EnableDnsHostnames: true,
EnableDnsSupport: true,
},
});
template.resourceCountIs('AWS::EC2::FlowLog', 1);
template.resourceCountIs('AWS::Logs::LogGroup', 1);
template.resourceCountIs('AWS::EC2::VPCEndpoint', 2);

expect(network.client.vpc.vpcId).toMatch(TOKEN_REGEXP);
expect(network.client.vpcEndpoint.vpcEndpointId).toMatch(TOKEN_REGEXP);
expect(network.client.secretsManagerVpcEndpoint.vpcEndpointId).toMatch(TOKEN_REGEXP);
});

test('Create endpoints on existing a client network ', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'TestStack', DEFAULT_ENV);
const vpc = new ec2.Vpc(stack, 'ClientVpc', {
cidr: '40.0.0.0/16',
subnetConfiguration: [{ name: 'Private', subnetType: ec2.SubnetType.PRIVATE_ISOLATED }],
});
const network = new hyperledger.HyperledgerFabricNetwork(stack, 'TestHyperledgerFabricNetwork', {
networkName: 'TestNetwork',
memberName: 'TestMember',
client: {
vpc: vpc,
},
});
const template = assertions.Template.fromStack(stack);
template.resourceCountIs('AWS::EC2::VPC', 1);
template.hasResource('AWS::EC2::VPC', {
Properties: {
CidrBlock: '40.0.0.0/16',
EnableDnsHostnames: true,
EnableDnsSupport: true,
},
});
template.resourceCountIs('AWS::EC2::FlowLog', 1);
template.resourceCountIs('AWS::Logs::LogGroup', 1);
template.resourceCountIs('AWS::EC2::VPCEndpoint', 2);

expect(network.client.vpc.vpcId).toMatch(TOKEN_REGEXP);
expect(network.client.vpcEndpoint.vpcEndpointId).toMatch(TOKEN_REGEXP);
expect(network.client.secretsManagerVpcEndpoint.vpcEndpointId).toMatch(TOKEN_REGEXP);
});

});

0 comments on commit 16efcc9

Please sign in to comment.