Skip to content

Commit

Permalink
fix: Refactor pipeline secrets to not use ember data (#1078)
Browse files Browse the repository at this point in the history
Co-authored-by: Alan <[email protected]>
  • Loading branch information
minghay and adong authored Jul 2, 2024
1 parent 51a1a2f commit d33d78e
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions app/v2/pipeline/secrets/route.js
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 };
}
}

0 comments on commit d33d78e

Please sign in to comment.