How to use the @kui-shell/core.Util.expandHomeDir function in @kui-shell/core

To help you get started, we’ve selected a few @kui-shell/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / openwhisk-core.ts View on Github external
// paramValue = paramValue.replace(new RegExp(startQuote, 'g'), '')
  }

  if (paramValue.charAt(0) === '$') {
    paramValue = process.env[paramValue]
  }

  if (paramValue.charAt(0) === '@') {
    // this is an @file form of parameter. read in the file
    // !!!!!!! FIXME cap the size of the file to avoid bombing out
    if (paramValue.charAt(1) === '$') {
      debug('filename from env var', paramValue.substring(2))
      paramValue = `@${process.env[paramValue.substring(2)]}`
    }

    const location = Util.expandHomeDir(paramValue.substring(1))
    if (!existsSync(location)) {
      throw new Error(`Requested parameter @file does not exist: ${location}`)
    } else {
      const extension = location.substring(location.lastIndexOf('.') + 1)
      const encoding = isBinary[extension] ? 'base64' : 'utf8'
      debug('encoding', encoding)

      paramValue = readFileSync(location).toString(encoding)
    }
  }

  // see if the value is JSON
  try {
    paramValue = JSON.parse(paramValue)
  } catch (e) {
    // console.error('NOT JSON', paramValue, typeof paramValue, argv)
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / actions / let.ts View on Github external
location: string,
  text: string,
  options,
  execOptions: Commands.ExecOptions
) => {
  const extensionWithoutDot = extension.substring(1)
  const action = Object.assign({}, options.action, {
    exec: { kind: 'nodejs:default' }
  })

  // add annotations
  if (!action.annotations) {
    action.annotations = []
  }
  ;(annotators[extension] || []).forEach(annotator => annotator(action))
  action.annotations.push({ key: 'file', value: Util.expandHomeDir(location) })

  // add an annotation to indicate that this is a managed action
  action.annotations.push({
    key: 'wskng.combinators',
    value: [
      {
        type: 'web',
        role: 'replacement',
        badge: 'web',
        contentType: extensionWithoutDot
      }
    ]
  })

  action.exec.code = webAssetTransformer(location, text, extension)
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / actions / let.ts View on Github external
} else if (extension === '.ico') {
    headers = 'headers: { "content-type": "image/x-icon" },'
    contentType = 'body'
    xform = base64
  } else if (extension === '.jpg' || extension === '.jpeg') {
    headers = 'headers: { "content-type": "image/jpeg" },'
    contentType = 'body'
    xform = base64
  }

  return (
    "const stripSlash = s => s.substring(0, s.lastIndexOf('/'))\n" +
    'const getHostRelativeRoot = () => `/api/v1/web${stripSlash(stripSlash(process.env.__OW_ACTION_NAME))}`\n' + // eslint-disable-line no-template-curly-in-string
    'const getReferer = hostRelativeRoot => `${process.env.__OW_API_HOST}${hostRelativeRoot}`\n' + // eslint-disable-line no-template-curly-in-string
    `function main(params) { const hostRelativeRoot = getHostRelativeRoot(); const referer = getReferer(hostRelativeRoot); const getParams = () => { delete params.__ow_headers; delete params.__ow_path; delete params.__ow_method; return params; }; return { ${headers} ${contentType}: \`` +
    xform(text || readFileSync(Util.expandHomeDir(location))) +
    '`} }'
  )
}
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / actions / let.ts View on Github external
annotations: (options.action && options.action.annotations) || [],
                parameters: (options.action && options.action.parameters) || [],
                limits: (options.action && options.action.limits) || {}
              }
              debug('body', action)

              const owOpts = wskOpts({
                name,
                // options.action may be defined, if the command has e.g. -a or -p
                action
              })

              // location on local filesystem
              owOpts.action.annotations.push({
                key: 'file',
                value: Util.expandHomeDir(location)
              })

              // add an annotation to indicate that this is a managed action
              owOpts.action.annotations.push({
                key: 'wskng.combinators',
                value: [
                  {
                    type: 'action.kind',
                    role: 'replacement',
                    badge: 'zip'
                  }
                ]
              })

              // broadcast that this is a binary action
              owOpts.action.annotations.push({ key: 'binary', value: true })
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / auth.ts View on Github external
const wskpropsFile = (): string => {
  return Util.expandHomeDir(process.env.WSK_CONFIG_FILE || '~/.wskprops')
}