Review fixes: rename type names and add better coloring

This commit is contained in:
Joseph Schorr 2017-05-23 15:30:59 -04:00
parent 602575f710
commit 51485a5006
3 changed files with 50 additions and 29 deletions

View file

@ -45,7 +45,7 @@
.tag-signing-display-element .expiring-soon {
border-radius: 100%;
background-color: #ffe0c4;
background-color: #fbab62;
position: absolute;
right: 0px;
@ -57,7 +57,7 @@
.tag-signing-display-element .expired {
border-radius: 100%;
background-color: #ffcad1;
background-color: #ec5266;
position: absolute;
right: 0px;
@ -69,7 +69,7 @@
.tag-signing-display-element .invalid {
border-radius: 100%;
background-color: #ffcad1;
background-color: #ec5266;
position: absolute;
right: 0px;
@ -128,10 +128,18 @@
}
.tag-signing-display-element.extended .delegations .delegation.okay {
background-color: #bdf1dd;
background-color: #d0deea;
}
.tag-signing-display-element.extended .delegations .delegation.okay:before {
color: #5f9dd0;
}
.tag-signing-display-element.extended .delegations .delegation.default {
background-color: #bdf1dd;
}
.tag-signing-display-element.extended .delegations .delegation.default:before {
color: #2FC98E;
}

View file

@ -67,8 +67,9 @@
<table class="delegations" ng-if="!$ctrl.compact && $ctrl.getSigningInfo($ctrl.tag, $ctrl.delegations).delegations.length">
<tr ng-repeat="delegation in $ctrl.getSigningInfo($ctrl.tag, $ctrl.delegations).delegations">
<td>
<span class="delegation" ng-class="{'okay': delegation.hasMatchingHash && !delegation.isExpired && !delegation.isExpiringSoon, 'warning': delegation.hasMatchingHash && delegation.isExpiringSoon, 'error': !delegation.hasMatchingHash || delegation.isExpired}">
<span class="delegation-name">{{ delegation.delegationName.substr('targets/'.length) }}</span>
<span class="delegation" ng-class="{'default': $ctrl.isDefaultDelegation(delegation.delegationName), 'okay': delegation.hasMatchingHash && !delegation.isExpired && !delegation.isExpiringSoon, 'warning': delegation.hasMatchingHash && delegation.isExpiringSoon, 'error': !delegation.hasMatchingHash || delegation.isExpired}">
<span class="delegation-name" ng-if="delegation.delegationName == 'targets'">(Default)</span>
<span class="delegation-name" ng-if="delegation.delegationName != 'targets'">{{ delegation.delegationName.substr('targets/'.length) }}</span>
</span>
<div class="delegation-info visible-xs" ng-if="!delegation.hasMatchingHash || delegation.isExpiringSoon || delegation.isExpired">
<span class="failure-reason" ng-if="delegation.hasMatchingHash && delegation.isExpiringSoon">

View file

@ -2,16 +2,16 @@ import { Input, Component, Inject } from 'ng-metadata/core';
import { ApostilleDelegationsSet, ApostilleSignatureDocument, ApostilleTagDocument } from '../../../types/common.types';
import * as moment from "moment";
type tagSigningInfo = {
delegations: delegationInfo[];
delegationsByName: {[delegationName: string]: delegationInfo};
type TagSigningInfo = {
delegations: DelegationInfo[];
delegationsByName: {[delegationName: string]: DelegationInfo};
hasExpiringSoon: boolean;
hasExpired: boolean;
hasInvalid: boolean;
}
type delegationInfo = {
type DelegationInfo = {
delegationName: string;
delegationHash: string;
expiration: moment.Moment;
@ -20,7 +20,7 @@ type delegationInfo = {
isExpiringSoon: boolean
};
var RELEASES = 'targets/releases';
var RELEASES = ['targets/releases', 'targets'];
/**
* A component that displays the signing status of a tag in the repository view.
@ -34,13 +34,18 @@ export class TagSigningDisplayComponent {
@Input('<') public tag: any;
@Input('<') public delegations: ApostilleDelegationsSet;
private cachedSigningInfo: tagSigningInfo | null = null;
private cachedSigningInfo: TagSigningInfo | null = null;
constructor(@Inject("$sanitize") private $sanitize: ng.sanitize.ISanitizeService) {}
private base64ToHex(base64String: string): string {
// Based on: http://stackoverflow.com/questions/39460182/decode-base64-to-hexadecimal-string-with-javascript
try {
var raw = atob(base64String);
} catch (e) {
return '(invalid)';
}
var hexString = '';
for (var i = 0; i < raw.length; ++i) {
var char = raw.charCodeAt(i);
@ -50,7 +55,7 @@ export class TagSigningDisplayComponent {
return hexString;
}
private buildDelegationInfo(tag: any, delegationName: string, delegation: ApostilleSignatureDocument): delegationInfo {
private buildDelegationInfo(tag: any, delegationName: string, delegation: ApostilleSignatureDocument): DelegationInfo {
var digest_without_prefix = tag.manifest_digest.substr('sha256:'.length);
var hex_signature = this.base64ToHex(delegation.targets[tag.name].hashes['sha256']);
@ -68,7 +73,7 @@ export class TagSigningDisplayComponent {
}
}
private buildTagSigningInfo(tag: any, delegationSet: ApostilleDelegationsSet): tagSigningInfo {
private buildTagSigningInfo(tag: any, delegationSet: ApostilleDelegationsSet): TagSigningInfo {
var info = {
'delegations': [],
'delegationsByName': {},
@ -81,19 +86,19 @@ export class TagSigningDisplayComponent {
Object.keys(delegationSet.delegations).forEach((delegationName) => {
var delegation = delegationSet.delegations[delegationName];
if (delegation.targets[tag.name]) {
var delegationInfo = this.buildDelegationInfo(tag, delegationName, delegation)
info.delegations.push(delegationInfo);
info.delegationsByName[delegationName] = delegationInfo;
var DelegationInfo = this.buildDelegationInfo(tag, delegationName, delegation)
info.delegations.push(DelegationInfo);
info.delegationsByName[delegationName] = DelegationInfo;
if (delegationInfo.isExpired) {
if (DelegationInfo.isExpired) {
info.hasExpired = true;
}
if (delegationInfo.isExpiringSoon) {
if (DelegationInfo.isExpiringSoon) {
info.hasExpiringSoon = true;
}
if (!delegationInfo.hasMatchingHash) {
if (!DelegationInfo.hasMatchingHash) {
info.hasInvalid = true;
}
}
@ -102,7 +107,11 @@ export class TagSigningDisplayComponent {
return info;
}
private getSigningInfo(tag: any, delegationSet: ApostilleDelegationsSet): tagSigningInfo {
private isDefaultDelegation(name: string): boolean {
return RELEASES.indexOf(name) >= 0;
}
private getSigningInfo(tag: any, delegationSet: ApostilleDelegationsSet): TagSigningInfo {
if (!this.cachedSigningInfo) {
this.cachedSigningInfo = this.buildTagSigningInfo(tag, delegationSet);
}
@ -141,8 +150,15 @@ export class TagSigningDisplayComponent {
allReleasesValid = allReleasesValid && isValid;
});
// Check if the special RELEASES target is signed and valid.
var releasesDelegation = this.cachedSigningInfo.delegationsByName[RELEASES];
// Check if the special RELEASES target(s) is/are signed and valid.
var releasesDelegation = null;
RELEASES.forEach((releaseTarget) => {
var delegation = this.cachedSigningInfo.delegationsByName[releaseTarget];
if (delegation && !releasesDelegation) {
releasesDelegation = delegation;
}
});
if (releasesDelegation && releasesDelegation.hasMatchingHash && !releasesDelegation.isExpired) {
if (allReleasesValid && this.cachedSigningInfo.delegations.length > 1) {
return 'all-signed';
@ -151,14 +167,10 @@ export class TagSigningDisplayComponent {
}
}
if (allReleasesValid) {
if (allReleasesValid || oneReleaseValid) {
return 'non-release-signed';
}
if (oneReleaseValid) {
return 'one-valid-signed';
}
return 'invalid-signed';
}
}