steelbrain / exec

Node's Process spawning APIs beautified
MIT License
9 stars 4 forks source link

Error importing function definition #72

Closed rutgoff closed 7 years ago

rutgoff commented 7 years ago

Per request of mschuchard author of AtomLinter/linter-puppet-lint I am cross-posting this error I receive as he believes it might be coming from sb-exec.

linter-puppet-lint version: 0.8.1 Atom Version: 1.12.8 OS version: macOS Sierra 10.12.2

When saving any puppet file and the linter is kicked off the following error is given:

Error: sh: droprole: line 1: syntax error: unexpected end of file
sh: error importing function definition for `droprole'
sh: assumerole: line 1: syntax error: unexpected end of file
sh: error importing function definition for `assumerole'
    at ChildProcess.<anonymous> (/Users/rday/.atom/packages/linter-puppet-lint/node_modules/sb-exec/lib/index.js:56:20)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

The functions referenced droprole and assumerole are custom ones from my ~/.profile. They are reproduced below and are used to change roles into other AWS accounts that I work with.

# changing AWSCLI role function
function assumerole() {
  # set $acct_id to the account number and $session_name to the user input
  acct_id=$1
  session_name="$2"

  # set the account role with the account-id and awk out the access key, secret key, and session token to an array
  #aws_creds=(`aws sts assume-role --role-arn "arn:aws:iam::$acct_id:role/etFullAccess" --role-session-name "$session_name" | grep CREDENTIALS | awk '{print $2 " "  $4 " " $(NF)}' `)
  # do the same thing but with JSON and jq
  aws_creds=(`aws --output json sts assume-role --role-arn "arn:aws:iam::$acct_id:role/etFullAccess" --role-session-name "$session_name" | jq '.Credentials.AccessKeyId,.Credentials.SecretAccessKey,.Credentials.SessionToken' --raw-output `)

  # export the array contents to the right variables
  export AWS_ACCESS_KEY_ID="${aws_creds[0]}"
  export AWS_SECRET_ACCESS_KEY="${aws_creds[1]}"
  export AWS_SESSION_TOKEN="${aws_creds[2]}"
}

export -f assumerole

# reverting AWSCLI role function
function droprole() {
  # sometimes you need to drop the session before the token times out
  unset AWS_SESSION_TOKEN AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID
}

export -f droprole

They are exported and so show up in my environment, reproduced below.

10:06:47 rday@rdays-mbpro:~/Documents/RRD/ssh $ env
...
BASH_FUNC_droprole%%=() {  unset AWS_SESSION_TOKEN AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID
}
BASH_FUNC_assumerole%%=() {  acct_id=$1;
 session_name="$2";
 aws_creds=(`aws --output json sts assume-role --role-arn "arn:aws:iam::$acct_id:role/etFullAccess" --role-session-name "$session_name" | jq '.Credentials.AccessKeyId,.Credentials.SecretAccessKey,.Credentials.SessionToken' --raw-output `);
 export AWS_ACCESS_KEY_ID="${aws_creds[0]}";
 export AWS_SECRET_ACCESS_KEY="${aws_creds[1]}";
 export AWS_SESSION_TOKEN="${aws_creds[2]}"
}
...
10:08:21 rday@rdays-mbpro:~/Documents/RRD/ssh $
steelbrain commented 7 years ago

Thanks @rutgoff! I've posted an explanation on the source issue about why this is not a bug in sb-exec