-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds mirage setup for sync endpoints * updates secret_name default in sync-association mirage factory
- Loading branch information
Showing
6 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { Factory } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
accessor: 'kv_eb4acbae', | ||
secret_name: 'my-path/my-secret-1', | ||
sync_status: 'SYNCED', | ||
updated_at: '2023-09-20T10:51:53.961861096-04:00', | ||
// set on create for lookup by destination | ||
type: null, | ||
name: null, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { Factory, trait } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
['aws-sm']: trait({ | ||
access_key_id: 'foo', | ||
secret_access_key: 'bar', | ||
region: 'us-west-1', | ||
type: 'aws-sm', | ||
name: 'destination-aws', | ||
}), | ||
['azure-kv']: trait({ | ||
key_vault_uri: 'https://keyvault-1234abcd.vault.azure.net', | ||
subscription_id: 'subscription-id', | ||
tenant_id: 'tenant-id', | ||
client_id: 'client-id', | ||
client_secret: 'my-secret', | ||
type: 'azure-kv', | ||
name: 'destination-azure', | ||
}), | ||
['gcp-sm']: trait({ | ||
credentials: '{"username":"foo","password":"bar"}', | ||
type: 'gcp-sm', | ||
name: 'destination-gcp', | ||
}), | ||
gh: trait({ | ||
access_token: 'github_pat_12345', | ||
repository_owner: 'my-organization-or-username', | ||
repository_name: 'my-repository', | ||
type: 'gh', | ||
name: 'destination-gh', | ||
}), | ||
['vercel-project']: trait({ | ||
access_token: 'my-access-token', | ||
project_id: 'prj_12345', | ||
deployment_environments: ['development', 'preview', 'production'], | ||
type: 'vercel-project', | ||
name: 'destination-vercel', | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { Response } from 'miragejs'; | ||
|
||
export default function (server) { | ||
const base = '/sys/sync/destinations'; | ||
const uri = `${base}/:type/:name`; | ||
// destinations | ||
server.get(base, (schema) => { | ||
const records = schema.db.syncDestinations.where({}); | ||
if (!records.length) { | ||
return new Response(404, {}, { errors: [] }); | ||
} | ||
return { | ||
data: { | ||
key_info: records.reduce((keyInfo, record) => { | ||
if (!keyInfo[record.type]) { | ||
keyInfo[record.type] = [record.name]; | ||
} else { | ||
keyInfo[record.type].push(record.name); | ||
} | ||
return keyInfo; | ||
}, {}), | ||
}, | ||
}; | ||
}); | ||
server.get(uri, (schema, req) => { | ||
const { type, name } = req.params; | ||
const record = schema.db.syncDestinations.findBy({ type, name }); | ||
if (record) { | ||
delete record.type; | ||
delete record.name; | ||
return { | ||
data: { | ||
connection_details: record, | ||
name, | ||
type, | ||
}, | ||
}; | ||
} | ||
return new Response(404, {}, { errors: [] }); | ||
}); | ||
server.post(uri, (schema, req) => { | ||
const { type, name } = req.params; | ||
const data = { ...JSON.parse(req.requestBody), type, name }; | ||
schema.db.syncDestinations.firstOrCreate({ type, name }, data); | ||
schema.db.syncDestinations.update({ type, name }, data); | ||
return new Response(204); | ||
}); | ||
server.delete(uri, (schema, req) => { | ||
const { type, name } = req.params; | ||
schema.db.syncDestinations.remove({ type, name }); | ||
return new Response(204); | ||
}); | ||
// associations | ||
server.get(`${uri}/associations`, (schema, req) => { | ||
const { type, name } = req.params; | ||
const records = schema.db.syncAssociations.where({ type, name }); | ||
if (!records.length) { | ||
return new Response(404, {}, { errors: [] }); | ||
} | ||
return { | ||
data: { | ||
associated_secrets: records.reduce((associations, association) => { | ||
const key = `${association.accessor}/${association.secret_name}`; | ||
delete association.type; | ||
delete association.name; | ||
associations[key] = association; | ||
return associations; | ||
}, {}), | ||
store_name: name, | ||
store_type: type, | ||
}, | ||
}; | ||
}); | ||
server.post(`${uri}/associations/set`, (schema, req) => { | ||
const { type, name } = req.params; | ||
const { secret_name, mount: accessor } = JSON.parse(req.requestBody); | ||
const data = { type, name, accessor, secret_name }; | ||
schema.db.syncAssociations.firstOrCreate({ type, name }, data); | ||
schema.db.syncAssociations.update({ type, name }, data); | ||
return new Response(204); | ||
}); | ||
server.post(`${uri}/associations/remove`, (schema, req) => { | ||
const { type, name } = req.params; | ||
schema.db.syncAssociations.remove({ type, name }); | ||
return new Response(204); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import kubernetes from './kubernetes'; | ||
import ldap from './ldap'; | ||
import sync from './sync'; | ||
|
||
export { kubernetes, ldap }; | ||
export { kubernetes, ldap, sync }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
export default function (server) { | ||
const types = ['aws-sm', 'azure-kv', 'gcp-sm', 'gh', 'vercel-project']; | ||
types.forEach((type) => { | ||
server.create('sync-destination', type); | ||
server.create('sync-association', { type, name: `destination-${type.split('-')[0]}` }); | ||
}); | ||
} |