Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/log/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import bunyan from 'bunyan';
import { getLogLevel } from '../configuration';

Expand Down
24 changes: 14 additions & 10 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions app/registries/BaseRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-nocheck
import { AxiosRequestConfig } from 'axios';
import { ContainerImage } from '../model/container';
import Registry from './Registry';

/**
Expand All @@ -8,7 +9,10 @@ class BaseRegistry extends Registry {
/**
* Common URL normalization for registries that need https:// prefix and /v2 suffix
*/
normalizeImageUrl(image, registryUrl = null) {
normalizeImageUrl(
image: ContainerImage,
registryUrl: string | null = null,
) {
const imageNormalized = { ...image };
const url = registryUrl || image.registry.url;

Expand All @@ -21,7 +25,10 @@ class BaseRegistry extends Registry {
/**
* Common Basic Auth implementation
*/
async authenticateBasic(requestOptions, credentials) {
async authenticateBasic(
requestOptions: AxiosRequestConfig,
credentials?: string,
) {
const requestOptionsWithAuth = { ...requestOptions };
if (credentials) {
requestOptionsWithAuth.headers.Authorization = `Basic ${credentials}`;
Expand All @@ -32,7 +39,10 @@ class BaseRegistry extends Registry {
/**
* Common Bearer token authentication
*/
async authenticateBearer(requestOptions, token) {
async authenticateBearer(
requestOptions: AxiosRequestConfig,
token?: string,
) {
const requestOptionsWithAuth = { ...requestOptions };
if (token) {
requestOptionsWithAuth.headers.Authorization = `Bearer ${token}`;
Expand Down Expand Up @@ -78,14 +88,14 @@ class BaseRegistry extends Registry {
/**
* Common URL pattern matching
*/
matchUrlPattern(image, pattern) {
return pattern.test(image.registry.url);
matchUrlPattern(imageUrl: string, pattern: RegExp) {
return pattern.test(imageUrl);
}

/**
* Common mask configuration for sensitive fields
*/
maskSensitiveFields(fields) {
maskSensitiveFields(fields: string[]) {
const masked = { ...this.configuration };
fields.forEach((field) => {
if (masked[field]) {
Expand Down
24 changes: 23 additions & 1 deletion app/registries/Registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('getId should return registry type only', async () => {
});

test('match should return false when not overridden', async () => {
expect(registry.match({})).toBeFalsy();
expect(registry.match('')).toBeFalsy();
});

test('normalizeImage should return same image when not overridden', async () => {
Expand Down Expand Up @@ -288,3 +288,25 @@ test('callRegistry should call authenticate', async () => {
});
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
});

describe('shouldWatchDigest', () => {
test('should return true when label is true', () => {
const result = registry.shouldWatchDigest('true', 'image/name');
expect(result).toBe(true);
});

test('should return true when label is TRUE (case insensitive)', () => {
const result = registry.shouldWatchDigest('TRUE', 'image/name');
expect(result).toBe(true);
});

test('should return true without label', () => {
const result = registry.shouldWatchDigest(undefined, 'image/name');
expect(result).toBe(true);
});

test('should return true with empty label', () => {
const result = registry.shouldWatchDigest('', 'image/name');
expect(result).toBe(true);
});
});
37 changes: 10 additions & 27 deletions app/registries/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import Component from '../registry/Component';
import { getSummaryTags } from '../prometheus/registry';
import { ContainerImage } from '../model/container';

export interface RegistryImage extends ContainerImage {
// Add any registry specific properties if needed
}

export interface RegistryManifest {
digest?: string;
version?: number;
Expand Down Expand Up @@ -43,40 +39,37 @@ export interface RegistryManifestResponse {
/**
* Docker Registry Abstract class.
*/
class Registry extends Component {
export class Registry extends Component {
/**
* Encode Bse64(login:password)
* @param login
* @param token
* @returns {string}
*/
static base64Encode(login: string, token: string) {
return Buffer.from(`${login}:${token}`, 'utf-8').toString('base64');
}

/**
* If this registry is responsible for the image (to be overridden).
* @param image the image
* @returns {boolean}
* Check if the digest label value is to be watched for this registry (to be overridden).
*/
match(_image: ContainerImage): boolean {
shouldWatchDigest(_wudWatchDigestLabelValue: string, _image: string) {
return true;
}

/**
* If this registry is responsible for the image url (to be overridden).
*/
match(_imageUrl: string): boolean {
return false;
}

/**
* Normalize image according to Registry Custom characteristics (to be overridden).
* @param image
* @returns {*}
*/
normalizeImage(image: ContainerImage): ContainerImage {
return image;
}

/**
* Authenticate and set authentication value to requestOptions.
* @param image
* @param requestOptions
* @returns {*}
*/
async authenticate(
_image: ContainerImage,
Expand All @@ -87,8 +80,6 @@ class Registry extends Component {

/**
* Get Tags.
* @param image
* @returns {*}
*/
async getTags(image: ContainerImage): Promise<string[]> {
this.log.debug(`Get ${image.name} tags`);
Expand Down Expand Up @@ -118,9 +109,6 @@ class Registry extends Component {

/**
* Get tags page
* @param image
* @param lastItem
* @returns {Promise<*>}
*/
getTagsPage(
image: ContainerImage,
Expand All @@ -139,9 +127,6 @@ class Registry extends Component {

/**
* Get image manifest for a remote tag.
* @param image
* @param digest (optional)
* @returns {Promise<undefined|*>}
*/
async getImageManifestDigest(
image: ContainerImage,
Expand Down Expand Up @@ -375,9 +360,7 @@ class Registry extends Component {

/**
* Return {username, pass } or undefined.
* @returns {}
*/

async getAuthPull(): Promise<
{ username?: string; password?: string } | undefined
> {
Expand Down
Loading