All files / utils kernels.ts

92.85% Statements 13/14
100% Branches 11/11
100% Functions 1/1
92.85% Lines 13/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 272x 2x     2x       170x 170x 1x     169x 169x 169x   169x 169x 169x   169x          
import isString from 'lodash/isString';
import { KERNELSPEC_NAME_SEPARATOR } from '../constants';
import { ParsedSpecName } from '../types';
 
export function parseSpecName(name: string | undefined): ParsedSpecName {
  // Parse a kernelspec into different parts
  // Example kernelspec: kernelname__SAGEMAKER_INTERNAL__arn:aws:sagemaker:region:account:image/imagename/version
  // Parsed result: { kernel: kernelname, arnEnvironment: arn:aws:sagemaker:region:account:image/imagename/version, version: version }
  try {
    if (!isString(name) || name.length === 0) {
      return { kernel: null, arnEnvironment: null, version: null };
    }
 
    const splitName = name.split(KERNELSPEC_NAME_SEPARATOR);
    const [kernel, environment] = splitName;
    const splitEnv = environment && environment.split('/');
 
    const arnEnvironment = splitEnv && splitEnv[0] + '/' + splitEnv[1];
    const version = splitEnv.length === 3 ? splitEnv[2] : null;
    const arnEnvironmentWithVersion = version ? `${arnEnvironment}/${version}` : arnEnvironment;
 
    return { kernel, arnEnvironment: arnEnvironmentWithVersion, version };
  } catch (e) {
    return { kernel: null, arnEnvironment: null, version: null };
  }
}