Skip to content

Pass job user as environment variable to task#1465

Merged
ssalinas merged 4 commits intomasterfrom
expose-runnow-user
Mar 31, 2017
Merged

Pass job user as environment variable to task#1465
ssalinas merged 4 commits intomasterfrom
expose-runnow-user

Conversation

@PtrTeixeira
Copy link
Contributor

@PtrTeixeira PtrTeixeira commented Mar 20, 2017

Pass the user who clicks the "Run Now" button as the value of the
environment variable STARTED_BY_USER in the task environment. Can provide
more granular, task-level permissions or auditability.

Pass the user who clicks the "Run Now" button as the value of the
environment variable `JOB_USER` in the task environment.  Can provide
more granular, task-level permissions or auditability.
setEnv(envBldr, "TASK_ID", taskId.getId());
setEnv(envBldr, "ESTIMATED_INSTANCE_COUNT", task.getRequest().getInstancesSafe());

setEnv(envBldr, "JOB_USER", task.getPendingTask().getUser().or(""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things.

  • Wondering if JOB_USER is descriptive enough here. This method will get called for services and workers as well. Maybe something more like STARTED_BY_USER ?
  • In the case where user is not present on the pending task, would it make more sent to leave this out rather than have an empty string as the value?

Two small changes:
* Change the name of the environment variable to something
  more descriptive (`JOB_USER` -> `STARTED_BY_USER`)
* Don't set the environment variable at all if the user can't be
  found.
@ssalinas
Copy link
Member

👍

for (Variable environmentVariable : environmentVariables) {
success = success || (environmentVariable.getName().equals("STARTED_BY_USER") && environmentVariable.getValue().equals(user));
}

Copy link
Contributor

@matush-v matush-v Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got an extra JOB_USER lurking here 🙂

@ssalinas ssalinas modified the milestone: 0.15.0 Mar 30, 2017
@ssalinas ssalinas merged commit c2fd507 into master Mar 31, 2017
@ssalinas ssalinas deleted the expose-runnow-user branch March 31, 2017 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants