Skip to content

Commit

Permalink
Merge pull request #2879 from dtaylor113/secrets
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

Create Opaque Secrets from File

https://trello.com/c/SANVwQnv

- Created a new Secret Type 'Opaque Secret'.  Not sure if this should be 'Input' or 'Builder' secret?
- 'Opaque Secret' form is same key-value map used in Create Config Map.
![image](https://user-images.githubusercontent.com/12733153/37102182-45abf7a2-21f5-11e8-9110-36fe4f2fe2d8.png)

Not sure what code to use to Create this type of secret.  Creating a Secret is:
```
DataService.create(secretsVersion, null, newSecret, $scope).then(function(secret) { // Success
            // In order to link:
            // - the SA has to be defined
            // - defined SA has to be present in the obtained SA list
            // - user can update SA
            // Else the linking will be skipped
            if ($scope.newSecret.linkSecret && $scope.serviceAccountsNames.contains($scope.newSecret.pickedServiceAccountToLink) && AuthorizationService.canI('serviceaccounts', 'update')) {
              linkSecretToServiceAccount(secret);
```
- Do I need to show the 'Link secret to a service account.' checkbox for 'Opaque Secrets' ?

Creating a Config Map is:
```
DataService.create(createConfigMapVersion, null, $scope.configMap, context)
```
- where `$scope.configMap.data` is the key-value pairs map.

Looking into `DataService.create(secretsVersion...` to see if it supports `data.keyvaluepairs`
  • Loading branch information
openshift-merge-robot authored Mar 16, 2018
2 parents d2c964d + 804f372 commit 29a4830
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ <h1>JavaScript Required</h1>
<script src="scripts/directives/createSecret.js"></script>
<script src="scripts/directives/date.js"></script>
<script src="scripts/directives/deleteLink.js"></script>
<script src="scripts/directives/editConfigMap.js"></script>
<script src="scripts/directives/editConfigMapOrSecret.js"></script>
<script src="scripts/directives/editEnvironmentFrom.js"></script>
<script src="scripts/directives/events.js"></script>
<script src="scripts/directives/eventsSidebar.js"></script>
Expand Down
18 changes: 17 additions & 1 deletion app/scripts/directives/createSecret.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ angular.module("openshiftConsole")
label: "Webhook Secret"
}
]
},
generic: {
label: "Generic Secret",
authTypes: [
{
id: "Opaque",
label: "Generic Secret"
}
]
}
};

Expand All @@ -95,7 +104,11 @@ angular.module("openshiftConsole")
$scope.newSecret = {
type: "source",
authType: "kubernetes.io/basic-auth",
data: {},
data: {
genericKeyValues: {
data: {}
}
},
linkSecret: false,
pickedServiceAccountToLink: "",
};
Expand Down Expand Up @@ -173,6 +186,9 @@ angular.module("openshiftConsole")
if (data.webhookSecretKey) {
secret.stringData.WebHookSecretKey = data.webhookSecretKey;
}
if (data.genericKeyValues.data) {
secret.stringData = data.genericKeyValues.data;
}
break;
}
return secret;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"use strict";

