-
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.
- Loading branch information
Showing
5 changed files
with
163 additions
and
19 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,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; | ||
}); | ||
} | ||
} |
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,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 }; | ||
}); | ||
} | ||
} |
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,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}} |
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