Skip to content

Commit

Permalink
🔧 Add ParamValue types
Browse files Browse the repository at this point in the history
  • Loading branch information
thorpelawrence committed Jan 10, 2021
1 parent fa61207 commit 9270bda
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 CribAdvisor
Copyright (c) 2021 CribAdvisor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cribadvisor/aws-param-cache",
"version": "2.1.0",
"version": "2.1.1",
"description": "Cache un/encrypted expiring values as AWS SSM parameters with a TTL",
"main": "dist/index.js",
"types": "dist",
Expand Down
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ interface SSMCacheOptions {
keyId?: string;
}

interface ParamValue {
TTL: number;
Value: string;
}

class SSMCache {
options: SSMCacheOptions;
_ssm: SSM;
Expand Down Expand Up @@ -58,7 +63,7 @@ class SSMCache {
}
const now = new Date().getTime() / 1000;
const timestamp = new Date(param.LastModifiedDate).getTime() / 1000;
const { TTL: ttl, Value: value } = JSON.parse(param.Value);
const { TTL: ttl, Value: value }: ParamValue = JSON.parse(param.Value);
if (now > timestamp + ttl) {
await this._ssm
.deleteParameter({
Expand Down Expand Up @@ -90,14 +95,14 @@ class SSMCache {
ttl,
ow.number.is((x) => x > 0 || `Expected \`${x}\` to be greater than 0`)
);
const param = JSON.stringify({
const param: ParamValue = {
TTL: ttl,
Value: value,
});
};
return await this._ssm
.putParameter({
Name: this._escapeName(`${this.options.basePath}/${key}`),
Value: param,
Value: JSON.stringify(param),
Type: this.options.secret ? "SecureString" : "String",
Overwrite: true,
KeyId: this.options.keyId,
Expand Down

0 comments on commit 9270bda

Please sign in to comment.