Skip to content

Commit 42c1bc8

Browse files
SAN-6186 Not tested with failures yet but otherwise good to go
1 parent 6fffd34 commit 42c1bc8

6 files changed

Lines changed: 272 additions & 83 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
require('app')
4+
.controller('PrivateRegistryFormController', PrivateRegistryFormController);
5+
6+
/**
7+
* @ngInject
8+
*/
9+
function PrivateRegistryFormController (
10+
privateRegistry,
11+
keypather,
12+
loading
13+
) {
14+
console.log(privateRegistry.getRegistryDetails());
15+
16+
var PRFC = this;
17+
PRFC.registryCredentials = privateRegistry.getRegistryDetails();
18+
PRFC.authorized = !!PRFC.registryCredentials;
19+
PRFC.invalidCredentials = false;
20+
PRFC.formReset = false;
21+
22+
PRFC.verifyAndSave = function () {
23+
loading('privateRegistry',true);
24+
25+
privateRegistry.addRegistry(PRFC.url, PRFC.username, PRFC.password)
26+
.then(function(response) {
27+
if (response.status === 204) {
28+
PRFC.invalidCredentials = false;
29+
PRFC.authorized = true;
30+
PRFC.formReset = false;
31+
32+
keypather.set(PRFC, 'registryCredentials.url', PRFC.url);
33+
keypather.set(PRFC, 'registryCredentials.username', PRFC.username);
34+
35+
PRFC.url = null;
36+
PRFC.username = null;
37+
PRFC.password = null;
38+
} else {
39+
PRFC.invalidCredentials = true;
40+
}
41+
}).finally(function() {
42+
loading('privateRegistry',false);
43+
});
44+
};
45+
46+
PRFC.changeRegistry = function () {
47+
PRFC.formReset = true;
48+
};
49+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
require('app')
4+
.directive('privateRegistryForm', privateRegistryForm);
5+
6+
function privateRegistryForm() {
7+
return {
8+
restrict: 'E',
9+
controller: 'PrivateRegistryFormController',
10+
controllerAs: 'PRFC',
11+
templateUrl: 'privateRegistryFormView'
12+
};
13+
}
Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,85 @@
1-
section.label-description
2-
.label-col Private Registry
3-
.small.text-gray If you push your images to a private registry, you can safely store your credentials to use those images on Runnable. 
4-
a.link(
5-
href = "//runnable.com/docs"
6-
target = "_blank"
7-
) Learn more
8-
| .
1+
.grid-block.vertical.modal-form.no-border.form-registry
2+
section.label-description
3+
.label-col Private Registry
4+
.small.text-gray If you push your images to a private registry, you can safely store your credentials to use those images on Runnable. 
5+
a.link(
6+
href = "//runnable.com/docs"
7+
target = "_blank"
8+
) Learn more
9+
| .
910

10-
form.grid-block.vertical.well.gray.ignore-margin(
11-
name = "privateRegistryForm"
12-
ng-class = "{'invalid': state.invalidCredentials}"
13-
ng-if = "!state.authorized"
14-
ng-init = "state.authorized = null"
15-
)
16-
p.red.small.text-center(
17-
ng-if = "state.invalidCredentials"
18-
) We couldn’t validate your credentials.
19-
br
20-
| Please check them and try again.
21-
label.padding-sm.label
22-
.padding-xxs.small.label-sm Registry URL
23-
input.input.input-md.input-validate(
24-
name = "data.url"
25-
ng-disabled = "state.saving"
26-
ng-model = "data.url"
27-
ng-required = "true"
28-
placeholder = "https://index.docker.io/v1/"
29-
spellcheck = "false"
30-
type = "url"
31-
)
32-
small.grid-block.padding-xxs.small Add the URL for the registry you use. This could be from Docker Hub or a private registry.
33-
label.padding-sm.label
34-
.padding-xxs.small.label-sm Username
35-
input.input.input-md.input-validate(
36-
name = "data.username"
37-
ng-disabled = "state.saving"
38-
ng-model = "data.username"
39-
ng-required = "true"
40-
spellcheck = "false"
41-
)
42-
label.padding-sm.label
43-
.padding-xxs.small.label-sm Password
44-
input.input.input-md.input-validate(
45-
autocomplete = "new-password"
46-
name = "data.password"
47-
ng-disabled = "state.saving"
48-
ng-model = "data.password"
49-
ng-required = "true"
50-
spellcheck = "false"
51-
type = "password"
52-
)
53-
footer.margin-top-sm.padding-sm.grid-block.footer(
54-
ng-class = "{\
55-
'justify-justified': state.authorized,\
56-
'justify-right': !state.authorized\
57-
}"
11+
form.grid-block.vertical.well.gray.ignore-margin(
12+
name = "privateRegistryForm"
13+
ng-class = "{'invalid': PRFC.invalidCredentials}"
14+
ng-if = "!PRFC.authorized || PRFC.formReset"
5815
)
59-
button.btn.btn-md.gray.btn-cancel(
60-
ng-if = "state.authorized"
61-
) Back
62-
button.grid-block.shrink.align-center.btn.btn-md.green(
63-
ng-click = "state.saving = true"
64-
ng-disabled = "state.saving || privateRegistryForm.$invalid"
65-
ng-init = "state.saving = null"
16+
p.red.small.text-center(
17+
ng-if = "PRFC.invalidCredentials"
18+
) We couldn’t validate your credentials.
19+
br
20+
| Please check them and try again.
21+
label.padding-sm.label
22+
.padding-xxs.small.label-sm Registry URL
23+
input.input.input-md.input-validate(
24+
name = "PRFC.url"
25+
ng-disabled = "$root.isLoading.privateRegistry"
26+
ng-model = "PRFC.url"
27+
ng-required = "true"
28+
placeholder = "https://index.docker.io/v1/"
29+
spellcheck = "false"
30+
type = "url"
31+
)
32+
small.grid-block.padding-xxs.small Add the URL for the registry you use. This could be from Docker Hub or a private registry.
33+
label.padding-sm.label
34+
.padding-xxs.small.label-sm Username
35+
input.input.input-md.input-validate(
36+
name = "PRFC.username"
37+
ng-disabled = "$root.isLoading.privateRegistry"
38+
ng-model = "PRFC.username"
39+
ng-required = "true"
40+
spellcheck = "false"
41+
)
42+
label.padding-sm.label
43+
.padding-xxs.small.label-sm Password
44+
input.input.input-md.input-validate(
45+
autocomplete = "new-password"
46+
name = "PRFC.password"
47+
ng-disabled = "$root.isLoading.privateRegistry"
48+
ng-model = "PRFC.password"
49+
ng-required = "true"
50+
spellcheck = "false"
51+
type = "password"
52+
)
53+
footer.margin-top-sm.padding-sm.grid-block.footer(
54+
ng-class = "{\
55+
'justify-justified': PRFC.authorized,\
56+
'justify-right': !PRFC.authorized\
57+
}"
6658
)
67-
.spinner-wrapper.spinner-sm.spinner-white(
68-
ng-if = "state.saving"
69-
ng-include = "'spinner'"
59+
button.btn.btn-md.gray.btn-cancel(
60+
ng-if = "PRFC.authorized && PRFC.formReset"
61+
ng-click = "PRFC.formReset = false"
62+
) Back
63+
button.grid-block.shrink.align-center.btn.btn-md.green(
64+
ng-click = "PRFC.verifyAndSave()"
65+
ng-disabled = "$root.isLoading.privateRegistry || privateRegistryForm.$invalid"
7066
)
71-
span Verify & Save
67+
.spinner-wrapper.spinner-sm.spinner-white(
68+
ng-if = "$root.isLoading.privateRegistry"
69+
ng-include = "'spinner'"
70+
)
71+
span Verify & Save
7272

73-
section.padding-sm.grid-block.align-center.well.white.ignore-margin(
74-
ng-if = "state.authorized"
75-
ng-init = "registryCredentials = [\
76-
{username: 'dockerfan88', url: 'https://index.docker.io/v1/'}\
77-
]"
78-
)
79-
svg.margin-right-xxs.text-green.grid-block.shrink.iconnables.icons-check
80-
use(
81-
xlink:href = "#icons-check"
82-
)
83-
.grid-block.vertical
84-
p.small.weight-strong.text-overflow Authorized {{registryCredentials[0].username}}
85-
small.small.text-gray.text-overflow {{registryCredentials[0].url}}
86-
button.btn.btn-xs.gray.margin-left-xxs Change
73+
section.padding-sm.grid-block.align-center.well.white.ignore-margin(
74+
ng-if = "PRFC.authorized && !PRFC.formReset"
75+
)
76+
svg.margin-right-xxs.text-green.grid-block.shrink.iconnables.icons-check
77+
use(
78+
xlink:href = "#icons-check"
79+
)
80+
.grid-block.vertical
81+
p.small.weight-strong.text-overflow Authorized {{PRFC.registryCredentials.username}}
82+
small.small.text-gray.text-overflow {{PRFC.registryCredentials.url}}
83+
button.btn.btn-xs.gray.margin-left-xxs(
84+
ng-click = "PRFC.changeRegistry()"
85+
) Change

client/directives/modals/settingsModal/settingsModalView.jade

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@
9393
ng-include = "'gitHubForm'"
9494
)
9595

