-
Notifications
You must be signed in to change notification settings - Fork 22
Add deb repository and remote pages #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
warisshaikh1
wants to merge
9
commits into
pulp:main
Choose a base branch
from
warisshaikh1:deb-repositories-and-remotes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cc56db4
Add deb repository and remote pages
warisshaikh1 881e49e
Page through the distributions of a deb repository being deleted
warisshaikh1 2f2e296
Default a deb sync to mirror: false, as pulp_deb does
warisshaikh1 728eced
Turn an empty deb detail lookup into a not-found rejection
warisshaikh1 c4fa93c
Collapse the deb repository breadcrumb branches
warisshaikh1 a14567c
Resolve the remote API through plugin2api
warisshaikh1 b3a2811
Stop stubbing hasObjectPermission on deb distributions
warisshaikh1 15cd87f
Describe the deb remote and repository as interfaces
warisshaikh1 9ce27a7
Add smoke tests for the deb pages
warisshaikh1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { msg } from '@lingui/core/macro'; | ||
| import { Paths, formatPath } from 'src/paths'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRemoteCreateAction = Action({ | ||
| title: msg`Add remote`, | ||
| onClick: (item, { navigate }) => | ||
| navigate(formatPath(Paths.deb.remote.edit, { name: '_' })), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { msg, t } from '@lingui/core/macro'; | ||
| import { DebRemoteAPI } from 'src/api'; | ||
| import { DeleteRemoteModal } from 'src/components'; | ||
| import { | ||
| handleHttpError, | ||
| parsePulpIDFromURL, | ||
| taskAlert, | ||
| waitForTaskUrl, | ||
| } from 'src/utilities'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRemoteDeleteAction = Action({ | ||
| title: msg`Delete`, | ||
| modal: ({ addAlert, listQuery, setState, state }) => | ||
| state.deleteModalOpen ? ( | ||
| <DeleteRemoteModal | ||
| closeAction={() => setState({ deleteModalOpen: null })} | ||
| deleteAction={() => | ||
| deleteRemote(state.deleteModalOpen, { addAlert, setState, listQuery }) | ||
| } | ||
| name={state.deleteModalOpen.name} | ||
| /> | ||
| ) : null, | ||
| onClick: ( | ||
| { name, id, pulp_href }: { name: string; id?: string; pulp_href?: string }, | ||
| { setState }, | ||
| ) => | ||
| setState({ | ||
| deleteModalOpen: { pulpId: id || parsePulpIDFromURL(pulp_href), name }, | ||
| }), | ||
| }); | ||
|
|
||
| function deleteRemote({ name, pulpId }, { addAlert, setState, listQuery }) { | ||
| return DebRemoteAPI.delete(pulpId) | ||
| .then(({ data }) => { | ||
| addAlert(taskAlert(data.task, t`Removal started for remote ${name}`)); | ||
| setState({ deleteModalOpen: null }); | ||
| return waitForTaskUrl(data.task); | ||
| }) | ||
| .then(() => listQuery()) | ||
| .catch( | ||
| handleHttpError(t`Failed to remove remote ${name}`, () => null, addAlert), | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { msg } from '@lingui/core/macro'; | ||
| import { Paths, formatPath } from 'src/paths'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRemoteEditAction = Action({ | ||
| title: msg`Edit`, | ||
| onClick: ({ name }, { navigate }) => | ||
| navigate(formatPath(Paths.deb.remote.edit, { name })), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { msg } from '@lingui/core/macro'; | ||
| import { Paths, formatPath } from 'src/paths'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRepositoryCreateAction = Action({ | ||
| title: msg`Add repository`, | ||
| onClick: (item, { navigate }) => | ||
| navigate(formatPath(Paths.deb.repository.edit, { name: '_' })), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { msg, t } from '@lingui/core/macro'; | ||
| import { DebDistributionAPI, DebRepositoryAPI } from 'src/api'; | ||
| import { DeleteRepositoryModal } from 'src/components'; | ||
| import { | ||
| handleHttpError, | ||
| parsePulpIDFromURL, | ||
| taskAlert, | ||
| waitForTaskUrl, | ||
| } from 'src/utilities'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRepositoryDeleteAction = Action({ | ||
| title: msg`Delete`, | ||
| modal: ({ addAlert, listQuery, setState, state }) => | ||
| state.deleteModalOpen ? ( | ||
| <DeleteRepositoryModal | ||
| closeAction={() => setState({ deleteModalOpen: null })} | ||
| deleteAction={() => | ||
| deleteRepository(state.deleteModalOpen, { | ||
| addAlert, | ||
| listQuery, | ||
| setState, | ||
| }) | ||
| } | ||
| name={state.deleteModalOpen.name} | ||
| /> | ||
| ) : null, | ||
| onClick: ( | ||
| { name, id, pulp_href }: { name: string; id?: string; pulp_href?: string }, | ||
| { setState }, | ||
| ) => | ||
| setState({ | ||
| deleteModalOpen: { | ||
| pulpId: id || parsePulpIDFromURL(pulp_href), | ||
| name, | ||
| pulp_href, | ||
| }, | ||
| }), | ||
| }); | ||
|
|
||
| const DISTRIBUTION_PAGE_SIZE = 100; | ||
|
|
||
| // A repository can be serving more distributions than a single page holds, and | ||
| // any the lookup misses are left pointing at a repository that no longer exists. | ||
| async function listDistributions(repository) { | ||
| const distributions = []; | ||
| let page = 1; | ||
| let count = Infinity; | ||
|
|
||
| while (distributions.length < count) { | ||
| const { data } = await DebDistributionAPI.list({ | ||
| repository, | ||
| page, | ||
| page_size: DISTRIBUTION_PAGE_SIZE, | ||
| }); | ||
|
|
||
| // Also stops the loop should count ever disagree with what the pages return. | ||
| if (!data.results?.length) { | ||
| break; | ||
| } | ||
|
|
||
| distributions.push(...data.results); | ||
| count = data.count; | ||
| page++; | ||
| } | ||
|
|
||
| return distributions; | ||
| } | ||
|
|
||
| async function deleteRepository( | ||
| { name, pulp_href, pulpId }, | ||
| { addAlert, setState, listQuery }, | ||
| ) { | ||
| const distributionsToDelete = await listDistributions(pulp_href).catch( | ||
| (e) => { | ||
| handleHttpError( | ||
| t`Failed to list distributions, removing only the repository.`, | ||
| () => null, | ||
| addAlert, | ||
| )(e); | ||
| return []; | ||
| }, | ||
| ); | ||
|
|
||
| const deleteRepo = DebRepositoryAPI.delete(pulpId) | ||
| .then(({ data }) => { | ||
| addAlert(taskAlert(data.task, t`Removal started for repository ${name}`)); | ||
| return waitForTaskUrl(data.task); | ||
| }) | ||
| .catch( | ||
| handleHttpError( | ||
| t`Failed to remove repository ${name}`, | ||
| () => setState({ deleteModalOpen: null }), | ||
| addAlert, | ||
| ), | ||
| ); | ||
|
|
||
| const deleteDistribution = ({ name, pulp_href }) => { | ||
| const distribution_id = parsePulpIDFromURL(pulp_href); | ||
| return DebDistributionAPI.delete(distribution_id) | ||
| .then(({ data }) => { | ||
| addAlert( | ||
| taskAlert(data.task, t`Removal started for distribution ${name}`), | ||
| ); | ||
| return waitForTaskUrl(data.task); | ||
| }) | ||
| .catch( | ||
| handleHttpError( | ||
| t`Failed to remove distribution ${name}`, | ||
| () => null, | ||
| addAlert, | ||
| ), | ||
| ); | ||
| }; | ||
|
|
||
| return Promise.all([ | ||
| deleteRepo, | ||
| ...distributionsToDelete.map(deleteDistribution), | ||
| ]).then(() => { | ||
| setState({ deleteModalOpen: null }); | ||
| listQuery(); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { msg } from '@lingui/core/macro'; | ||
| import { Paths, formatPath } from 'src/paths'; | ||
| import { Action } from './action'; | ||
|
|
||
| export const debRepositoryEditAction = Action({ | ||
| title: msg`Edit`, | ||
| onClick: ({ name }, { navigate }) => | ||
| navigate(formatPath(Paths.deb.repository.edit, { name })), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { msg, t } from '@lingui/core/macro'; | ||
| import { Button, FormGroup, Modal, Switch } from '@patternfly/react-core'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { DebRepositoryAPI } from 'src/api'; | ||
| import { HelpButton, Spinner } from 'src/components'; | ||
| import { handleHttpError, parsePulpIDFromURL, taskAlert } from 'src/utilities'; | ||
| import { Action } from './action'; | ||
|
|
||
| // pulp_deb's own API default for a sync. ansible and file hardcode mirror: true | ||
| // instead, and this deliberately does not follow them: mirroring deletes local | ||
| // content the remote no longer has, so it is the direction to opt into rather | ||
| // than out of. | ||
| const DEFAULT_SYNC_PARAMS = { mirror: false, optimize: true }; | ||
|
|
||
| // otherwise as in ansible-repository-sync and file-repository-sync | ||
| const SyncModal = ({ | ||
| closeAction, | ||
| syncAction, | ||
| name, | ||
| }: { | ||
| closeAction: () => null; | ||
| syncAction: (syncParams) => Promise<void>; | ||
| name: string; | ||
| }) => { | ||
| const [pending, setPending] = useState(false); | ||
| const [syncParams, setSyncParams] = useState(DEFAULT_SYNC_PARAMS); | ||
|
|
||
| useEffect(() => { | ||
| setPending(false); | ||
| setSyncParams(DEFAULT_SYNC_PARAMS); | ||
| }, [name]); | ||
|
|
||
| if (!name) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Modal | ||
| actions={[ | ||
| <div data-cy='sync-button' key='sync'> | ||
| <Button | ||
| key='sync' | ||
| onClick={() => { | ||
| setPending(true); | ||
| syncAction(syncParams) | ||
| .then(closeAction) | ||
| .finally(() => setPending(false)); | ||
| }} | ||
| variant='primary' | ||
| isDisabled={pending} | ||
| > | ||
| {t`Sync`} | ||
| {pending && <Spinner size='sm' />} | ||
| </Button> | ||
| </div>, | ||
| <Button key='close' onClick={closeAction} variant='link'> | ||
| {t`Close`} | ||
| </Button>, | ||
| ]} | ||
| isOpen | ||
| onClose={closeAction} | ||
| title={t`Sync repository "${name}"`} | ||
| variant='medium' | ||
| > | ||
| <FormGroup | ||
| label={t`Mirror`} | ||
| labelIcon={ | ||
| <HelpButton | ||
| content={t`If selected, all content that is not present in the remote repository will be removed from the local repository; otherwise, sync will add missing content.`} | ||
| /> | ||
| } | ||
| > | ||
| <Switch | ||
| isChecked={syncParams.mirror} | ||
| onChange={(_event, mirror) => | ||
| setSyncParams({ ...syncParams, mirror }) | ||
| } | ||
| label={t`Content not present in remote repository will be removed from the local repository`} | ||
| labelOff={t`Sync will only add missing content`} | ||
| /> | ||
| </FormGroup> | ||
| <br /> | ||
| <FormGroup | ||
| label={t`Optimize`} | ||
| labelIcon={ | ||
| <HelpButton | ||
| content={t`Only perform the sync if changes are reported by the remote server. To force a sync to happen, deselect this option.`} | ||
| /> | ||
| } | ||
| > | ||
| <Switch | ||
| isChecked={syncParams.optimize} | ||
| onChange={(_event, optimize) => | ||
| setSyncParams({ ...syncParams, optimize }) | ||
| } | ||
| label={t`Only perform the sync if changes are reported by the remote server.`} | ||
| labelOff={t`Force a sync to happen.`} | ||
| /> | ||
| </FormGroup> | ||
| <br /> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export const debRepositorySyncAction = Action({ | ||
| title: msg`Sync`, | ||
| modal: ({ addAlert, query, setState, state }) => | ||
| state.syncModalOpen ? ( | ||
| <SyncModal | ||
| closeAction={() => setState({ syncModalOpen: null })} | ||
| syncAction={(syncParams) => | ||
| syncRepository(state.syncModalOpen, { addAlert, query }, syncParams) | ||
| } | ||
| name={state.syncModalOpen.name} | ||
| /> | ||
| ) : null, | ||
| onClick: ({ name, pulp_href }, { setState }) => | ||
| setState({ | ||
| syncModalOpen: { name, pulp_href }, | ||
| }), | ||
| visible: (_item, { hasPermission }) => | ||
| hasPermission('deb.change_aptrepository'), | ||
| disabled: ({ remote, last_sync_task }) => { | ||
| if (!remote) { | ||
| return t`There are no remotes associated with this repository.`; | ||
| } | ||
|
|
||
| if ( | ||
| last_sync_task && | ||
| ['running', 'waiting'].includes(last_sync_task.state) | ||
| ) { | ||
| return t`Sync task is already queued.`; | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| function syncRepository({ name, pulp_href }, { addAlert, query }, syncParams) { | ||
| const pulpId = parsePulpIDFromURL(pulp_href); | ||
| return DebRepositoryAPI.sync(pulpId, syncParams || DEFAULT_SYNC_PARAMS) | ||
| .then(({ data }) => { | ||
| addAlert(taskAlert(data.task, t`Sync started for repository "${name}".`)); | ||
|
|
||
| query(); | ||
| }) | ||
| .catch( | ||
| handleHttpError( | ||
| t`Failed to sync repository "${name}"`, | ||
| () => null, | ||
| addAlert, | ||
| ), | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MUST (mirror default): Good to see this flagged on the PR already - I'd agree it's worth resolving to match what
pulp_debdefaults to, since that's the safer, non-destruction option. Awareansibleandfilehardcodetruetoo, but I'll raise a separate issue to track.SHOULD (SyncModal duplication): Also flagged by you already - agreed this is worth doing, but I'd suggest pulling
SyncModalout into a shared component as a precursor PR rather than here, since it's identical tofileandansible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flipped to
mirror: false. It was written out in three places, so it is oneDEFAULT_SYNC_PARAMSconstant now, with a note there on why deb does not follow ansible and file.On the SyncModal duplication: agreed, and agreed it belongs in its own PR rather than this one. I will follow up with one that pulls it out for ansible and file, and drop this copy once that lands.
2f2e296
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #363 for the extraction. Once that lands I will rebase this branch on it and drop the copy here.