mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 14:59:37 +08:00
Merge pull request #24374 from migstopheles/master
Add typings for nodecredstash
This commit is contained in:
45
types/nodecredstash/index.d.ts
vendored
Normal file
45
types/nodecredstash/index.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Type definitions for nodecredstash 2.0
|
||||
// Project: https://github.com/DavidTanner/nodecredstash
|
||||
// Definitions by: Mike Cook <https://github.com/migstopheles>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node"/>
|
||||
import * as AWS from 'aws-sdk';
|
||||
|
||||
interface CredstashConfig {
|
||||
table?: string;
|
||||
awsOpts?: AWS.KMS.ClientConfiguration;
|
||||
dynamoOpts?: AWS.DynamoDB.ClientConfiguration;
|
||||
kmsKey?: string;
|
||||
kmsOpts?: AWS.KMS.ClientConfiguration;
|
||||
}
|
||||
|
||||
interface CredstashContext {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
interface PutSecretOptions {
|
||||
name: string;
|
||||
secret: string;
|
||||
context: CredstashContext;
|
||||
digest?: string;
|
||||
version?: number;
|
||||
}
|
||||
|
||||
interface Credstash {
|
||||
getHighestVersion: (options: { name: string }) => Promise<AWS.DynamoDB.AttributeMap>;
|
||||
incrementVersion: (options: { name: string }) => Promise<string>;
|
||||
putSecret: (options: PutSecretOptions) => Promise<AWS.DynamoDB.DocumentClient.PutItemOutput>;
|
||||
decryptStash: (stash: { key: string; }, context?: CredstashContext) => Promise<AWS.KMS.DecryptResponse>;
|
||||
getAllVersions: (options: { name: string, context?: CredstashContext, limit?: number }) => Promise<Array<{ version: string; secret: string }>>;
|
||||
getSecret: (options: { name: string, context?: CredstashContext, version?: number }) => Promise<string>;
|
||||
deleteSecrets: (options: { name: string }) => Promise<AWS.DynamoDB.DocumentClient.DeleteItemOutput[]>;
|
||||
deleteSecret: (options: { name: string, version: number }) => Promise<AWS.DynamoDB.DocumentClient.DeleteItemOutput>;
|
||||
listSecrets: () => Promise<string[]>;
|
||||
getAllSecrets: (options: { version?: number, context?: CredstashContext, startsWith?: string }) => Promise<{ [key: string]: string }>;
|
||||
createDdbTable: () => Promise<void>;
|
||||
}
|
||||
|
||||
declare function Credstash(config: CredstashConfig): Credstash;
|
||||
|
||||
export = Credstash;
|
||||
59
types/nodecredstash/nodecredstash-tests.ts
Normal file
59
types/nodecredstash/nodecredstash-tests.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import Credstash = require('nodecredstash');
|
||||
|
||||
const credstash = Credstash({
|
||||
awsOpts: { region: 'us-east-1' },
|
||||
dynamoOpts: { accessKeyId: 'foo' },
|
||||
kmsKey: 'bar',
|
||||
kmsOpts: { accessKeyId: 'baz' },
|
||||
table: 'something'
|
||||
});
|
||||
|
||||
credstash.decryptStash({ key: 'foo' }).then((result) => {
|
||||
return {
|
||||
id: result.KeyId,
|
||||
text: result.Plaintext
|
||||
};
|
||||
});
|
||||
|
||||
credstash.deleteSecret({ name: 'foo', version: 1 }).then((result) => {
|
||||
if (result.Attributes) return result.Attributes['blah'];
|
||||
if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName;
|
||||
if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey;
|
||||
});
|
||||
|
||||
credstash.deleteSecrets({ name: 'foo' }).then((results) => {
|
||||
const result = results[0];
|
||||
if (result.Attributes) return result.Attributes['blah'].toUpperCase();
|
||||
if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName;
|
||||
if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey;
|
||||
});
|
||||
|
||||
credstash.getAllSecrets({ version: 1 }).then((result) => {
|
||||
return result['foo'].toUpperCase();
|
||||
});
|
||||
|
||||
credstash.getAllVersions({ name: 'foo', context: { bar: 'baz' }, limit: 1 }).then((result) => {
|
||||
return result[0].secret.toUpperCase() + result[0].version.toUpperCase();
|
||||
});
|
||||
|
||||
credstash.getHighestVersion({ name: 'foo' }).then((result) => {
|
||||
return result['foo'].S;
|
||||
});
|
||||
|
||||
credstash.getSecret({ name: 'foo', version: 1, context: { bar: 'baz' } }).then((result) => {
|
||||
return result.toUpperCase();
|
||||
});
|
||||
|
||||
credstash.incrementVersion({ name: 'foo' }).then((result) => {
|
||||
return result.toUpperCase();
|
||||
});
|
||||
|
||||
credstash.listSecrets().then((result) => {
|
||||
return result.map((str) => str.toUpperCase());
|
||||
});
|
||||
|
||||
credstash.putSecret({ name: 'foo', secret: 'bar', context: { baz: 'qux' }, digest: 'quux', version: 1 }).then((result) => {
|
||||
if (result.Attributes) return result.Attributes['foo'];
|
||||
if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName;
|
||||
if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey;
|
||||
});
|
||||
6
types/nodecredstash/package.json
Normal file
6
types/nodecredstash/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.211.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
23
types/nodecredstash/tsconfig.json
Normal file
23
types/nodecredstash/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"nodecredstash-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/nodecredstash/tslint.json
Normal file
1
types/nodecredstash/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user