96-
.grid-block.vertical.modal-form.no-border.form-registry(
96+
private-registry-form(
9797
ng-if = "$root.featureFlags.privateRegistry && SEMC.currentTab === 'privateRegistry'"
98-
ng-include = "'privateRegistryFormView'"
9998
)
10099

101100
slack-integration-form(

client/services/privateRegistry.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
require('app')
4+
.factory('privateRegistry', privateRegistry);
5+
6+
function privateRegistry(
7+
$http,
8+
configAPIHost,
9+
currentOrg,
10+
keypather
11+
) {
12+
return {
13+
addRegistry: function (regUrl, username, password) {
14+
return $http({
15+
method: 'post',
16+
url: configAPIHost + '/organizations/' + currentOrg.poppa.id() + '/private-registry',
17+
data: {
18+
url: regUrl,
19+
username: username,
20+
password: password
21+
}
22+
});
23+
},
24+
getRegistryDetails: function() {
25+
var username = keypather.get(currentOrg, 'poppa.attrs.privateRegistryUsername');
26+
var url = keypather.get(currentOrg, 'poppa.attrs.privateRegistryUrl');
27+
28+
if (username && url) {
29+
return {
30+
username: username,
31+
url: url
32+
};
33+
}
34+
35+
return null;
36+
}
37+
};
38+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict';
2+
3+
describe('privateRegistryFormController'.bold.underline.blue, function () {
4+
var $scope;
5+
var $rootScope;
6+
var $controller;
7+
var privateRegistryFormController;
8+
var mockGetRegistryDetails;
9+
10+
describe('base', function () {
11+
describe('Check the construction when does not have registry', function () {
12+
beforeEach(function () {
13+
angular.mock.module('app');
14+
angular.mock.module(function ($provide) {
15+
$provide.factory('privateRegistry', function ($q) {
16+
mockGetRegistryDetails = function() {
17+
return null;
18+
};
19+
20+
return {
21+
getRegistryDetails: mockGetRegistryDetails
22+
};
23+
});
24+
});
25+
angular.mock.inject(function (
26+
_$controller_,
27+
_$rootScope_
28+
) {
29+
$controller = _$controller_;
30+
$rootScope = _$rootScope_;
31+
32+
$scope = $rootScope.$new();
33+
34+
privateRegistryFormController = $controller('PrivateRegistryFormController', {
35+
'$scope': $scope
36+
});
37+
});
38+
$scope.$digest();
39+
40+
});
41+
42+
it('constructor', function () {
43+
expect(privateRegistryFormController.registryCredentials).to.be.null;
44+
expect(privateRegistryFormController.authorized).to.be.false;
45+
expect(privateRegistryFormController.invalidCredentials).to.be.false;
46+
expect(privateRegistryFormController.formReset).to.be.false;
47+
});
48+
});
49+
50+
describe('Check the construction when has registry', function () {
51+
beforeEach(function () {
52+
angular.mock.module('app');
53+
angular.mock.module(function ($provide) {
54+
$provide.factory('privateRegistry', function ($q) {
55+
mockGetRegistryDetails = function() {
56+
return {
57+
username: 'somebody',
58+
url: 'somewhere'
59+
};
60+
};
61+
62+
return {
63+
getRegistryDetails: mockGetRegistryDetails
64+
};
65+
});
66+
});
67+
angular.mock.inject(function (
68+
_$controller_,
69+
_$rootScope_
70+
) {
71+
$controller = _$controller_;
72+
$rootScope = _$rootScope_;
73+
74+
$scope = $rootScope.$new();
75+
76+
privateRegistryFormController = $controller('PrivateRegistryFormController', {
77+
'$scope': $scope
78+
});
79+
});
80+
$scope.$digest();
81+
});
82+
83+
it('constructor', function() {
84+
expect(privateRegistryFormController.registryCredentials.username).to.equal('somebody');
85+
expect(privateRegistryFormController.authorized).to.be.true;
86+
expect(privateRegistryFormController.invalidCredentials).to.be.false;
87+
expect(privateRegistryFormController.formReset).to.be.false;
88+
});
89+
});
90+
});
91+
});

0 commit comments

Comments
 (0)