Skip to content
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
- id: prettier
exclude: pnpm-lock.yaml
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.27.0
rev: v9.28.0
hooks:
- id: eslint
files: \.(m|c)?[jt]sx?$
Expand Down
65 changes: 33 additions & 32 deletions docs/CONFIG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import tseslint from "typescript-eslint";
export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
Expand Down
10 changes: 10 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ export interface HtsgetLambdaProps {
* @defaultValue undefined
*/
role?: IRole;

/**
* Override the environment variables used to build htsget. Note that this only adds environment variables that
* get used to build htsget-rs with `cargo`. It has no effect on the environment variables that htsget-rs has when
* the Lambda function is deployed. In general, leave this undefined unless there is a specific reason to override
* the build environment.
*
* @defaultValue undefined
*/
buildEnvironment?: Record<string, string>;
}

/**
Expand Down
43 changes: 22 additions & 21 deletions lib/htsget-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ export class HtsgetLambda extends Construct {
constructor(scope: Construct, id: string, props: HtsgetLambdaProps) {
super(scope, id);

if (props.htsgetConfig == undefined) {
props.htsgetConfig = {
locations: [],
};
}
props.htsgetConfig ??= {
locations: [],
};

let httpApi: IHttpApi;
if (props.httpApi !== undefined) {
Expand All @@ -95,6 +93,8 @@ export class HtsgetLambda extends Construct {
lambdaRole = this.createRole(id);
}

props.buildEnvironment ??= {};

const htsgetLambda = new RustFunction(this, "Function", {
gitRemote: "https://github.com/umccr/htsget-rs",
gitForceClone: props.gitForceClone,
Expand All @@ -105,6 +105,7 @@ export class HtsgetLambda extends Construct {
RUSTFLAGS: "-C target-cpu=neoverse-n1",
CARGO_PROFILE_RELEASE_LTO: "true",
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1",
...props.buildEnvironment,
},
cargoLambdaFlags: props.cargoLambdaFlags ?? [
this.resolveFeatures(props.htsgetConfig, props.copyTestData ?? false),
Expand Down Expand Up @@ -214,7 +215,7 @@ export class HtsgetLambda extends Construct {
const latestCommit = exec("git", [
"ls-remote",
gitRemote,
gitReference || "HEAD",
gitReference ?? "HEAD",
])
.stdout.toString()
.split(/(\s+)/)[0];
Expand Down Expand Up @@ -425,14 +426,14 @@ export class HtsgetLambda extends Construct {
bucket?: Bucket,
privateKey?: Secret,
publicKey?: Secret,
): { [key: string]: string } {
): Record<string, string> {
const toHtsgetEnv = (value: unknown) => {
return JSON.stringify(value)
.replaceAll(new RegExp(/"( )*:( )*/g), "=")
.replaceAll('"', "");
};

const out: { [key: string]: string | undefined } = {};
const out: Record<string, string | undefined> = {};
const locations = config.locations ?? [];

if (bucket !== undefined) {
Expand Down Expand Up @@ -463,25 +464,25 @@ export class HtsgetLambda extends Construct {
if (
locationsEnv == "[]" &&
(config.environment_override === undefined ||
config.environment_override["HTSGET_LOCATIONS"] === undefined)
config.environment_override.HTSGET_LOCATIONS === undefined)
) {
throw new Error(
"no locations configured, htsget-rs wouldn't be able to access any files!",
);
}

out["HTSGET_LOCATIONS"] = locationsEnv;
out["HTSGET_TICKET_SERVER_CORS_ALLOW_CREDENTIALS"] =
out.HTSGET_LOCATIONS = locationsEnv;
out.HTSGET_TICKET_SERVER_CORS_ALLOW_CREDENTIALS =
corsConfig?.allowCredentials?.toString();
out["HTSGET_TICKET_SERVER_CORS_ALLOW_HEADERS"] =
`[${corsConfig?.allowHeaders?.join(",") as string}]`;
out["HTSGET_TICKET_SERVER_CORS_ALLOW_METHODS"] =
`[${corsConfig?.allowMethods?.join(",") as string}]`;
out["HTSGET_TICKET_SERVER_CORS_ALLOW_ORIGINS"] =
`[${corsConfig?.allowOrigins?.join(",") as string}]`;
out["HTSGET_TICKET_SERVER_CORS_EXPOSE_HEADERS"] =
`[${corsConfig?.exposeHeaders?.join(",") as string}]`;
out["HTSGET_TICKET_SERVER_CORS_MAX_AGE"] = corsConfig?.maxAge
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
out.HTSGET_TICKET_SERVER_CORS_ALLOW_HEADERS = `[${corsConfig?.allowHeaders?.join(",") as string}]`;
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
out.HTSGET_TICKET_SERVER_CORS_ALLOW_METHODS = `[${corsConfig?.allowMethods?.join(",") as string}]`;
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
out.HTSGET_TICKET_SERVER_CORS_ALLOW_ORIGINS = `[${corsConfig?.allowOrigins?.join(",") as string}]`;
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
out.HTSGET_TICKET_SERVER_CORS_EXPOSE_HEADERS = `[${corsConfig?.exposeHeaders?.join(",") as string}]`;
out.HTSGET_TICKET_SERVER_CORS_MAX_AGE = corsConfig?.maxAge
?.toSeconds()
.toString();

Expand All @@ -499,6 +500,6 @@ export class HtsgetLambda extends Construct {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
(out[key] == `[undefined]` || out[key] == "[]") && delete out[key],
);
return out as { [key: string]: string };
return out as Record<string, string>;
}
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
"cargo-lambda-cdk": "^0.0.33"
},
"devDependencies": {
"@eslint/js": "^9.27.0",
"@types/node": "22.15.19",
"@eslint/js": "^9.28.0",
"@types/node": "22.15.29",
"aws-cdk": "2.112.0",
"aws-cdk-lib": "2.112.0",
"constructs": "10.4.2",
"eslint": "^9.27.0",
"eslint": "^9.28.0",
"prettier": "^3.5.3",
"typedoc": "^0.28.4",
"typedoc-plugin-markdown": "^4.6.3",
"typedoc": "^0.28.5",
"typedoc-plugin-markdown": "^4.6.4",
"typescript": "5.8.3",
"typescript-eslint": "^8.32.1"
"typescript-eslint": "^8.33.0"
},
"files": [
"./**/*.d.ts",
"./**/*.js"
],
"license": "MIT",
"name": "htsget-lambda",
"packageManager": "pnpm@9.14.0",
"packageManager": "pnpm@10.11.0",
"peerDependencies": {
"aws-cdk-lib": "^2.112.0"
},
Expand All @@ -34,7 +34,7 @@
"prettier": "prettier",
"run": "cdk deploy",
"watch": "tsc -w",
"typedoc": "typedoc"
"typedoc": "typedoc --gitRevision main --plugin typedoc-plugin-markdown"
},
"version": "0.9.0"
"version": "0.9.1"
}
Loading