Skip to content

Commit

Permalink
feat(artifacts): Support embedded/base64 artifact type (#5021)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Bloch-Wehba-Seaward committed Mar 20, 2018
1 parent b25c932 commit 7123971
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ArtifactCtrl implements IController {

if (artifactKindConfig.length) {
const config = artifactKindConfig[0];
const template: Element = config.template as any;
const template: string = config.template;
this.description = config.description;

const ctrl = config.controller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { DEFAULT_GCS_ARTIFACT } from './gcs/defaultGcs.artifact';
import { DEFAULT_GITHUB_ARTIFACT } from './github/defaultGithub.artifact';
import { ARTIFACT } from './artifact.component';
import { GITHUB_ARTIFACT } from 'core/pipeline/config/triggers/artifacts/github/github.artifact';
import { BASE64_ARTIFACT } from 'core/pipeline/config/triggers/artifacts/base64/base64.artifact';
import { DEFAULT_BASE64_ARTIFACT } from 'core/pipeline/config/triggers/artifacts/base64/defaultBase64.artifact';

export const ARTIFACT_MODULE = 'spinnaker.core.pipeline.config.trigger.artifacts';

Expand All @@ -18,8 +20,10 @@ module(ARTIFACT_MODULE, [
GCS_ARTIFACT,
GITHUB_ARTIFACT,
DOCKER_ARTIFACT,
BASE64_ARTIFACT,
DEFAULT_DOCKER_ARTIFACT,
DEFAULT_GCS_ARTIFACT,
DEFAULT_GITHUB_ARTIFACT,
DEFAULT_BASE64_ARTIFACT,
ARTIFACT,
]);
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;
}
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>
`,
});
});
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>
`,
});
});

0 comments on commit 7123971

Please sign in to comment.