forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VAULT-13220 use decorator instead of extending overview route (hashic…
- Loading branch information
1 parent
0d3c0c0
commit 354af62
Showing
6 changed files
with
57 additions
and
24 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,36 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
/** | ||
* the overview, roles, issuers, certificates, and key routes all need to be aware of the whether there is a config for the engine | ||
* if the user has not configured they are prompted to do so in each of the routes | ||
* decorate the necessary routes to perform the check in the beforeModel hook since that may change what is returned for the model | ||
*/ | ||
|
||
export function withConfig() { | ||
return function decorator(SuperClass) { | ||
if (!Object.prototype.isPrototypeOf.call(Route, SuperClass)) { | ||
// eslint-disable-next-line | ||
console.error( | ||
'withConfig decorator must be used on an instance of ember Route class. Decorator not applied to returned class' | ||
); | ||
return SuperClass; | ||
} | ||
return class CheckConfig extends SuperClass { | ||
shouldPromptConfig = false; | ||
|
||
async beforeModel() { | ||
super.beforeModel(...arguments); | ||
|
||
// When the engine is configured, it creates a default issuer. | ||
// If the issuers list is empty, we know it hasn't been configured | ||
return ( | ||
this.store | ||
.query('pki/issuer', { backend: this.secretMountPath.currentPath }) | ||
.then(() => (this.shouldPromptConfig = true)) | ||
// this endpoint is unauthenticated, so we're not worried about permissions errors | ||
.catch(() => (this.shouldPromptConfig = false)) | ||
); | ||
} | ||
}; | ||
}; | ||
} |
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
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
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