-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Refactor pipeline secrets to not use ember data (#1078)
Co-authored-by: Alan <[email protected]>
- Loading branch information
Showing
1 changed file
with
31 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 |
---|---|---|
@@ -1,42 +1,49 @@ | ||
import Route from '@ember/routing/route'; | ||
import { service } from '@ember/service'; | ||
import { get } from '@ember/object'; | ||
|
||
export default class NewPipelineSecretsRoute extends Route { | ||
@service router; | ||
|
||
@service session; | ||
|
||
@service store; | ||
@service shuttle; | ||
|
||
@service router; | ||
async beforeModel() { | ||
// Guests should not access this page | ||
if (this.session.data.authenticated.isGuest) { | ||
this.router.transitionTo('v2.pipeline'); | ||
} | ||
} | ||
|
||
model() { | ||
async model() { | ||
// Refresh error message | ||
this.controllerFor('v2.pipeline.secrets').set('errorMessage', ''); | ||
|
||
// Guests should not access this page | ||
if (get(this, 'session.data.authenticated.isGuest')) { | ||
this.router.transitionTo('pipeline'); | ||
} | ||
|
||
const { pipeline } = this.modelFor('v2.pipeline'); | ||
const secrets = pipeline.get('secrets'); | ||
|
||
this.store.unloadAll('token'); | ||
|
||
return this.store | ||
.findAll('token', { adapterOptions: { pipelineId: pipeline.get('id') } }) | ||
.then(tokens => ({ | ||
tokens, | ||
secrets, | ||
pipeline | ||
})) | ||
.catch(error => { | ||
this.controllerFor('pipeline.secrets').set( | ||
const pipelineId = pipeline.id; | ||
|
||
const secrets = await this.shuttle | ||
.fetchFromApi('get', `/pipelines/${pipelineId}/secrets`) | ||
.catch(err => { | ||
this.controllerFor('v2.pipeline.secrets').set( | ||
'errorMessage', | ||
err.message | ||
); | ||
|
||
return []; | ||
}); | ||
|
||
const tokens = await this.shuttle | ||
.fetchFromApi('get', `/pipelines/${pipelineId}/tokens`) | ||
.catch(err => { | ||
this.controllerFor('v2.pipeline.secrets').set( | ||
'errorMessage', | ||
error.errors[0].detail | ||
err.message | ||
); | ||
|
||
return { secrets, pipeline }; | ||
return []; | ||
}); | ||
|
||
return { pipeline, secrets, tokens }; | ||
} | ||
} |