-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(artifacts): Support embedded/base64 artifact type (#5021)
- Loading branch information
Scott Bloch-Wehba-Seaward
committed
Mar 20, 2018
1 parent
b25c932
commit 7123971
Showing
5 changed files
with
164 additions
and
1 deletion.
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
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
10 changes: 10 additions & 0 deletions
10
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/base64/base64.artifact.less
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,10 @@ | ||
.copy-base64-reference { | ||
float: right; | ||
} | ||
|
||
pre.base64-artifact-encoded-preview { | ||
max-height: 100px; | ||
overflow: auto; | ||
white-space: normal; | ||
word-break: break-word; | ||
} |
46 changes: 46 additions & 0 deletions
46
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/base64/base64.artifact.ts
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,46 @@ | ||
import { module } from 'angular'; | ||
|
||
import { PIPELINE_CONFIG_PROVIDER } from 'core/pipeline/config/pipelineConfigProvider'; | ||
import { IArtifact } from 'core/domain/IArtifact'; | ||
import { PipelineConfigProvider } from 'core/pipeline'; | ||
|
||
import './base64.artifact.less'; | ||
|
||
export const BASE64_ARTIFACT = 'spinnaker.core.pipeline.trigger.artifact.base64'; | ||
module(BASE64_ARTIFACT, [ | ||
PIPELINE_CONFIG_PROVIDER, | ||
]).config((pipelineConfigProvider: PipelineConfigProvider) => { | ||
pipelineConfigProvider.registerArtifactKind({ | ||
label: 'Base64', | ||
description: 'An artifact that includes its referenced resource as part of its payload.', | ||
key: 'base64', | ||
isDefault: false, | ||
isMatch: true, | ||
controller(artifact: IArtifact) { | ||
'ngInject'; | ||
this.artifact = artifact; | ||
this.artifact.type = 'embedded/base64'; | ||
}, | ||
controllerAs: 'ctrl', | ||
template: ` | ||
<div class="col-md-12"> | ||
<div class="form-group row"> | ||
<label class="col-md-2 sm-label-right"> | ||
Name | ||
</label> | ||
<div class="col-md-8"> | ||
<input type="text" | ||
placeholder="base64-artifact" | ||
class="form-control input-sm" | ||
ng-model="ctrl.artifact.name" /> | ||
</div> | ||
</div> | ||
<div ng-if="ctrl.encodeDecodeError" class="form-group row"> | ||
<div class="col-md-12 error-message"> | ||
Error encoding/decoding artifact content: {{ ctrl.encodeDecodeError }} | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
...ipts/modules/core/src/pipeline/config/triggers/artifacts/base64/defaultBase64.artifact.ts
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,103 @@ | ||
import { module } from 'angular'; | ||
|
||
import { has } from 'lodash'; | ||
|
||
import { PIPELINE_CONFIG_PROVIDER } from 'core/pipeline/config/pipelineConfigProvider'; | ||
import { IArtifact } from 'core/domain/IArtifact'; | ||
import { PipelineConfigProvider } from 'core/pipeline'; | ||
|
||
import './base64.artifact.less'; | ||
|
||
export const DEFAULT_BASE64_ARTIFACT = 'spinnaker.core.pipeline.trigger.artifact.defaultBase64'; | ||
|
||
const DOMBase64Errors: { [key: string]: string } = { | ||
5: 'The string to encode contains characters outside the latin1 range.', | ||
}; | ||
|
||
module(DEFAULT_BASE64_ARTIFACT, [ | ||
PIPELINE_CONFIG_PROVIDER, | ||
]).config((pipelineConfigProvider: PipelineConfigProvider) => { | ||
pipelineConfigProvider.registerArtifactKind({ | ||
label: 'Base64', | ||
description: 'An artifact that includes its referenced resource as part of its payload.', | ||
key: 'default.base64', | ||
isDefault: true, | ||
isMatch: false, | ||
controller(artifact: IArtifact) { | ||
'ngInject'; | ||
this.artifact = artifact; | ||
this.artifact.type = 'embedded/base64'; | ||
this.decoded = ''; | ||
this.encodeDecodeError = ''; | ||
|
||
this.convert = (fn: ((s: string) => string), str: string): string => { | ||
this.encodeDecodeError = ''; | ||
try { | ||
return fn(str); | ||
} catch (e) { | ||
if (has(DOMBase64Errors, e.code)) { | ||
this.encodeDecodeError = DOMBase64Errors[e.code]; | ||
} else { | ||
this.encodeDecodeError = e.message; | ||
} | ||
return ''; | ||
} | ||
}; | ||
|
||
this.onContentChange = () => { | ||
const encoded = this.convert(btoa, this.decoded); | ||
if (!this.encodeDecodeError) { | ||
this.artifact.reference = encoded; | ||
} | ||
}; | ||
|
||
if (this.artifact.reference) { | ||
const decoded = this.convert(atob, this.artifact.reference); | ||
if (!this.encodeDecodeError) { | ||
this.decoded = decoded; | ||
} | ||
} | ||
}, | ||
controllerAs: 'ctrl', | ||
template: ` | ||
<div class="col-md-12"> | ||
<div class="form-group row"> | ||
<label class="col-md-2 sm-label-right"> | ||
Name | ||
</label> | ||
<div class="col-md-8"> | ||
<input type="text" | ||
placeholder="base64-artifact" | ||
class="form-control input-sm" | ||
ng-model="ctrl.artifact.name" /> | ||
</div> | ||
</div> | ||
<div class="form-group row"> | ||
<label class="col-md-2 sm-label-right"> | ||
Contents | ||
</label> | ||
<div class="col-md-8"> | ||
<textarea autocapitalize="none" | ||
autocomplete="off" | ||
rows="16" | ||
class="form-control code" | ||
ng-model="ctrl.decoded" | ||
ng-change="ctrl.onContentChange()"> | ||
</textarea> | ||
<copy-to-clipboard | ||
class="copy-base64-reference" | ||
text="ctrl.artifact.reference" | ||
tool-tip="'Copy base64-encoded content to clipboard'" | ||
analytics-label="'Copy Base64 Artifact Content'" | ||
></copy-to-clipboard> | ||
</div> | ||
</div> | ||
<div ng-if="ctrl.encodeDecodeError" class="form-group row"> | ||
<div class="col-md-12 error-message"> | ||
Error encoding/decoding artifact content: {{ ctrl.encodeDecodeError }} | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
}); | ||
}); |