-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubernetes Mirage Setup #17943
Merged
zofskeez
merged 1 commit into
ui/kubernetes-secrets-engine
from
ui/VAULT-9831/kubernetes-mirage-setup
Nov 17, 2022
Merged
Kubernetes Mirage Setup #17943
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
kubernetes_host: 'https://192.168.99.100:8443', | ||
kubernetes_ca_cert: '-----BEGIN CERTIFICATE-----\n.....\n-----END CERTIFICATE-----', | ||
disable_local_ca_jwt: false, | ||
|
||
// property used only for record lookup and filtered from response payload | ||
path: 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,16 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
name: 'default-role', | ||
allowed_kubernetes_namespaces: () => ['*'], | ||
allowed_kubernetes_namespace_selector: '', | ||
token_max_ttl: 86400, | ||
token_default_ttl: 0, | ||
service_account_name: 'default', | ||
kubernetes_role_name: '', | ||
kubernetes_role_type: 'Role', | ||
generated_role_rules: '', | ||
name_template: '', | ||
extra_annotations: null, | ||
extra_labels: 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
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,68 @@ | ||
import { Response } from 'miragejs'; | ||
|
||
export default function (server) { | ||
const getRecord = (schema, req, dbKey) => { | ||
const { path, name } = req.params; | ||
const findBy = dbKey === 'kubernetesConfigs' ? { path } : { name }; | ||
const record = schema.db[dbKey].findBy(findBy); | ||
if (record) { | ||
delete record.path; | ||
delete record.id; | ||
} | ||
return record ? { data: record } : new Response(404, {}, { errors: [] }); | ||
}; | ||
const createRecord = (req, key) => { | ||
const data = JSON.parse(req.requestBody); | ||
if (key === 'kubernetes-config') { | ||
data.path = req.params.path; | ||
} | ||
server.create(key, data); | ||
return new Response(204); | ||
}; | ||
const deleteRecord = (schema, req, dbKey) => { | ||
const record = getRecord(schema, req, dbKey); | ||
if (record) { | ||
schema.db[dbKey].remove(record.id); | ||
} | ||
return new Response(204); | ||
}; | ||
|
||
server.get('/:path/config', (schema, req) => { | ||
return getRecord(schema, req, 'kubernetesConfigs'); | ||
}); | ||
server.post('/:path/config', (schema, req) => { | ||
return createRecord(req, 'kubernetes-config'); | ||
}); | ||
server.delete('/:path/config', (schema, req) => { | ||
return deleteRecord(schema, req, 'kubernetesConfigs'); | ||
}); | ||
server.get('/:path/roles', (schema) => { | ||
return { | ||
data: { | ||
keys: schema.db.kubernetesRoles.where({}).mapBy('name'), | ||
}, | ||
}; | ||
}); | ||
server.get('/:path/roles/:name', (schema, req) => { | ||
return getRecord(schema, req, 'kubernetesRoles'); | ||
}); | ||
server.post('/:path/roles/:name', (schema, req) => { | ||
return createRecord(req, 'kubernetes-role'); | ||
}); | ||
server.delete('/:path/roles/:name', (schema, req) => { | ||
return deleteRecord(schema, req, 'kubernetesRoles'); | ||
}); | ||
server.post('/:path/creds/:role', (schema, req) => { | ||
const { role } = req.params; | ||
const record = schema.db.kubernetesRoles.findBy({ name: role }); | ||
const data = JSON.parse(req.requestBody); | ||
let errors; | ||
if (!record) { | ||
errors = [`role '${role}' does not exist`]; | ||
} else if (!data.kubernetes_namespace) { | ||
errors = ["'kubernetes_namespace' is required"]; | ||
} | ||
// creds cannot be fetched after creation so we don't need to store them | ||
return errors ? new Response(400, {}, { errors }) : new Response(204); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these methods need to be defined within the server function? This might read a little clearer if they are defined outside of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createRecord
uses theserver
instance but I suppose that could be passed in. Not sure if it's worth moving outside to then pass in the server instance though? I'm curious if there is a best practice regarding this or personal preference (thinking about possible eslint warning)?