Skip to content
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

chore: rework config keys, remove template leftovers #1

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"watch": ["src"],
"ext": "ts",
"exec": "node --inspect -r ts-node/register ./src/server.ts"
}
}
17 changes: 0 additions & 17 deletions readme-typescript-nodejs.md

This file was deleted.

8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ Note: the ad normalizer assumes that your packager is set up with the output sub
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `ENCORE_URL` | The URL of your encore instance | none |
| `CALLBACK_LISTENER_URL` | The URL of your callback listener | none |
| `MINIO_URL` | The minio instance endpoint | none |
| `MINIO_ACCESS_KEY` | Your minio access key | none |
| `MINIO_SECRET_KEY` | Your minio secret key | none |
| `S3_ENDPOINT` | The S3 instance endpoint endpoint | none |
| `S3_ACCESS_KEY` | Your S3 access key | none |
| `S3_SECRET_KEY` | Your S3 secret key | none |
| `LOG_LEVEL` | The log level of the service | Info |
| `REDIS_URL` | The url of your redis instance | none |
| `AD_SERVER_URL` | The url of your ad server | none |
| `PORT` | The port that the server listens on | 8000 |
| `MINIO_BUCKET` | The bucket that the packaged assets will be placed into | none |
| `OUTPUT_BUCKET_URL` | The url to the output folder for the packaged assets | none |
| `SERVICE_ACCESS_TOKEN` | your OSC service access token for encore (only needed when running the service outside OSC with an encore instance in OSC) | none |

### starting the service
Expand Down
14 changes: 7 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EncoreClient } from './encore/encoreclient';
import { MinioClient, MinioNotification } from './minio/minio';

const HelloWorld = Type.String({
description: 'The magical words!'
status: 'HEALTHY'
});

export interface HealthcheckOptions {
Expand All @@ -29,7 +29,7 @@ const healthcheck: FastifyPluginCallback<HealthcheckOptions> = (
'/',
{
schema: {
description: 'Say hello',
description: 'Health check',
response: {
200: HelloWorld
}
Expand Down Expand Up @@ -76,9 +76,9 @@ export default (opts: ApiOptions) => {
);

const minioClient = new MinioClient(
config.minioUrl,
config.minioAccessKey,
config.minioSecretKey
config.s3Endpoint,
config.s3AccessKey,
config.s3SecretKey
);

minioClient.setupClient();
Expand Down Expand Up @@ -109,14 +109,14 @@ export default (opts: ApiOptions) => {

api.register(vastApi, {
adServerUrl: config.adServerUrl,
assetServerUrl: `https://${config.minioUrl}/${config.minioBucket}/`,
assetServerUrl: `https://${config.s3Endpoint}/${config.bucket}/`,
lookUpAsset: async (mediaFile: string) => redisclient.get(mediaFile),
onMissingAsset: async (asset: ManifestAsset) =>
encoreClient.createEncoreJob(asset),
setupNotification: (asset: ManifestAsset) => {
logger.debug('Setting up notification for asset', { asset });
minioClient.listenForNotifications(
config.minioBucket,
config.bucket,
asset.creativeId + '/', // TODO: Pass encore job id and add as part of the prefix
'index.m3u8',
async (notification: MinioNotification) =>
Expand Down
31 changes: 19 additions & 12 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface AdNormalizerConfiguration {
encoreUrl: string;
callbackListenerUrl: string;
minioUrl: string;
minioAccessKey: string;
minioSecretKey: string;
minioBucket: string;
s3Endpoint: string;
s3AccessKey: string;
s3SecretKey: string;
bucket: string;
adServerUrl: string;
redisUrl: string;
serviceAccessToken?: string;
Expand All @@ -15,22 +15,29 @@ let config: AdNormalizerConfiguration | null = null;
const loadConfiguration = (): AdNormalizerConfiguration => {
const encoreUrl = process.env.ENCORE_URL;
const callbackListenerUrl = process.env.CALLBACK_LISTENER_URL;
const minioUrl = process.env.MINIO_URL;
const minioAccessKey = process.env.MINIO_ACCESS_KEY;
const minioSecretKey = process.env.MINIO_SECRET_KEY;
const endpoint = process.env.S3_ENDPOINT;
const accessKey = process.env.S3_ACCESS_KEY;
const secretKey = process.env.S3_SECRET_KEY;
const adServerUrl = process.env.AD_SERVER_URL;
const redisUrl = process.env.REDIS_URL;
const minioBucket = process.env.MINIO_BUCKET;
const bucketRaw = process.env.OUTPUT_BUCKET_URL;
if (!bucketRaw) {
throw new Error('OUTPUT_BUCKET_URL is required');
}
const bucket = new URL(bucketRaw);
const bucketPath = bucket.pathname
? bucket.hostname + '/' + bucket.pathname
: bucket.hostname;
const serviceAccessToken = process.env.SERVICE_ACCESS_TOKEN;
const configuration = {
encoreUrl: encoreUrl,
callbackListenerUrl: callbackListenerUrl,
minioUrl: minioUrl,
minioAccessKey: minioAccessKey,
minioSecretKey: minioSecretKey,
s3Endpoint: endpoint,
s3AccessKey: accessKey,
s3SecretKey: secretKey,
adServerUrl: adServerUrl,
redisUrl: redisUrl,
minioBucket: minioBucket,
bucket: bucketPath,
serviceAccessToken: serviceAccessToken
} as AdNormalizerConfiguration;

Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import api from './api';
import 'dotenv/config';
import logger from './util/logger';

const server = api({ title: '@eyevinn/typescript-nodejs' });
const server = api({ title: '@eyevinn/ad-normalizer' });

const PORT = process.env.PORT ? Number(process.env.PORT) : 8000;

Expand Down
16 changes: 11 additions & 5 deletions src/vast/vastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@
const code = response.status;
const url = response.url;
const reason = response.statusText;
logger.error('Failed to submit encore job', {
code,
reason,
url
});
if (code == 401) {
logger.error(
'Encore returned status code 401 Unauthorized. Check that your service access token is still valid.'
);
} else {
logger.error('Failed to submit encore job', {
code,
reason,
url
});
}
throw new Error('Failed to submit encore job');
}
return response.json();
Expand Down Expand Up @@ -136,7 +142,7 @@
const parser = new XMLParser();
const parsedVAST = parser.parse(body);
const creatives = parsedVAST.VAST.Ad.reduce(
(acc: ManifestAsset[], ad: any) => {

Check warning on line 145 in src/vast/vastApi.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const adId = ad.InLine.Creatives.Creative.UniversalAdId.replace(
/[^a-zA-Z0-9]/g,
''
Expand Down
Loading