Skip to content

Commit

Permalink
fix: Refactor the configService property name from `providerBaseUrl…
Browse files Browse the repository at this point in the history
…` to `webhookBaseUrl`
  • Loading branch information
mattheworris committed Aug 8, 2024
1 parent 669e73a commit 859ab33
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 48 deletions.
6 changes: 2 additions & 4 deletions docker-compose-k6.account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ services:
account-service-webhook:
condition: service_healthy
environment:
PROVIDER_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service'
WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks'
WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service'

account-service-worker:
pull_policy: never
Expand All @@ -32,8 +31,7 @@ services:
- redis
- ipfs
environment:
PROVIDER_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service'
WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks'
WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service'

account-service-webhook:
image: rust:1.80.0
Expand Down
2 changes: 1 addition & 1 deletion services/account/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This application recognizes the following environment variables:
| `HEALTH_CHECK_SUCCESS_THRESHOLD` | Minimum number of consecutive successful calls to the provider webhook `/health` endpoint before it is marked up again | > 0 | | 10 |
| `PROVIDER_ACCESS_TOKEN` | An optional bearer token authentication to the provider webhook | string | | |
| `PROVIDER_ACCOUNT_SEED_PHRASE` | Seed phrase for provider MSA control key | string | Y | |
| `PROVIDER_BASE_URL` | Base URL for provider webhook endpoints | URL | Y | |
| `WEBHOOK_BASE_URL` | Base URL for provider webhook endpoints | URL | Y | |
| `PROVIDER_ID` | Provider MSA ID | integer | Y | |
| `REDIS_URL` | Connection URL for Redis | URL | Y | |
| `WEBHOOK_FAILURE_THRESHOLD` | Number of failures allowing in the provider webhook before the service is marked down | > 0 | | 3 |
Expand Down
16 changes: 3 additions & 13 deletions services/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,6 @@ In order to run this project you need:
- [Node.js](https://nodejs.org)
- [Docker](https://docs.docker.com/get-docker/)

### Setup

Clone this repository to your desired folder:

Example commands:

```sh
git clone [email protected]:ProjectLibertyLabs/account-service.git
cd account-service
```

### Environment Variables

Modify any environment variables in the `.env` file as needed. The complete set of environment variables is documented [here](./ENVIRONMENT.md), and a sample environment file is provided [here](./env.template).
Expand All @@ -209,6 +198,7 @@ Install NPM Dependencies:

```sh
npm install
npm install -g @nestjs/cli
```

### Usage
Expand Down Expand Up @@ -257,7 +247,7 @@ In order to run the `account-service` in development mode without containers, yo
Run the following command to start the account service api and worker containers. This will start the account service api and worker in development mode.

```sh
docker-compose up -d api worker
docker-compose up -d account-service-api account-service-worker
```

#### 4. Check the job in [BullUI](http://0.0.0.0:3000/queues/), to monitor job progress based on defined tests
Expand All @@ -276,7 +266,7 @@ In order to run the `account-service` in development mode without containers, yo

### Swagger UI

Check out the Swagger UI hosted on the app instance at [http://localhost:3000/api/docs/swagger](http://localhost:3000/api/docs/swagger) to view the API documentation and submit requests to the service.
Check out the Swagger UI hosted on the app instance at [http://localhost:3000/api/docs/swagger](http://localhost:3000/docs/swagger) to view the API documentation and submit requests to the service.

### Queue Management

Expand Down
2 changes: 1 addition & 1 deletion services/account/apps/api/src/build-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ process.env.FREQUENCY_HTTP_URL = 'http://127.0.0.1';
process.env.PROVIDER_ACCOUNT_SEED_PHRASE =
'offer debate skin describe light badge fish turtle actual inject struggle border';
process.env.PROVIDER_ID = '0';
process.env.PROVIDER_BASE_URL = 'http://127.0.0.1';
process.env.WEBHOOK_BASE_URL = 'http://127.0.0.1';
process.env.CAPACITY_LIMIT = '{"type":"amount","value":0}';

// eslint-disable-next-line
Expand Down
9 changes: 0 additions & 9 deletions services/account/apps/api/src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,4 @@ export class ApiService implements OnApplicationShutdown {
this.logger.error(`Error during cleanup on shutdown: ${e}`);
}
}

// async watchGraphs(watchGraphsDto: WatchGraphsDto): Promise<void> {
// watchGraphsDto.msaIds.forEach(async (msaId) => {
// const redisKey = `${QueueConstants.REDIS_WATCHER_PREFIX}:${msaId}`;
// const redisValue = watchGraphsDto.webhookEndpoint;
// // eslint-disable-next-line no-await-in-loop
// await this.redis.rpush(redisKey, redisValue);
// });
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,6 @@ export class TxnNotifierService
}

async getWebhook(): Promise<string> {
return this.configService.providerBaseUrl.toString();
return this.configService.webhookBaseUrl.toString();
}
}
12 changes: 7 additions & 5 deletions services/account/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ FREQUENCY_HTTP_URL=http://0.0.0.0:9944
PROVIDER_ID=1

# Base URL for provider webhook endpoints
#PROVIDER_BASE_URL=http://localhost:5555/api/v3
PROVIDER_BASE_URL=http://host.docker.internal:5555/api/v3/webhook
#WEBHOOK_BASE_URL=http://localhost:5555/api/v3
WEBHOOK_BASE_URL=http://host.docker.internal:5555/api/v3/webhook

# Redis URL
REDIS_URL=redis://0.0.0.0:6379
#REDIS_URL=redis://redis:6379 #docker dev

# How many seconds to delay between successive scans of the chain
# for new content (after end of chain is reached)
BLOCKCHAIN_SCAN_INTERVAL_SECONDS=12
BLOCKCHAIN_SCAN_INTERVAL_SECONDS=3

# Whether to examine blocks that have not been finalized when tracking extrinsic completion
TRUST_UNFINALIZED_BLOCKS=false
# Trusting unfinalized blocks is faster but in the unlikely event of a chain reorganization
# it may result in incorrect data. If set to false, the service will wait for blocks to be finalized
TRUST_UNFINALIZED_BLOCKS=true

# An optional bearer token authentication to the provider webhook
PROVIDER_ACCESS_TOKEN=some-token
Expand Down Expand Up @@ -59,7 +61,7 @@ HEALTH_CHECK_SUCCESS_THRESHOLD=10
CAPACITY_LIMIT='{"type":"percentage", "value":80}'

# URL for the Sign-In With Frequency UI
SIWF_URL=https://projectlibertylabs.github.io/siwf/ui
SIWF_URL=https://ProjectLibertyLabs.github.io/siwf/ui

# Domain for the Sign-in with Frequency login payload
SIWF_DOMAIN=localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('BlockchainService', () => {
const configService = {
logger: jest.fn(),
nestConfigService: jest.fn(),
providerBaseUrl: jest.fn(),
webhookBaseUrl: jest.fn(),
providerApiToken: jest.fn(),
getProviderId: jest.fn(),
getQueueHighWater: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('AccountSericeConfig', () => {
PROVIDER_ID: undefined,
SIWF_URL: undefined,
SIWF_DOMAIN: undefined,
PROVIDER_BASE_URL: undefined,
WEBHOOK_BASE_URL: undefined,
PROVIDER_ACCESS_TOKEN: undefined,
WEBHOOK_FAILURE_THRESHOLD: undefined,
HEALTH_CHECK_SUCCESS_THRESHOLD: undefined,
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('AccountSericeConfig', () => {
});

it('should get provider base url', () => {
expect(accountServiceConfig.providerBaseUrl?.toString()).toStrictEqual(ALL_ENV.PROVIDER_BASE_URL?.toString());
expect(accountServiceConfig.webhookBaseUrl?.toString()).toStrictEqual(ALL_ENV.WEBHOOK_BASE_URL?.toString());
});

it('should get provider api token', () => {
Expand Down
6 changes: 3 additions & 3 deletions services/account/libs/common/src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ConfigEnvironmentVariables {
PROVIDER_ID: string;
SIWF_URL: string;
SIWF_DOMAIN: string;
PROVIDER_BASE_URL: string;
WEBHOOK_BASE_URL: string;
PROVIDER_ACCESS_TOKEN: string;
WEBHOOK_FAILURE_THRESHOLD: number;
HEALTH_CHECK_SUCCESS_THRESHOLD: number;
Expand All @@ -40,8 +40,8 @@ export class ConfigService {
return this.nestConfigService.get<boolean>('TRUST_UNFINALIZED_BLOCKS') ?? false;
}

public get providerBaseUrl(): URL {
return this.nestConfigService.get<URL>('PROVIDER_BASE_URL')!;
public get webhookBaseUrl(): URL {
return this.nestConfigService.get<URL>('WEBHOOK_BASE_URL')!;
}

public get providerApiToken(): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion services/account/libs/common/src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const configModuleOptions: ConfigModuleOptions = {
}
return value;
}),
PROVIDER_BASE_URL: Joi.string().uri().required(),
WEBHOOK_BASE_URL: Joi.string().uri().required(),
PROVIDER_ACCESS_TOKEN: Joi.string().default(''),
WEBHOOK_FAILURE_THRESHOLD: Joi.number().min(1).default(3),
WEBHOOK_RETRY_INTERVAL_SECONDS: Joi.number().min(1).default(10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ProviderWebhookService implements OnModuleDestroy {
) {
this.logger = new Logger(this.constructor.name);
this.webhook = axios.create({
baseURL: this.configService.providerBaseUrl.toString(),
baseURL: this.configService.webhookBaseUrl.toString(),
});

this.webhook.defaults.headers.common.Authorization = this.configService.providerApiToken;
Expand All @@ -61,7 +61,7 @@ export class ProviderWebhookService implements OnModuleDestroy {
if (this.failedHealthChecks > 0) {
if (this.failedHealthChecks >= this.configService.healthCheckMaxRetries) {
this.logger.error(
`FATAL ERROR: Failed to connect to provider webhook at '${this.configService.providerBaseUrl}' after ${this.failedHealthChecks} attempts.`,
`FATAL ERROR: Failed to connect to provider webhook at '${this.configService.webhookBaseUrl}' after ${this.failedHealthChecks} attempts.`,
);
this.eventEmitter.emit('shutdown');
return;
Expand Down
7 changes: 4 additions & 3 deletions services/account/scripts/docker-clean-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# Stop and remove containers, networks
echo "Stopping and removing containers, networks..."
docker compose down
docker compose down frequency redis account-service-api account-service-worker

# Remove specified volumes
echo "Removing specified volumes..."
docker volume rm account-service_redis_data
docker volume rm account-service_chainstorage
docker volume rm gateway_redis_data
docker volume rm gateway_chainstorage
docker volume rm gateway_account_node_cache

# Remove account-service images
echo "Removing account-service image..."
Expand Down
4 changes: 2 additions & 2 deletions services/account/scripts/restart-chain-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ echo "Running make setup to provision Provider with capacity, etc..."
make setup

# Start all services in detached mode
echo "Starting all services..."
docker compose up -d
echo "Starting account-service, api and worker apps..."
docker compose up -d account-service-api account-service-worker

# Start the mock web server
echo "Please run 'make mock-webhook' in a separate terminal..."
Expand Down

0 comments on commit 859ab33

Please sign in to comment.