Skip to content

Commit

Permalink
When adding known official docker registry do not append default port.
Browse files Browse the repository at this point in the history
The change is in both the back end and UI.

Added additional check when setting the UI title to either
Admiral or VIC, if it's not embedded.

Added additional check in main-resources-component, if the
current user is project viewer and there is no harbor configured
to not show the Library in left navigation bar, because in this case
none of Library submenus should be shown.

Change-Id: I718fea64ecef1dcdf6560189a0f58f373968fe5f
Reviewed-on: http://bellevue-ci.eng.vmware.com:8080/15771
Closures-Verified: jenkins <[email protected]>
Upgrade-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
CS-Verified: jenkins <[email protected]>
Reviewed-by: Sergio Sanchez <[email protected]>
  • Loading branch information
angel-ivanov committed Aug 18, 2017
1 parent 281c3e2 commit 24c9b1b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

package com.vmware.admiral.adapter.docker.util;

import java.util.Arrays;
import java.util.List;
import static com.vmware.admiral.common.util.UriUtilsExtended.OFFICIAL_REGISTRY_LIST;

import java.util.regex.Pattern;

/**
Expand All @@ -24,9 +24,6 @@ public class DockerImage {
public static final String DEFAULT_NAMESPACE = "library";
public static final String DEFAULT_TAG = "latest";
private static final Pattern NAMESPACE_PATTERN = Pattern.compile("[a-z0-9_]+");
private static final List<String> OFFICIAL_REGISTRY_LIST = Arrays.asList(
"registry.hub.docker.com",
"docker.io");

private String host;
private String namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -33,6 +36,12 @@ public class UriUtilsExtended {
private static final String DEFAULT_DOCKER_REGISTRY_SCHEME = UriUtils.HTTPS_SCHEME;
private static final int DEFAULT_DOCKER_REGISTRY_HTTP_PORT = 80;
private static final int DEFAULT_DOCKER_REGISTRY_HTTPS_PORT = 443;

public static final List<String> OFFICIAL_REGISTRY_LIST = Collections
.unmodifiableList(Arrays.asList(
"registry.hub.docker.com",
"docker.io"));

/* Host URL pattern */
public static final Pattern PATTERN_HOST_URL = Pattern
.compile("((?<scheme>\\w[\\w\\d+-\\.]*)(://))?"
Expand Down Expand Up @@ -62,21 +71,26 @@ public static URI buildDockerRegistryUri(String address) {
"common.unsupported.scheme", scheme);
}

String serviceHost = matcher.group("host");
boolean isDefaultDockerRegistry = OFFICIAL_REGISTRY_LIST.contains(serviceHost);

