Skip to content

Commit

Permalink
account-service should replace PROVIDER_BASE_URL with WEBHOOK_BASE_URL (
Browse files Browse the repository at this point in the history
#350)

## Description
The gateway microservices that use webhooks previously used the
environment variable `PROVIDER_BASE_URL` as the webhook target server.
The `social-app-template` has adopted a new nomenclature using
`WEBHOOK_BASE_URL`. All micro services should be in sync with the
`social-app-template` and use the new nomenclature.

## Acceptance Criteria

- All microservices that use webhooks use `WEBHOOK_BASE_URL` to
provision their webhook.
  - [x] account

Follow up to remove entirely:
#339
  • Loading branch information
mattheworris authored Aug 9, 2024
1 parent f40e6eb commit b5e7fee
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 89 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
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ x-common-environment: &common-environment
REDIS_URL: 'redis://redis:6379'
PROVIDER_ID: ${PROVIDER_ID:-1}
PROVIDER_ACCOUNT_SEED_PHRASE: ${PROVIDER_ACCOUNT_SEED_PHRASE:-//Alice}
WEBHOOK_BASE_URL: 'http://social-app-template-backend:3001/webhooks'
WEBHOOK_FAILURE_THRESHOLD: 3
WEBHOOK_RETRY_INTERVAL_SECONDS: 10
HEALTH_CHECK_MAX_RETRIES: 4
Expand Down Expand Up @@ -43,7 +42,7 @@ x-graph-service-env: &graph-service-env
x-account-service-env: &account-service-env
BLOCKCHAIN_SCAN_INTERVAL_SECONDS: 1
TRUST_UNFINALIZED_BLOCKS: true
PROVIDER_BASE_URL: 'http://social-app-template-backend:3001/webhooks/account-service'
WEBHOOK_BASE_URL: 'http://social-app-template-backend:3001/webhooks/account-service'

services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion services/account/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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
32 changes: 10 additions & 22 deletions services/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

# 📗 Table of Contents

- [📖 About the Project](#-account-service-a-nameabout-projecta)
- [📖 About the Project](#account-service)
- [🔍 Arch Map](#-arch-maps)
- [🛠 Built With](#-built-with-a-namebuilt-witha)
- [Tech Stack](#tech-stack-a-nametech-stacka)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [🚀 Live OpenAPI Docs](#-live-docs)
- [💻 Getting Started](#-getting-started)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Environment Variables](#environment-variables)
- [Install](#install)
- [Usage](#usage)
Expand All @@ -24,7 +23,7 @@
- [Debugging](#debugging)
- [Debugging with VSCode](#using-the-debugger-with-vscode)
- [🤝 Contributing](#-contributing)
- [⭐️ Show your support](#-show-your-support)
- [⭐️ Show your support](#show-your-support)
- [❓FAQ](#faq)
- [📝 License](#-license)

Expand Down Expand Up @@ -180,26 +179,15 @@ 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).

1. Copy the template values into the .env files.

```sh
```sh
cp env.template .env
```
```

2. Replace template values with values appropriate to your environment.

Expand Down Expand Up @@ -257,12 +245,12 @@ 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

## 📋 Testing
## 📋 Testing <a name="testing"></a>

### Run the tests

Expand All @@ -276,7 +264,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 Expand Up @@ -339,7 +327,7 @@ Contributions, issues, and feature requests are welcome!

<!-- SUPPORT -->

## ⭐️ Show your support
## ⭐️ Show your support <a name="show-your-support"></a>

If you would like to explore contributing bug fixes or enhancements, issues with the label `good-first-issue` can be a good place to start.

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);
// });
// }
}
49 changes: 25 additions & 24 deletions services/account/apps/api/test/setup/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/account/apps/api/test/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "UNLICENSED",
"dependencies": {
"@projectlibertylabs/frequency-scenario-template": "^1.1.5",
"@projectlibertylabs/frequency-scenario-template": "1.1.6",
"@dsnp/frequency-schemas": "^1.1.0",
"@frequency-chain/api-augment": "~1.11.1",
"@polkadot/api": "^10.13.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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:3001/webhooks/account-service

# 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='{"serviceLimit":{"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 @@ -19,7 +19,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 @@ -42,7 +42,7 @@ describe('AccountServiceConfig', () => {
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 @@ -183,7 +183,7 @@ describe('AccountServiceConfig', () => {
});

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 Down Expand Up @@ -59,8 +59,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 @@ -48,7 +48,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
9 changes: 5 additions & 4 deletions services/account/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"time-constants": "^1.0.3"
},
"devDependencies": {
"@projectlibertylabs/frequency-scenario-template": "^1.1.5",
"@projectlibertylabs/frequency-scenario-template": "^1.1.6",
"@projectlibertylabs/prettier-config": "file:../../packages/prettier-config",
"@projectlibertylabs/ts-config": "file:../../packages/ts-config",
"@types/jest": "^29.5.12",
Expand Down
Loading

0 comments on commit b5e7fee

Please sign in to comment.