Skip to content

Conversation

@imbriaco
Copy link
Member

Create an administrative user using values from the environment, if present. If any of the following variables are not set, the bootstrap will not be performed. Required variables:

COG_BOOTSTRAP_USERNAME
COG_BOOTSTRAP_PASSWORD
COG_BOOTSTRAP_EMAIL_ADDRESS
COG_BOOTSTRAP_FIRST_NAME
COG_BOOTSTRAP_LAST_NAME

Additionally, if the user bootstrap completes successfully and the RELAY_ID and RELAY_COG_TOKEN variables are set, a relay will be created using the variables and assigned to a default relay group, which will also be created. If the relevant variables are not present, this step will be skipped.

If any creation attempt fails, the entire bootstrap process will be rolled back.

true
end

false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this return value? And the true above in the unless block?

Copy link
Member Author

Choose a reason for hiding this comment

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

I ... don't remember. Looking at the code now it doesn't seem to be used. I think I just wanted to indicate whether a bootstrap actually happened or not as a result of that call. I can easily take taht out if we want.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah let's take that out. Feels weird that it would always return false.

@christophermaier
Copy link
Collaborator

Have you tested to see if the transactions behave as expected? If you're not explicitly checking return values and rolling back the transaction on your own, you need to be using ! methods and throwing exceptions to abort the transaction. In the past, I wasn't doing that and would happily carry on with the transaction when I thought I wasn't.

@imbriaco
Copy link
Member Author

imbriaco commented Jun 24, 2016

@christophermaier I made the functions you mentioned private and left a comment above about he return value from the maybe_bootstrap. i don't have a strong opinion about whether or not to keep it.

As far as the transaction goes, yes, I tested it. If you look in relay_from_env I'm doing :ok = with .... If that can't match, it'll raise and rollback the transaction.

@christophermaier
Copy link
Collaborator

Ah, yeah, I missed the :ok = with ... bit.

I'd rather remove those booleans... it's potentially confusing.

@imbriaco imbriaco force-pushed the imbriaco/auto-bootstrap branch from d2e7509 to 3dedfa1 Compare June 24, 2016 22:25
@imbriaco
Copy link
Member Author

Added logging for missing variables. I only emit this if at least one of the COG_BOOTSTRAP_* variables was seen so we're not noisy if the user didn't intend to bootstrap from the environment.

2016-06-24T18:22:18.0424  (Cog.Bootstrap:116) [info] Skipping bootstrap: Missing value for COG_BOOTSTRAP_LAST_NAME.

Also removed the booleans.

@christophermaier
Copy link
Collaborator

👍

@imbriaco imbriaco force-pushed the imbriaco/auto-bootstrap branch from 3dedfa1 to 7b68f13 Compare June 24, 2016 23:56
@imbriaco
Copy link
Member Author

Thanks, @christophermaier for the review. You made my code better. I'm going to go ahead and merge as soon as CI finishes since I've addressed all the feedback.

Here's where we landed:

Victory!

Environment:

export COG_BOOTSTRAP_USERNAME=imbriaco
export COG_BOOTSTRAP_PASSWORD=sekrit
export COG_BOOTSTRAP_FIRST_NAME=Mark
export COG_BOOTSTRAP_LAST_NAME=Imbriaco
export [email protected]
export RELAY_ID=8b610fc6-f643-4e0b-bba0-bfc140266393
export RELAY_COG_TOKEN=supersecret

All variables present:

2016-06-24T19:46:39.0428  (Cog.Bootstrap:112) [info] Bootstrapping Cog from environment variables.
2016-06-24T19:46:40.0595  (Cog.Bootstrap:130) [info] Configuring default relay from environment variables.

Validation:

 $ cogctl users --rest-user=imbriaco --rest-password=sekrit
USERNAME  FULL NAME      EMAIL_ADDRESS
imbriaco  Mark Imbriaco  [email protected]

Error Logging:

Cog variables present, but no relay variables:

2016-06-24T19:42:18.0428  (Cog.Bootstrap:112) [info] Bootstrapping Cog from environment variables.

Some, but not all, Cog variables present:

2016-06-24T19:49:46.0210  (Cog.Bootstrap:119) [info] Skipping bootstrap: Missing value for COG_BOOTSTRAP_FIRST_NAME.
2016-06-24T19:49:46.0210  (Cog.Bootstrap:119) [info] Skipping bootstrap: Missing value for COG_BOOTSTRAP_USERNAME.

@imbriaco imbriaco merged commit 33a3b25 into master Jun 25, 2016
@imbriaco imbriaco deleted the imbriaco/auto-bootstrap branch June 25, 2016 00:35
@imbriaco imbriaco removed the review label Jun 25, 2016
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.

4 participants