String servicePort = matcher.group("port");
int port = DEFAULT_DOCKER_REGISTRY_HTTPS_PORT;
Integer port = null;
if (servicePort != null && !servicePort.isEmpty()) {
port = Integer.parseInt(servicePort);
} else {
if (UriUtils.HTTP_SCHEME.equals(scheme)) {
// Do not append default port if it's official docker registry.
if (UriUtils.HTTP_SCHEME.equals(scheme) && !isDefaultDockerRegistry) {
port = DEFAULT_DOCKER_REGISTRY_HTTP_PORT;
} else {
} else if (UriUtils.HTTPS_SCHEME.equals(scheme) && !isDefaultDockerRegistry) {
port = DEFAULT_DOCKER_REGISTRY_HTTPS_PORT;
}
}

String serviceHost = matcher.group("host");

try {
if (port == null) {
return new URI(scheme, serviceHost, null, null);
}
return new URI(scheme, null, serviceHost, port, null, null, null);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
Expand Down
8 changes: 6 additions & 2 deletions ui/app/src/js/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const RE_UNIX_ABS_PATH_OR_NAME = new RegExp('^((' + RX_NAME + ')|(' + RX_UNIX_AB

const VERSION_REG_EX = /^(\*|\d+(\.\d+){0,2}(\.\*)?)/g;

const OFFICIAL_REGISTRY_LIST = ['registry.hub.docker.com', 'docker.io'];

var isSingleView = window.isSingleView;
var isNavigationLess = window.isNavigationLess;

Expand Down Expand Up @@ -831,11 +833,13 @@ var utils = {
urlParts.scheme = 'https';
}

var isDefaultDockerRegistry = OFFICIAL_REGISTRY_LIST.indexOf(urlParts.host) !== -1;

if (!urlParts.port) {
if (urlParts.scheme.toLowerCase() === 'https') {
if (urlParts.scheme.toLowerCase() === 'https' && !isDefaultDockerRegistry) {
urlParts.port = 443;
}
if (urlParts.scheme.toLowerCase() === 'http') {
if (urlParts.scheme.toLowerCase() === 'http' && !isDefaultDockerRegistry) {
urlParts.port = 80;
}
}
Expand Down
10 changes: 6 additions & 4 deletions ui/ng-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ export class AppComponent implements OnInit {
}

ngOnInit() {
if (this.vic) {
this.title.setTitle("vSphere Integrated Containers");
} else {
this.title.setTitle("Admiral");
if (!this.embedded) {
if (this.vic) {
this.title.setTitle("vSphere Integrated Containers");
} else {
this.title.setTitle("Admiral");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</li>
</ul>
</section>
<section class="nav-group collapsible">
<section *ngIf="showLibrary"class="nav-group collapsible">
<input id="libraryCollapse" type="checkbox">
<label for="libraryCollapse">{{ "navigation.library" | i18n }}</label>
<ul class="nav-list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import { FT } from './../../utils/ft';
import { Roles } from './../../utils/roles';
import { Ajax } from './../../utils/ajax.service';
import { Links } from './../../utils/links';
import { DocumentListResult, DocumentService } from './../../utils/document.service';
Expand All @@ -18,6 +19,7 @@ import { Subscription } from 'rxjs/Subscription';
import { Router, NavigationEnd } from '@angular/router';
import { RoutesRestriction } from './../../utils/routes-restriction';
import { ProjectService } from './../../utils/project.service';
import { AuthService } from './../../utils/auth.service';
import { ErrorService } from '../../utils/error.service';
import { FormerViewPathBridge, RouteUtils } from './../../utils/route-utils';

Expand Down Expand Up @@ -58,11 +60,12 @@ export class MainResourcesComponent implements OnInit, OnDestroy {

selectedProject;
projects;
showLibrary: boolean;

alertMessage: string;

constructor(private router: Router, private ds: DocumentService, private ajax: Ajax,
private ps: ProjectService, private errorService: ErrorService) {
private ps: ProjectService, private errorService: ErrorService, private authService: AuthService) {

this.routeObserve = this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
Expand Down Expand Up @@ -104,6 +107,7 @@ export class MainResourcesComponent implements OnInit, OnDestroy {
}

this.ps.setSelectedProject(this.selectedProject);
this.checkShowLibrary();
});
}

Expand All @@ -115,6 +119,7 @@ export class MainResourcesComponent implements OnInit, OnDestroy {
selectProject(project) {
this.selectedProject = project;
this.ps.setSelectedProject(this.selectedProject);
this.checkShowLibrary();
}

onFormerViewRouteChange(newFormerPath: string) {
Expand Down Expand Up @@ -147,6 +152,34 @@ export class MainResourcesComponent implements OnInit, OnDestroy {
});
}

checkShowLibrary() {
if (this.isHbrEnabled || !this.selectedProject) {
this.showLibrary = true;
return;
}

let selectedProjectLink = this.selectedProject.documentSelfLink;
this.authService.getCachedSecurityContext().then(securityContext => {
let foundProject = securityContext.projects.find(x => {
return x.documentSelfLink === selectedProjectLink;
});

if (foundProject && foundProject.roles) {
if (foundProject.roles.indexOf(Roles.PROJECT_ADMIN) == -1
&& foundProject.roles.indexOf(Roles.PROJECT_MEMBER) == -1) {
this.showLibrary = false;
} else {
this.showLibrary = true;
}
} else {
this.showLibrary = false;
}

}).catch(e => {
this.showLibrary = true;
})
}

get deploymentsRouteRestriction() {
return RoutesRestriction.DEPLOYMENTS;
}
Expand Down

0 comments on commit 24c9b1b

Please sign in to comment.