1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { AxiosInstance } from "axios";
6 import { SshKeyResource } from '~/models/ssh-key';
7 import { CommonResourceService, CommonResourceServiceError } from '~/services/common-service/common-resource-service';
8 import { ApiActions } from "~/services/api/api-actions";
10 export enum AuthorizedKeysServiceError {
11 UNIQUE_PUBLIC_KEY = 'UniquePublicKey',
12 INVALID_PUBLIC_KEY = 'InvalidPublicKey',
15 export class AuthorizedKeysService extends CommonResourceService<SshKeyResource> {
16 constructor(serverApi: AxiosInstance, actions: ApiActions) {
17 super(serverApi, "authorized_keys", actions);
21 export const getAuthorizedKeysServiceError = (errorResponse: any) => {
22 if ('errors' in errorResponse && 'errorToken' in errorResponse) {
23 const error = errorResponse.errors.join('');
25 case /Public key does not appear to be a valid ssh-rsa or dsa public key/.test(error):
26 return AuthorizedKeysServiceError.INVALID_PUBLIC_KEY;
27 case /Public key already exists in the database, use a different key./.test(error):
28 return AuthorizedKeysServiceError.UNIQUE_PUBLIC_KEY;
30 return CommonResourceServiceError.UNKNOWN;
33 return CommonResourceServiceError.NONE;