angular.module("openshiftConsole")
.directive("editConfigMap",
.directive("editConfigMapOrSecret",
function(DNS1123_SUBDOMAIN_VALIDATION) {
return {
require: '^form',
restrict: 'E',
scope: {
configMap: "=model",
showNameInput: "="
map: "=model",
showNameInput: "=",
type: "@"
},
templateUrl: 'views/directives/edit-config-map.html',
templateUrl: 'views/directives/edit-config-map-or-secret.html',
link: function($scope, element, attrs, formCtl) {
$scope.form = formCtl;

Expand All @@ -32,7 +33,7 @@ angular.module("openshiftConsole")
};

// Load the data once when it is first set.
var clearWatch = $scope.$watch('configMap.data', function(data) {
var clearWatch = $scope.$watch('map.data', function(data) {
if (!data) {
return;
}
Expand All @@ -53,14 +54,14 @@ angular.module("openshiftConsole")

clearWatch();

// Update `$scope.configMap` as the form data changes.
// Update `$scope.map` as the form data changes.
$scope.$watch('data', function(data) {
var map = {};
_.each(data, function(keyValuePair) {
map[keyValuePair.key] = keyValuePair.value;
});

_.set($scope, 'configMap.data', map);
_.set($scope, 'map.data', map);
}, true);
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/create-config-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Create Config Map</h1>
</div>
<form name="createConfigMapForm" class="mar-top-xl">
<fieldset ng-disabled="disableInputs">
<edit-config-map model="configMap" show-name-input="true"></edit-config-map>
<edit-config-map-or-secret model="configMap" type="config-map" show-name-input="true"></edit-config-map-or-secret>
<div class="button-group gutter-top gutter-bottom">
<button type="submit"
class="btn btn-primary btn-lg"
Expand Down
5 changes: 4 additions & 1 deletion app/views/directives/create-secret.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</div>
</div>

<div ng-if="newSecret.type != 'webhook'">
<div ng-if="newSecret.type === 'source' || newSecret.type === 'image'">
<div class="form-group">
<label for="authentification-type">Authentication Type</label>
<ui-select required input-id="authentification-type" ng-model="newSecret.authType" search-enabled="false">
Expand Down Expand Up @@ -350,6 +350,9 @@
</div>
</div>
</div>
<div ng-if="newSecret.type === 'generic'">
<edit-config-map-or-secret model="newSecret.data.genericKeyValues" type="secret"></edit-config-map-or-secret>
</div>
</div>
<div class="buttons gutter-top-bottom">
<button class="btn btn-primary"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
<ng-form name="configMapForm">
<ng-form name="keyValueMapForm">
<fieldset>
<!-- Name -->
<div ng-show="showNameInput" class="form-group">
<label for="config-map-name" class="required">Name</label>
<label for="key-value-map-name" class="required">Name</label>
<!-- regex, maxlength from k8s.io/kubernetes/pkg/util/validation/validation.go -->
<div ng-class="{ 'has-error': configMapForm.name.$invalid && configMapForm.name.$touched }">
<div ng-class="{ 'has-error': keyValueMapForm.name.$invalid && keyValueMapForm.name.$touched }">
<input
id="config-map-name"
id="key-value-map-name"
class="form-control"
type="text"
name="name"
ng-model="configMap.metadata.name"
ng-model="map.metadata.name"
ng-required="showNameInput"
ng-pattern="nameValidation.pattern"
ng-maxlength="nameValidation.maxlength"
placeholder="my-config-map"
placeholder="my-{{type}}"
select-on-focus
autocorrect="off"
autocapitalize="none"
spellcheck="false"
aria-describedby="config-map-name-help">
aria-describedby="key-value-map-name-help">
</div>
<div>
<span id="config-map-name-help" class="help-block">A unique name for the config map within the project.</span>
<span id="key-value-map-name-help" class="help-block">A unique name for the {{type}} within the project.</span>
</div>
<div class="has-error" ng-show="configMapForm.name.$error.pattern && configMapForm.name.$touched">
<div class="has-error" ng-show="keyValueMapForm.name.$error.pattern && keyValueMapForm.name.$touched">
<span class="help-block">
{{nameValidation.description}}
</span>
</div>
<div class="has-error" ng-show="configMapForm.name.$error.required && configMapForm.name.$touched">
<div class="has-error" ng-show="keyValueMapForm.name.$error.required && keyValueMapForm.name.$touched">
<span class="help-block">
Name is required.
</span>
</div>
<div class="has-error" ng-show="configMapForm.name.$error.maxlength">
<div class="has-error" ng-show="keyValueMapForm.name.$error.maxlength">
<span class="help-block">
Can't be longer than {{nameValidation.maxlength}} characters.
</span>
</div>
</div>

<div ng-if="!data.length">
<p><em>The config map has no items.</em></p>
<p><em>The {{type}} has no items.</em></p>
<a href="" ng-click="addItem()">Add Item</a>
</div>

Expand All @@ -53,7 +53,7 @@
Config map validation:
https://github.com/openshift/origin/blob/32708e768d77db08b118d084955a7ccf2aebbf1c/vendor/k8s.io/client-go/1.4/pkg/util/validation/validation.go#L271-L273
-->
<div ng-class="{ 'has-error': configMapForm['key-' + $id].$invalid && configMapForm['key-' + $id].$touched }">
<div ng-class="{ 'has-error': keyValueMapForm['key-' + $id].$invalid && keyValueMapForm['key-' + $id].$touched }">
<input
class="form-control"
name="key-{{$id}}"
Expand All @@ -72,26 +72,26 @@
aria-describedby="key-{{$id}}-help">
</div>
<div class="help-block">
A unique key for this config map entry.
A unique key for this {{type}} entry.
</div>
<div class="has-error" ng-show="configMapForm['key-' + $id].$error.required && configMapForm['key-' + $id].$touched">
<div class="has-error" ng-show="keyValueMapForm['key-' + $id].$error.required && keyValueMapForm['key-' + $id].$touched">
<span class="help-block">
Key is required.
</span>
</div>
<div class="has-error" ng-show="configMapForm['key-' + $id].$error.oscUnique && configMapForm['key-' + $id].$touched">
<div class="has-error" ng-show="keyValueMapForm['key-' + $id].$error.oscUnique && keyValueMapForm['key-' + $id].$touched">
<span class="help-block">
Duplicate key "{{item.key}}". Keys must be unique within the config map.
Duplicate key "{{item.key}}". Keys must be unique within the {{type}}.
</span>
</div>
<div class="has-error" ng-show="configMapForm['key-' + $id].$error.pattern && configMapForm['key-' + $id].$touched">
<div class="has-error" ng-show="keyValueMapForm['key-' + $id].$error.pattern && keyValueMapForm['key-' + $id].$touched">
<span class="help-block">
Config map keys may only consist of letters, numbers, periods, hyphens, and underscores.
Keys may only consist of letters, numbers, periods, hyphens, and underscores.
</span>
</div>
<div class="has-error" ng-show="configMapForm['key-' + $id].$error.maxlength">
<div class="has-error" ng-show="keyValueMapForm['key-' + $id].$error.maxlength">
<span class="help-block">
Config map keys may not be longer than 253 characters.
Keys may not be longer than 253 characters.
</span>
</div>
</div>
Expand All @@ -100,7 +100,7 @@
<osc-file-input
model="item.value"
drop-zone-id="drop-zone-{{$id}}"
help-text="Enter a value for the config map entry or use the contents of a file."></osc-file-input>
help-text="Enter a value for the {{type}} entry or use the contents of a file."></osc-file-input>
<div ui-ace="{
theme: 'eclipse',
rendererOptions: {
Expand Down
2 changes: 1 addition & 1 deletion app/views/edit/config-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>Edit Config Map {{configMap.metadata.name}}</h1>
Config map {[configMap.metadata.name}} has been deleted since you started editing it.
</div>
<fieldset ng-disabled="disableInputs">
<edit-config-map model="configMap"></edit-config-map>
<edit-config-map-or-secret model="configMap" type="config map"></edit-config-map-or-secret>
<div class="button-group gutter-top gutter-bottom">
<button type="submit"
class="btn btn-primary btn-lg"
Expand Down
28 changes: 20 additions & 8 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9150,6 +9150,13 @@ authTypes: [ {
id: "Opaque",
label: "Webhook Secret"
} ]
},
generic: {
label: "Generic Secret",
authTypes: [ {
id: "Opaque",
label: "Generic Secret"
} ]
}
}, l.secretTypes = _.keys(l.secretAuthTypeMap), l.type ? l.newSecret = {
type: l.type,
Expand All @@ -9160,7 +9167,11 @@ pickedServiceAccountToLink: l.serviceAccountToLink || ""
} : l.newSecret = {
type: "source",
authType: "kubernetes.io/basic-auth",
data: {},
data: {
genericKeyValues: {
data: {}
}
},
linkSecret: !1,
pickedServiceAccountToLink: ""
}, l.add = {
Expand Down Expand Up @@ -9204,7 +9215,7 @@ auth: o
break;

case "Opaque":
e.webhookSecretKey && (r.stringData.WebHookSecretKey = e.webhookSecretKey);
e.webhookSecretKey && (r.stringData.WebHookSecretKey = e.webhookSecretKey), e.genericKeyValues.data && (r.stringData = e.genericKeyValues.data);
}
return r;
}, d = function() {
Expand Down Expand Up @@ -9393,15 +9404,16 @@ details: n("getErrorDetails")(e)
};
}
};
} ]), angular.module("openshiftConsole").directive("editConfigMap", [ "DNS1123_SUBDOMAIN_VALIDATION", function(e) {
} ]), angular.module("openshiftConsole").directive("editConfigMapOrSecret", [ "DNS1123_SUBDOMAIN_VALIDATION", function(e) {
return {
require: "^form",
restrict: "E",
scope: {
configMap: "=model",
showNameInput: "="
map: "=model",
showNameInput: "=",
type: "@"
},
templateUrl: "views/directives/edit-config-map.html",
templateUrl: "views/directives/edit-config-map-or-secret.html",
link: function(t, n, r, a) {
t.form = a, t.nameValidation = e, t.addItem = function() {
t.data.push({
Expand All @@ -9413,7 +9425,7 @@ t.data.splice(e, 1), t.form.$setDirty();
}, t.getKeys = function() {
return _.map(t.data, "key");
};
var o = t.$watch("configMap.data", function(e) {
var o = t.$watch("map.data", function(e) {
e && (t.data = _.map(e, function(e, t) {
return {
key: t,
Expand All @@ -9423,7 +9435,7 @@ value: e
var n = {};
_.each(e, function(e) {
n[e.key] = e.value;
}), _.set(t, "configMap.data", n);
}), _.set(t, "map.data", n);
}, !0));
});
}
Expand Down
Loading

0 comments on commit 29a4830

Please sign in to comment.