Skip to content

Commit

Permalink
forgotten new files
Browse files Browse the repository at this point in the history
  • Loading branch information
vitasek01 committed Dec 5, 2023
1 parent 16be1e0 commit 5397f30
Show file tree
Hide file tree
Showing 10 changed files with 827 additions and 0 deletions.
Binary file added doc/libs.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions src/components/LibArtifactCard/libraryInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Entity } from '@backstage/catalog-model';

import { Config } from '@backstage/config';
import {
ENTITY_ARTIFACT,
ENTITY_GROUP,
ENTITY_PACKAGING,
ENTITY_REPO,
ENTITY_SCOPE,
isJfrogArtifactAvailable, isJfrogRepoAvailable,
LibraryArtifact
} from "../../types";
import {
ArtifactInfo,
extractArtifactFromFullDockerName,
getDockerLatestVersion, getMavenLatestVersion, getPypiLatestVersion,
getRepositoryType,
removeDockerVersion
} from "./api";
import {generatePackageManagersCode} from "./codeSnippets";

export const DEFAULT_PROXY_PATH = '/artifactory-proxy/';

export function checkAnnotationsPresent(entity: Entity) {
const annotations = entity.metadata?.annotations;

const entityArtifact: LibraryArtifact = {
repo: annotations?.[ENTITY_REPO] || '',
group: annotations?.[ENTITY_GROUP],
artifact: annotations?.[ENTITY_ARTIFACT] || '',
packaging: annotations?.[ENTITY_PACKAGING],
scope: annotations?.[ENTITY_SCOPE],
};

if (isJfrogArtifactAvailable(entity) && !isJfrogRepoAvailable(entity)) {
throw new Error(
`Repository definition is required for JFrog artifact ${entityArtifact.artifact}`,
);
}
return entityArtifact;
}

export async function libraryInfo(
entity: Entity,
config: Config,
): Promise<ArtifactInfo> {
const artifactoryBackendProxy =
config.getOptionalString('jfrog.artifactory.proxyPath') ||
DEFAULT_PROXY_PATH;
const entityArtifact = checkAnnotationsPresent(entity);

const backendUrl = config.getString('backend.baseUrl');
const proxyUrl = `/proxy${artifactoryBackendProxy}`;
// try {
const url = `${backendUrl}/api${proxyUrl}`;

const { packageType } = await getRepositoryType(fetch, url, entityArtifact);
let version;
const artInfo = { ...entityArtifact };
switch (packageType) {
case 'docker':
const dockerInfo = await getDockerLatestVersion(
fetch,
url,
entityArtifact,
);
artInfo.stats = dockerInfo?.statsDownload;
artInfo.size = dockerInfo?.size;
artInfo.artifactFullName = removeDockerVersion(artInfo.artifact);
artInfo.lastModified = dockerInfo?.lastModified
? new Date(dockerInfo?.lastModified)
: undefined;
artInfo.artifact = extractArtifactFromFullDockerName(artInfo.artifact);
version = dockerInfo?.version;
break;
case 'pypi':
version = await getPypiLatestVersion(fetch, url, entityArtifact);
break;
default:
version = await getMavenLatestVersion(fetch, url, entityArtifact);
}

artInfo.version = version;
artInfo.packageType = packageType;

return {
lib: artInfo,
code: () => generatePackageManagersCode(artInfo, false, false),
};
// } catch (e) {
// if (e instanceof Error) {
// setError(e);
// } else {
// setError(new Error(e as string));
// }
// return '';
// }
}
35 changes: 35 additions & 0 deletions src/components/LibverPage/EntityLibraryFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
CATALOG_FILTER_EXISTS,
DefaultEntityFilters,
EntityFilter,
useEntityList,
} from '@backstage/plugin-catalog-react';
import { ENTITY_ARTIFACT } from '../../types';
import { useEffect } from 'react';

class EntityLibraryFilter implements EntityFilter {
getCatalogFilters(): Record<string, string | symbol | (string | symbol)[]> {
return {
[`metadata.annotations.${ENTITY_ARTIFACT}`]: CATALOG_FILTER_EXISTS,
};
}
}

export type CustomFilters = DefaultEntityFilters & {
libraryFilters?: EntityLibraryFilter
};

export const EntityLibraryFilterPicker = () => {
const {
updateFilters
} = useEntityList<CustomFilters>();

useEffect(() => {
const entityLibraryFilter = new EntityLibraryFilter();
updateFilters({
libraryFilters: entityLibraryFilter,
});
}, [updateFilters]);

return null;
};
74 changes: 74 additions & 0 deletions src/components/LibverPage/LibverPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
Content,
ContentHeader,
PageWithHeader,
SupportButton,
TableColumn,
TableProps,
} from '@backstage/core-components';
import {configApiRef, useApi} from '@backstage/core-plugin-api';
import {
CatalogFilterLayout,
EntityKindPicker,
EntityListProvider,
EntityOwnerPicker,
EntityTagPicker,
EntityTypePicker,
} from '@backstage/plugin-catalog-react';
import React, {ReactNode} from 'react';
import {LibverTable} from '../LibverTable';
import {EntityLibraryFilterPicker} from './EntityLibraryFilter';
import {LibverTableRow} from '../../types';

/**
* Props for root catalog pages.
* @public
*/
export interface LibverPageProps {
title?: string;
topComponents?: ReactNode;
columns?: TableColumn<LibverTableRow>[];
tableOptions?: TableProps<LibverTableRow>['options'];
}

export function LibverPageContent(props: LibverPageProps) {
return (
<EntityListProvider>
<Content>
<ContentHeader
title={props.title || 'JFrog Repository artifacts'}
// titleComponent={<EntityKindPicker initialFilter={initialKind} />}
>
{props.topComponents}
<SupportButton>All your software catalog libraries</SupportButton>
</ContentHeader>
<CatalogFilterLayout>
<CatalogFilterLayout.Filters>
<EntityKindPicker initialFilter={'Component'} hidden={true} />
<EntityLibraryFilterPicker />
<EntityTypePicker />
<EntityOwnerPicker />
<EntityTagPicker />
</CatalogFilterLayout.Filters>
<CatalogFilterLayout.Content>
<LibverTable
columns={props.columns}
tableOptions={props.tableOptions}
/>
</CatalogFilterLayout.Content>
</CatalogFilterLayout>
</Content>
</EntityListProvider>
);
}

export function LibverPage(props: LibverPageProps) {
const orgName =
useApi(configApiRef).getOptionalString('organization.name') ?? 'Backstage';

return (
<PageWithHeader title={`${orgName} Libraries`} themeId="home">
{LibverPageContent(props)}
</PageWithHeader>
);
}
2 changes: 2 additions & 0 deletions src/components/LibverPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { LibverPage } from './LibverPage';
export type { LibverPageProps } from './LibverPage';
32 changes: 32 additions & 0 deletions src/components/LibverPage/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {createExternalRouteRef,} from '@backstage/core-plugin-api';

export const createComponentRouteRef = createExternalRouteRef({
id: 'create-component',
optional: true,
});

export const viewTechDocRouteRef = createExternalRouteRef({
id: 'view-techdoc',
optional: true,
params: ['namespace', 'kind', 'name'],
});

export const rootRouteRef = createExternalRouteRef({
id: 'catalog',
});
Loading

0 comments on commit 5397f30

Please sign in to comment.