--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { Resource } from '~/models/resource';
+
+export interface SshKey {
+ name: string;
+ keyType: KeyType;
+ authorizedUserUuid: string;
+ publicKey: string;
+ expiresAt: string;
+}
+
+export interface SshKeyCreateFormDialogData {
+ publicKey: string;
+ name: string;
+}
+
+export enum KeyType {
+ SSH = 'SSH'
+}
+
+export interface SshKeyResource extends Resource {
+ name: string;
+ keyType: KeyType;
+ authorizedUserUuid: string;
+ publicKey: string;
+ expiresAt: string;
+}
\ No newline at end of file
import { History, Location } from 'history';
import { RootStore } from '~/store/store';
-import { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute, matchSearchResultsRoute } from './routes';
-import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog } from '~/store/workbench/workbench-actions';
+import { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute, matchSearchResultsRoute, matchSshKeysRoute } from './routes';
+import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog, loadSshKeys } from '~/store/workbench/workbench-actions';
import { navigateToRootProject } from '~/store/navigation/navigation-action';
import { loadSharedWithMe, loadRunProcess, loadWorkflow, loadSearchResults } from '~//store/workbench/workbench-actions';
const sharedWithMeMatch = matchSharedWithMeRoute(pathname);
const runProcessMatch = matchRunProcessRoute(pathname);
const workflowMatch = matchWorkflowRoute(pathname);
+ const sshKeysMatch = matchSshKeysRoute(pathname);
if (projectMatch) {
store.dispatch(loadProject(projectMatch.params.id));
store.dispatch(loadWorkflow);
} else if (searchResultsMatch) {
store.dispatch(loadSearchResults);
+ } else if (sshKeysMatch) {
+ store.dispatch(loadSshKeys);
}
};
SHARED_WITH_ME: '/shared-with-me',
RUN_PROCESS: '/run-process',
WORKFLOWS: '/workflows',
- SEARCH_RESULTS: '/search-results'
+ SEARCH_RESULTS: '/search-results',
+ SSH_KEYS: `/ssh-keys`
};
export const getResourceUrl = (uuid: string) => {
export const matchSearchResultsRoute = (route: string) =>
matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
+
+export const matchSshKeysRoute = (route: string) =>
+ matchPath(route, { path: Routes.SSH_KEYS });
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { AxiosInstance } from "axios";
+import { SshKeyResource } from '~/models/ssh-key';
+import { CommonResourceService } from "~/services/common-service/common-resource-service";
+import { ApiActions } from "~/services/api/api-actions";
+
+export class AuthorizedKeysService extends CommonResourceService<SshKeyResource> {
+ constructor(serverApi: AxiosInstance, actions: ApiActions) {
+ super(serverApi, "authorized_keys", actions);
+ }
+}
\ No newline at end of file
UNIQUE_VIOLATION = 'UniqueViolation',
OWNERSHIP_CYCLE = 'OwnershipCycle',
MODIFYING_CONTAINER_REQUEST_FINAL_STATE = 'ModifyingContainerRequestFinalState',
+ UNIQUE_PUBLIC_KEY = 'UniquePublicKey',
+ INVALID_PUBLIC_KEY = 'InvalidPublicKey',
UNKNOWN = 'Unknown',
NONE = 'None'
}
return CommonResourceServiceError.OWNERSHIP_CYCLE;
case /Mounts cannot be modified in state 'Final'/.test(error):
return CommonResourceServiceError.MODIFYING_CONTAINER_REQUEST_FINAL_STATE;
+ case /Public key does not appear to be a valid ssh-rsa or dsa public key/.test(error):
+ return CommonResourceServiceError.INVALID_PUBLIC_KEY;
+ case /Public key already exists in the database, use a different key./.test(error):
+ return CommonResourceServiceError.UNIQUE_PUBLIC_KEY;
default:
return CommonResourceServiceError.UNKNOWN;
}
import { WorkflowService } from "~/services/workflow-service/workflow-service";
import { SearchService } from '~/services/search-service/search-service';
import { PermissionService } from "~/services/permission-service/permission-service";
+import { AuthorizedKeysService } from '~/services/authorized-keys-service/authorized-keys-service';
export type ServiceRepository = ReturnType<typeof createServices>;
const webdavClient = new WebDAV();
webdavClient.defaults.baseURL = config.keepWebServiceUrl;
+ const authorizedKeysService = new AuthorizedKeysService(apiClient, actions);
const containerRequestService = new ContainerRequestService(apiClient, actions);
const containerService = new ContainerService(apiClient, actions);
const groupsService = new GroupsService(apiClient, actions);
ancestorsService,
apiClient,
authService,
+ authorizedKeysService,
collectionFilesService,
collectionService,
containerRequestService,
import { ofType, unionize, UnionOf } from '~/common/unionize';
import { Dispatch } from "redux";
+import { reset, stopSubmit } from 'redux-form';
import { User } from "~/models/user";
import { RootState } from "../store";
import { ServiceRepository } from "~/services/services";
+import { getCommonResourceServiceError, CommonResourceServiceError } from '~/services/common-service/common-resource-service';
import { AxiosInstance } from "axios";
+import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { dialogActions } from '~/store/dialog/dialog-actions';
+import { SshKeyCreateFormDialogData, SshKey, KeyType } from '~/models/ssh-key';
+import { setBreadcrumbs } from '../breadcrumbs/breadcrumbs-actions';
export const authActions = unionize({
SAVE_API_TOKEN: ofType<string>(),
LOGOUT: {},
INIT: ofType<{ user: User, token: string }>(),
USER_DETAILS_REQUEST: {},
- USER_DETAILS_SUCCESS: ofType<User>()
+ USER_DETAILS_SUCCESS: ofType<User>(),
+ SET_SSH_KEYS: ofType<SshKey[]>(),
+ ADD_SSH_KEY: ofType<SshKey>()
});
+export const SSH_KEY_CREATE_FORM_NAME = 'sshKeyCreateFormName';
+
function setAuthorizationHeader(services: ServiceRepository, token: string) {
services.apiClient.defaults.headers.common = {
Authorization: `OAuth2 ${token}`
});
};
+export const openSshKeyCreateDialog = () => dialogActions.OPEN_DIALOG({ id: SSH_KEY_CREATE_FORM_NAME, data: {} });
+
+export const createSshKey = (data: SshKeyCreateFormDialogData) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ try {
+ const userUuid = getState().auth.user!.uuid;
+ const { name, publicKey } = data;
+ const newSshKey = await services.authorizedKeysService.create({
+ name,
+ publicKey,
+ keyType: KeyType.SSH,
+ authorizedUserUuid: userUuid
+ });
+ dispatch(dialogActions.CLOSE_DIALOG({ id: SSH_KEY_CREATE_FORM_NAME }));
+ dispatch(reset(SSH_KEY_CREATE_FORM_NAME));
+ dispatch(authActions.ADD_SSH_KEY(newSshKey));
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: "Public key has been successfully created.",
+ hideDuration: 2000
+ }));
+ } catch (e) {
+ const error = getCommonResourceServiceError(e);
+ if (error === CommonResourceServiceError.UNIQUE_PUBLIC_KEY) {
+ dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key already exists.' }));
+ } else if (error === CommonResourceServiceError.INVALID_PUBLIC_KEY) {
+ dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key is invalid' }));
+ }
+ }
+ };
+
+export const loadSshKeysPanel = () =>
+ async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ try {
+ dispatch(setBreadcrumbs([{ label: 'SSH Keys'}]));
+ const response = await services.authorizedKeysService.list();
+ dispatch(authActions.SET_SSH_KEYS(response.items));
+ } catch (e) {
+ return;
+ }
+ };
+
+
export type AuthAction = UnionOf<typeof authActions>;
import { authActions, AuthAction } from "./auth-action";
import { User } from "~/models/user";
import { ServiceRepository } from "~/services/services";
+import { SshKey } from '~/models/ssh-key';
export interface AuthState {
user?: User;
apiToken?: string;
+ sshKeys?: SshKey[];
}
-export const authReducer = (services: ServiceRepository) => (state: AuthState = {}, action: AuthAction) => {
+const initialState: AuthState = {
+ user: undefined,
+ apiToken: undefined,
+ sshKeys: []
+};
+
+export const authReducer = (services: ServiceRepository) => (state: AuthState = initialState, action: AuthAction) => {
return authActions.match(action, {
SAVE_API_TOKEN: (token: string) => {
return {...state, apiToken: token};
USER_DETAILS_SUCCESS: (user: User) => {
return {...state, user};
},
+ SET_SSH_KEYS: (sshKeys: SshKey[]) => {
+ return {...state, sshKeys};
+ },
+ ADD_SSH_KEY: (sshKey: SshKey) => {
+ return { ...state, sshKeys: state.sshKeys!.concat(sshKey) };
+ },
default: () => state
});
};
export const navigateToRunProcess = push(Routes.RUN_PROCESS);
export const navigateToSearchResults = push(Routes.SEARCH_RESULTS);
+
+export const navigateToSshKeys= push(Routes.SSH_KEYS);
\ No newline at end of file
import { loadSharedWithMePanel } from '../shared-with-me-panel/shared-with-me-panel-actions';
import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
+import { loadSshKeysPanel } from '~/store/auth/auth-action';
import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
import { getProgressIndicator } from '../progress-indicator/progress-indicator-reducer';
await dispatch(loadSearchResultsPanel());
});
+export const loadSshKeys = handleFirstTimeLoad(
+ async (dispatch: Dispatch<any>) => {
+ await dispatch(loadSshKeysPanel());
+ });
+
const finishLoadingProject = (project: GroupContentsResource | string) =>
async (dispatch: Dispatch<any>) => {
const uuid = typeof project === 'string' ? project : project.uuid;
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+
+const ERROR_MESSAGE = 'Public key is invalid';
+
+export const isRsaKey = (value: any) => {
+ return value.match(/ssh-rsa AAAA[0-9A-Za-z+/]+[=]{0,3} ([^@]+@[^@]+)/i) ? undefined : ERROR_MESSAGE;
+};
import { require } from './require';
import { maxLength } from './max-length';
+import { isRsaKey } from './is-rsa-key';
export const TAG_KEY_VALIDATION = [require, maxLength(255)];
export const TAG_VALUE_VALIDATION = [require, maxLength(255)];
export const MOVE_TO_VALIDATION = [require];
-export const PROCESS_NAME_VALIDATION = [require, maxLength(255)];
\ No newline at end of file
+export const PROCESS_NAME_VALIDATION = [require, maxLength(255)];
+
+export const SSH_KEY_PUBLIC_VALIDATION = [require, isRsaKey, maxLength(1024)];
+export const SSH_KEY_NAME_VALIDATION = [require, maxLength(255)];
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { InjectedFormProps } from 'redux-form';
+import { WithDialogProps } from '~/store/dialog/with-dialog';
+import { FormDialog } from '~/components/form-dialog/form-dialog';
+import { SshKeyPublicField, SshKeyNameField } from '~/views-components/form-fields/ssh-key-form-fields';
+import { SshKeyCreateFormDialogData } from '~/models/ssh-key';
+
+type DialogSshKeyProps = WithDialogProps<{}> & InjectedFormProps<SshKeyCreateFormDialogData>;
+
+export const DialogSshKeyCreate = (props: DialogSshKeyProps) =>
+ <FormDialog
+ dialogTitle='Add new SSH key'
+ formFields={SshKeyAddFields}
+ submitLabel='Add new ssh key'
+ {...props}
+ />;
+
+const SshKeyAddFields = () => <span>
+ <SshKeyPublicField />
+ <SshKeyNameField />
+</span>;
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { compose } from "redux";
+import { reduxForm } from 'redux-form';
+import { withDialog } from "~/store/dialog/with-dialog";
+import { SSH_KEY_CREATE_FORM_NAME, createSshKey } from '~/store/auth/auth-action';
+import { DialogSshKeyCreate } from '~/views-components/dialog-create/dialog-ssh-key-create';
+import { SshKeyCreateFormDialogData } from '~/models/ssh-key';
+
+export const CreateSshKeyDialog = compose(
+ withDialog(SSH_KEY_CREATE_FORM_NAME),
+ reduxForm<SshKeyCreateFormDialogData>({
+ form: SSH_KEY_CREATE_FORM_NAME,
+ onSubmit: (data, dispatch) => {
+ dispatch(createSshKey(data));
+ }
+ })
+)(DialogSshKeyCreate);
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { Field } from "redux-form";
+import { TextField } from "~/components/text-field/text-field";
+import { SSH_KEY_PUBLIC_VALIDATION, SSH_KEY_NAME_VALIDATION } from "~/validators/validators";
+
+export const SshKeyPublicField = () =>
+ <Field
+ name='publicKey'
+ component={TextField}
+ validate={SSH_KEY_PUBLIC_VALIDATION}
+ autoFocus={true}
+ label="Public Key" />;
+
+export const SshKeyNameField = () =>
+ <Field
+ name='name'
+ component={TextField}
+ validate={SSH_KEY_NAME_VALIDATION}
+ label="Name" />;
+
+
import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
import { UserPanelIcon } from "~/components/icon/icon";
import { DispatchProp, connect } from 'react-redux';
-import { logout } from "~/store/auth/auth-action";
+import { logout } from '~/store/auth/auth-action';
import { RootState } from "~/store/store";
import { openCurrentTokenDialog } from '../../store/current-token-dialog/current-token-dialog-actions';
+import { navigateToSshKeys } from '~/store/navigation/navigation-action';
interface AccountMenuProps {
user?: User;
{getUserFullname(user)}
</MenuItem>
<MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
+ <MenuItem onClick={() => dispatch(navigateToSshKeys)}>Ssh Keys</MenuItem>
<MenuItem>My account</MenuItem>
<MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
</DropdownMenu>
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { StyleRulesCallback, WithStyles, withStyles, Card, CardContent, Button, Typography } from '@material-ui/core';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { SshKey } from '~/models/ssh-key';
+
+
+type CssRules = 'root' | 'link';
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+ root: {
+ width: '100%'
+ },
+ link: {
+ color: theme.palette.primary.main,
+ textDecoration: 'none',
+ margin: '0px 4px'
+ }
+});
+
+export interface SshKeyPanelRootActionProps {
+ onClick: () => void;
+}
+
+export interface SshKeyPanelRootDataProps {
+ sshKeys?: SshKey[];
+}
+
+type SshKeyPanelRootProps = SshKeyPanelRootDataProps & SshKeyPanelRootActionProps & WithStyles<CssRules>;
+
+export const SshKeyPanelRoot = withStyles(styles)(
+ ({ classes, sshKeys, onClick }: SshKeyPanelRootProps) =>
+ <Card className={classes.root}>
+ <CardContent>
+ <Typography variant='body1' paragraph={true}>
+ You have not yet set up an SSH public key for use with Arvados.
+ <a href='https://doc.arvados.org/user/getting_started/ssh-access-unix.html' target='blank' className={classes.link}>
+ Learn more.
+ </a>
+ </Typography>
+ <Typography variant='body1' paragraph={true}>
+ When you have an SSH key you would like to use, add it using button below.
+ </Typography>
+ <Button
+ onClick={onClick}
+ color="primary"
+ variant="contained">
+ Add New Ssh Key
+ </Button>
+ </CardContent>
+ </Card>
+ );
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { RootState } from '~/store/store';
+import { Dispatch } from 'redux';
+import { connect } from 'react-redux';
+import { SshKeyPanelRoot, SshKeyPanelRootDataProps, SshKeyPanelRootActionProps } from '~/views/ssh-key-panel/ssh-key-panel-root';
+import { openSshKeyCreateDialog } from '~/store/auth/auth-action';
+
+const mapStateToProps = (state: RootState): SshKeyPanelRootDataProps => {
+ return {
+ sshKeys: state.auth.sshKeys
+ };
+};
+
+const mapDispatchToProps = (dispatch: Dispatch): SshKeyPanelRootActionProps => ({
+ onClick: () => {
+ dispatch(openSshKeyCreateDialog());
+ }
+});
+
+export const SshKeyPanel = connect(mapStateToProps, mapDispatchToProps)(SshKeyPanelRoot);
\ No newline at end of file
import SplitterLayout from 'react-splitter-layout';
import { WorkflowPanel } from '~/views/workflow-panel/workflow-panel';
import { SearchResultsPanel } from '~/views/search-results-panel/search-results-panel';
+import { SshKeyPanel } from '~/views/ssh-key-panel/ssh-key-panel';
import { SharingDialog } from '~/views-components/sharing-dialog/sharing-dialog';
import { AdvancedTabDialog } from '~/views-components/advanced-tab-dialog/advanced-tab-dialog';
import { ProcessInputDialog } from '~/views-components/process-input-dialog/process-input-dialog';
import { ProjectPropertiesDialog } from '~/views-components/project-properties-dialog/project-properties-dialog';
+import { CreateSshKeyDialog } from '~/views-components/dialog-forms/create-ssh-key-dialog';
type CssRules = 'root' | 'container' | 'splitter' | 'asidePanel' | 'contentWrapper' | 'content';
<Route path={Routes.RUN_PROCESS} component={RunProcessPanel} />
<Route path={Routes.WORKFLOWS} component={WorkflowPanel} />
<Route path={Routes.SEARCH_RESULTS} component={SearchResultsPanel} />
+ <Route path={Routes.SSH_KEYS} component={SshKeyPanel} />
</Switch>
</Grid>
</Grid>
<CopyProcessDialog />
<CreateCollectionDialog />
<CreateProjectDialog />
+ <CreateSshKeyDialog />
<CurrentTokenDialog />
<FileRemoveDialog />
<FilesUploadCollectionDialog />