Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shahradelahi committed Apr 12, 2024
1 parent fa20586 commit 58bfd65
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 39 deletions.
28 changes: 14 additions & 14 deletions src/engine/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/config/root',
client: this,
client: this.client,
schema: {
body: z.object({
max_retries: z.number().optional(),
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'GET',
path: '/aws/config/root',
client: this,
client: this.client,
schema: {
response: z.any()
}
Expand All @@ -61,7 +61,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/config/rotate-root',
client: this,
client: this.client,
schema: {
response: z.any()
}
Expand All @@ -77,7 +77,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/config/lease',
client: this,
client: this.client,
schema: {
body: z.object({
lease: z.string(),
Expand All @@ -97,7 +97,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/config/lease',
client: this,
client: this.client,
schema: {
response: z.any()
}
Expand All @@ -113,7 +113,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/config/role',
client: this,
client: this.client,
schema: {
body: z.object({
name: z.string(),
Expand Down Expand Up @@ -145,7 +145,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'GET',
path: '/aws/roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -164,7 +164,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'LIST',
path: '/aws/roles',
client: this,
client: this.client,
schema: {
response: z.any()
}
Expand All @@ -180,7 +180,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'DELETE',
path: '/aws/roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -199,7 +199,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'GET',
path: '/aws/creds/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -224,7 +224,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'POST',
path: '/aws/static-roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -247,7 +247,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'GET',
path: '/aws/static-roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -266,7 +266,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'DELETE',
path: '/aws/static-roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -285,7 +285,7 @@ export class Aws extends ApiSector {
return generateCommand({
method: 'GET',
path: '/aws/static-creds/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand Down
16 changes: 8 additions & 8 deletions src/engine/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'POST',
path: '/kubernetes/config',
client: this,
client: this.client,
schema: {
// Parameters
//
Expand Down Expand Up @@ -46,7 +46,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'GET',
path: '/kubernetes/config',
client: this,
client: this.client,
schema: {
response: ErrorResponseSchema.or(ZodAnyRecord)
}
Expand All @@ -62,7 +62,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'DELETE',
path: '/kubernetes/config',
client: this,
client: this.client,
schema: {
response: ErrorResponseSchema.or(z.boolean())
}
Expand All @@ -78,7 +78,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'POST',
path: '/kubernetes/roles/{{name}}',
client: this,
client: this.client,
schema: {
// Parameters
//
Expand Down Expand Up @@ -126,7 +126,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'GET',
path: '/kubernetes/roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -145,7 +145,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'LIST',
path: '/kubernetes/roles',
client: this,
client: this.client,
schema: {
response: ErrorResponseSchema.or(ZodAnyRecord)
}
Expand All @@ -161,7 +161,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'DELETE',
path: '/kubernetes/roles/{{name}}',
client: this,
client: this.client,
schema: {
path: z.object({
name: z.string()
Expand All @@ -180,7 +180,7 @@ export class Kubernetes extends ApiSector {
return generateCommand({
method: 'POST',
path: '/kubernetes/creds/{{name}}',
client: this,
client: this.client,
schema: {
// Parameters
//
Expand Down
60 changes: 58 additions & 2 deletions src/engine/kv2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateCommand } from '@/index';
import { ApiSector } from '@/lib/sector';
import { ErrorResponseSchema, SuccessResponseSchema } from '@/schema';
import { ErrorResponseSchema, SuccessResponseSchema, ZodAnyRecord } from '@/schema';
import { z } from 'zod';

export class Kv2 extends ApiSector {
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Kv2 extends ApiSector {
*
* @link https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-latest-version-of-secret
*/
get deleteLatestVersion() {
get deleteLatest() {
return generateCommand({
method: 'DELETE',
path: '/{{mountPath}}/data/{{path}}',
Expand Down Expand Up @@ -404,6 +404,62 @@ export class Kv2 extends ApiSector {
}
});
}

/**
* Engine info
*/
get info() {
return generateCommand({
method: 'GET',
path: '/sys/mounts/{{mountPath}}',
client: this.client,
schema: {
path: z.object({
mountPath: z.string()
}),
response: ErrorResponseSchema.or(
SuccessResponseSchema.extend({
local: z.boolean(),
seal_wrap: z.boolean(),
external_entropy_access: z.boolean(),
options: ZodAnyRecord,
running_sha256: z.string(),
deprecation_status: z.string(),
config: z.object({
default_lease_ttl: z.number(),
force_no_cache: z.boolean(),
max_lease_ttl: z.number()
}),
type: z.string(),
description: z.string(),
accessor: z.string(),
uuid: z.string(),
plugin_version: z.string(),
running_plugin_version: z.string(),
data: z.object({
accessor: z.string(),
config: z.object({
default_lease_ttl: z.number(),
force_no_cache: z.boolean(),
max_lease_ttl: z.number()
}),
deprecation_status: z.string(),
description: z.string(),
external_entropy_access: z.boolean(),
local: z.boolean(),
options: ZodAnyRecord,
plugin_version: z.string(),
running_plugin_version: z.string(),
running_sha256: z.string(),
seal_wrap: z.boolean(),
type: z.string(),
uuid: z.string()
})
})
)
}
});
}
}

const MetadataSchema = z.object({
Expand Down
26 changes: 11 additions & 15 deletions tests/engines/kv2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ describe('Key/Value Secrets Engine - Version 2', () => {

it('should mount the secrets engine', async () => {
// Create
{
const result = await vc.mount({
mountPath,
type: 'kv-v2'
});
const mounted = await vc.mount({
mountPath,
type: 'kv-v2'
});

expect(result).to.true;
}
expect(mounted).to.true;

// Verify
{
const result = await vc.engineInfo({
mountPath
});
const info = await vc.kv2.info({
mountPath
});

expect(result).to.have.property('type', 'kv');
expect(result).to.have.property('options').to.have.property('version', '2');
}
expect(info).to.have.property('type', 'kv');
expect(info).to.have.property('options').to.have.property('version', '2');
});

it('should create a secret path and write a new version', async () => {
Expand Down Expand Up @@ -154,7 +150,7 @@ describe('Key/Value Secrets Engine - Version 2', () => {
.to.have.property('1')
.to.have.property('destroyed', false);

const deleted = await vc.kv2.deleteLatestVersion({
const deleted = await vc.kv2.deleteLatest({
mountPath,
path: 'new-test'
});
Expand Down

0 comments on commit 58bfd65

Please sign in to comment.