Skip to content
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

feat: add v2 secrets route #1072

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions app/v2/pipeline/secrets/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Controller from '@ember/controller';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class NewPipelineController extends Controller {
@service store;

@service session;

@service('pipeline.secrets')
refreshService;

@tracked errorMessage = '';

@tracked newToken = null;

get pipeline() {
return this.model.pipeline;
}

get secrets() {
return this.model.secrets;
}

get pipelineTokens() {
return this.model.tokens;
}

get pipelineId() {
return this.model.pipeline.id;
}

@action
createSecret(name, value, pipelineId, allowInPR) {
const newSecret = this.store.createRecord('secret', {
name,
value,
pipelineId,
allowInPR
});

return newSecret.save().then(
s => {
this.errorMessage = '';
this.secrets.reload();

return s;
},
err => {
this.errorMessage = err.errors[0].detail;
}
);
}

@action
createPipelineToken(name, description) {
const newToken = this.store.createRecord('token', {
name,
description: description || '',
action: 'created'
});

return newToken
.save({ adapterOptions: { pipelineId: this.pipelineId } })
.then(
token => {
this.newToken = token;
},
error => {
newToken.destroyRecord({
adapterOptions: { pipelineId: this.pipelineId }
});
throw error;
}
);
}

@action
refreshPipelineToken(tokenId) {
return this.refreshService
.refreshPipelineToken(this.pipelineId, tokenId)
.then(token => {
this.newToken = token;
});
}
}
41 changes: 40 additions & 1 deletion app/v2/pipeline/secrets/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { get } from '@ember/object';

export default class NewPipelineSecretsRoute extends Route {}
export default class NewPipelineSecretsRoute extends Route {
@service session;

@service store;

@service router;

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(
'errorMessage',
error.errors[0].detail
);

return { secrets, pipeline };
});
}
}
21 changes: 20 additions & 1 deletion app/v2/pipeline/secrets/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{{page-title "Secrets"}}
<div>secrets content</div>

<div class="padded-container">
<PipelineSecretSettings
@secrets={{this.secrets}}
@onCreateSecret={{action "createSecret"}}
@pipeline={{this.pipeline}}
@errorMessage={{this.errorMessage}}
/>

<TokenList
@tokens={{this.pipelineTokens}}
@newToken={{this.newToken}}
@pipelineId={{this.pipelineId}}
@onCreateToken={{action "createPipelineToken"}}
@onRefreshToken={{action "refreshPipelineToken"}}
@tokenName="Pipeline"
@tokenScope="this pipeline"
/>
</div>

{{outlet}}
30 changes: 14 additions & 16 deletions app/v2/pipeline/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
grid-template-areas: 'pipeline-nav pipeline-main';

.pipeline-main-content {
grid-area: pipeline-main;
min-width: 300px;
display: grid;

grid-template-areas:
'pipeline-header pipeline-header'
'pipeline-tab pipeline-tab'
'pipeline-content pipeline-workflowgraph';

grid-template-rows: 80px 52px 1fr;
grid-template-columns: 366px 8fr;

.pipeline-header {
grid-area: pipeline-header;
}
Expand Down Expand Up @@ -141,12 +129,22 @@
border-top: none;
}
}

// .event-card-group + .event-card-group {
// border-top: none;
// }
}
}
}

.pipeline-main-content.grid {
grid-area: pipeline-main;
min-width: 300px;
display: grid;

grid-template-areas:
'pipeline-header pipeline-header'
'pipeline-tab pipeline-tab'
'pipeline-content pipeline-workflowgraph';

grid-template-rows: 80px 52px 1fr;
grid-template-columns: 366px 8fr;
}
}
}
3 changes: 2 additions & 1 deletion app/v2/pipeline/template.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{page-title "Pipeline"}}
<div class="pipeline-content">
<Pipeline::Nav />
<div class="pipeline-main-content">
<div class="pipeline-main-content {{if this.isEventsPullsJobsRoute "grid"}}"
>
<div class="pipeline-header">
<PipelineHeader
@pipeline={{this.pipeline}}
Expand Down