{"action":"created","comment":{"url":"https://api.github.com/repos/operable/cog/pulls/comments/68467586","id":68467586,"diff_hunk":"@@ -54,6 +67,65 @@ defmodule Cog.Bootstrap do\n     end)\n   end\n \n+  # Bootstraps using environment variables if they are present.\n+  @doc \"\"\"\n+  Create an administrative user using values from the environment, if present.\n+  If any of the following variables are not set, the bootstrap will not be\n+  performed. Required variables:\n+\n+  COG_BOOTSTRAP_USERNAME\n+  COG_BOOTSTRAP_PASSWORD\n+  COG_BOOTSTRAP_EMAIL_ADDRESS\n+  COG_BOOTSTRAP_FIRST_NAME\n+  COG_BOOTSTRAP_LAST_NAME\n+\n+  Additionally, if the user bootstrap completes successfully and the RELAY_ID\n+  and RELAY_COG_TOKEN variables are set, a relay will be created using the\n+  variables and assigned to a default relay group, which will also be created.\n+  If the relevant variables are not present, this step will be skipped.\n+\n+  If any creation attempt fails, the entire bootstrap process will be rolled\n+  back.\n+  \"\"\"\n+  def maybe_bootstrap do\n+    unless is_bootstrapped? do\n+      Repo.transaction fn ->\n+        if bootstrap_from_env, do: relay_from_env(System.get_env)\n+      end\n+\n+      true\n+    end\n+\n+    false\n+  end\n+\n+  def bootstrap_from_env do\n+    user_keys = ~w(username password email_address first_name last_name)\n+    user_map = for param <- user_keys do\n+      key = \"COG_BOOTSTRAP_\" <> String.upcase(param)\n+      { param, System.get_env(key) }\n+    end |> Enum.into(%{})\n+\n+    unless Enum.any?(user_map, fn({_k, v}) -> v == nil end) do\n+      bootstrap(user_map)\n+    end\n+  end\n+\n+  def relay_from_env(%{\"RELAY_ID\" => relay_id,","path":"lib/cog/bootstrap.ex","position":75,"original_position":75,"commit_id":"e442fabbd477fc3dba40a02e98146a0ead57ae7a","original_commit_id":"e442fabbd477fc3dba40a02e98146a0ead57ae7a","user":{"login":"christophermaier","id":207178,"avatar_url":"https://avatars.githubusercontent.com/u/207178?v=3","gravatar_id":"","url":"https://api.github.com/users/christophermaier","html_url":"https://github.com/christophermaier","followers_url":"https://api.github.com/users/christophermaier/followers","following_url":"https://api.github.com/users/christophermaier/following{/other_user}","gists_url":"https://api.github.com/users/christophermaier/gists{/gist_id}","starred_url":"https://api.github.com/users/christophermaier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christophermaier/subscriptions","organizations_url":"https://api.github.com/users/christophermaier/orgs","repos_url":"https://api.github.com/users/christophermaier/repos","events_url":"https://api.github.com/users/christophermaier/events{/privacy}","received_events_url":"https://api.github.com/users/christophermaier/received_events","type":"User","site_admin":false},"body":"Can be private","created_at":"2016-06-24T21:44:44Z","updated_at":"2016-06-24T21:44:44Z","html_url":"https://github.com/operable/cog/pull/811#discussion_r68467586","pull_request_url":"https://api.github.com/repos/operable/cog/pulls/811","_links":{"self":{"href":"https://api.github.com/repos/operable/cog/pulls/comments/68467586"},"html":{"href":"https://github.com/operable/cog/pull/811#discussion_r68467586"},"pull_request":{"href":"https://api.github.com/repos/operable/cog/pulls/811"}}},"pull_request":{"url":"https://api.github.com/repos/operable/cog/pulls/811","id":75153760,"html_url":"https://github.com/operable/cog/pull/811","diff_url":"https://github.com/operable/cog/pull/811.diff","patch_url":"https://github.com/operable/cog/pull/811.patch","issue_url":"https://api.github.com/repos/operable/cog/issues/811","number":811,"state":"open","locked":false,"title":"Automatically bootstrap using environment variables, if present.","user":{"login":"imbriaco","id":1198,"avatar_url":"https://avatars.githubusercontent.com/u/1198?v=3","gravatar_id":"","url":"https://api.github.com/users/imbriaco","html_url":"https://github.com/imbriaco","followers_url":"https://api.github.com/users/imbriaco/followers","following_url":"https://api.github.com/users/imbriaco/following{/other_user}","gists_url":"https://api.github.com/users/imbriaco/gists{/gist_id}","starred_url":"https://api.github.com/users/imbriaco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imbriaco/subscriptions","organizations_url":"https://api.github.com/users/imbriaco/orgs","repos_url":"https://api.github.com/users/imbriaco/repos","events_url":"https://api.github.com/users/imbriaco/events{/privacy}","received_events_url":"https://api.github.com/users/imbriaco/received_events","type":"User","site_admin":false},"body":"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:\r\n\r\n```\r\nCOG_BOOTSTRAP_USERNAME\r\nCOG_BOOTSTRAP_PASSWORD\r\nCOG_BOOTSTRAP_EMAIL_ADDRESS\r\nCOG_BOOTSTRAP_FIRST_NAME\r\nCOG_BOOTSTRAP_LAST_NAME\r\n```\r\n\r\nAdditionally, 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.\r\n\r\nIf any creation attempt fails, the entire bootstrap process will be rolled back.\r\n","created_at":"2016-06-24T18:25:09Z","updated_at":"2016-06-24T21:44:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4dad0a7afbe148b8875d75835ad53e8c3f743660","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/operable/cog/pulls/811/commits","review_comments_url":"https://api.github.com/repos/operable/cog/pulls/811/comments","review_comment_url":"https://api.github.com/repos/operable/cog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/operable/cog/issues/811/comments","statuses_url":"https://api.github.com/repos/operable/cog/statuses/e442fabbd477fc3dba40a02e98146a0ead57ae7a","head":{"label":"operable:imbriaco/auto-bootstrap","ref":"imbriaco/auto-bootstrap","sha":"e442fabbd477fc3dba40a02e98146a0ead57ae7a","user":{"login":"operable","id":6070463,"avatar_url":"https://avatars.githubusercontent.com/u/6070463?v=3","gravatar_id":"","url":"https://api.github.com/users/operable","html_url":"https://github.com/operable","followers_url":"https://api.github.com/users/operable/followers","following_url":"https://api.github.com/users/operable/following{/other_user}","gists_url":"https://api.github.com/users/operable/gists{/gist_id}","starred_url":"https://api.github.com/users/operable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/operable/subscriptions","organizations_url":"https://api.github.com/users/operable/orgs","repos_url":"https://api.github.com/users/operable/repos","events_url":"https://api.github.com/users/operable/events{/privacy}","received_events_url":"https://api.github.com/users/operable/received_events","type":"Organization","site_admin":false},"repo":{"id":49292670,"name":"cog","full_name":"operable/cog","owner":{"login":"operable","id":6070463,"avatar_url":"https://avatars.githubusercontent.com/u/6070463?v=3","gravatar_id":"","url":"https://api.github.com/users/operable","html_url":"https://github.com/operable","followers_url":"https://api.github.com/users/operable/followers","following_url":"https://api.github.com/users/operable/following{/other_user}","gists_url":"https://api.github.com/users/operable/gists{/gist_id}","starred_url":"https://api.github.com/users/operable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/operable/subscriptions","organizations_url":"https://api.github.com/users/operable/orgs","repos_url":"https://api.github.com/users/operable/repos","events_url":"https://api.github.com/users/operable/events{/privacy}","received_events_url":"https://api.github.com/users/operable/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/operable/cog","description":"Bringing the power of the command line to chat","fork":false,"url":"https://api.github.com/repos/operable/cog","forks_url":"https://api.github.com/repos/operable/cog/forks","keys_url":"https://api.github.com/repos/operable/cog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/operable/cog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/operable/cog/teams","hooks_url":"https://api.github.com/repos/operable/cog/hooks","issue_events_url":"https://api.github.com/repos/operable/cog/issues/events{/number}","events_url":"https://api.github.com/repos/operable/cog/events","assignees_url":"https://api.github.com/repos/operable/cog/assignees{/user}","branches_url":"https://api.github.com/repos/operable/cog/branches{/branch}","tags_url":"https://api.github.com/repos/operable/cog/tags","blobs_url":"https://api.github.com/repos/operable/cog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/operable/cog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/operable/cog/git/refs{/sha}","trees_url":"https://api.github.com/repos/operable/cog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/operable/cog/statuses/{sha}","languages_url":"https://api.github.com/repos/operable/cog/languages","stargazers_url":"https://api.github.com/repos/operable/cog/stargazers","contributors_url":"https://api.github.com/repos/operable/cog/contributors","subscribers_url":"https://api.github.com/repos/operable/cog/subscribers","subscription_url":"https://api.github.com/repos/operable/cog/subscription","commits_url":"https://api.github.com/repos/operable/cog/commits{/sha}","git_commits_url":"https://api.github.com/repos/operable/cog/git/commits{/sha}","comments_url":"https://api.github.com/repos/operable/cog/comments{/number}","issue_comment_url":"https://api.github.com/repos/operable/cog/issues/comments{/number}","contents_url":"https://api.github.com/repos/operable/cog/contents/{+path}","compare_url":"https://api.github.com/repos/operable/cog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/operable/cog/merges","archive_url":"https://api.github.com/repos/operable/cog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/operable/cog/downloads","issues_url":"https://api.github.com/repos/operable/cog/issues{/number}","pulls_url":"https://api.github.com/repos/operable/cog/pulls{/number}","milestones_url":"https://api.github.com/repos/operable/cog/milestones{/number}","notifications_url":"https://api.github.com/repos/operable/cog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/operable/cog/labels{/name}","releases_url":"https://api.github.com/repos/operable/cog/releases{/id}","deployments_url":"https://api.github.com/repos/operable/cog/deployments","created_at":"2016-01-08T19:45:06Z","updated_at":"2016-06-24T03:26:28Z","pushed_at":"2016-06-24T21:39:04Z","git_url":"git://github.com/operable/cog.git","ssh_url":"git@github.com:operable/cog.git","clone_url":"https://github.com/operable/cog.git","svn_url":"https://github.com/operable/cog","homepage":"http://operable.io","size":1996,"stargazers_count":360,"watchers_count":360,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":140,"forks":23,"open_issues":140,"watchers":360,"default_branch":"master"}},"base":{"label":"operable:master","ref":"master","sha":"a1f0a474ca8b218ce7a467723245504da53a5898","user":{"login":"operable","id":6070463,"avatar_url":"https://avatars.githubusercontent.com/u/6070463?v=3","gravatar_id":"","url":"https://api.github.com/users/operable","html_url":"https://github.com/operable","followers_url":"https://api.github.com/users/operable/followers","following_url":"https://api.github.com/users/operable/following{/other_user}","gists_url":"https://api.github.com/users/operable/gists{/gist_id}","starred_url":"https://api.github.com/users/operable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/operable/subscriptions","organizations_url":"https://api.github.com/users/operable/orgs","repos_url":"https://api.github.com/users/operable/repos","events_url":"https://api.github.com/users/operable/events{/privacy}","received_events_url":"https://api.github.com/users/operable/received_events","type":"Organization","site_admin":false},"repo":{"id":49292670,"name":"cog","full_name":"operable/cog","owner":{"login":"operable","id":6070463,"avatar_url":"https://avatars.githubusercontent.com/u/6070463?v=3","gravatar_id":"","url":"https://api.github.com/users/operable","html_url":"https://github.com/operable","followers_url":"https://api.github.com/users/operable/followers","following_url":"https://api.github.com/users/operable/following{/other_user}","gists_url":"https://api.github.com/users/operable/gists{/gist_id}","starred_url":"https://api.github.com/users/operable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/operable/subscriptions","organizations_url":"https://api.github.com/users/operable/orgs","repos_url":"https://api.github.com/users/operable/repos","events_url":"https://api.github.com/users/operable/events{/privacy}","received_events_url":"https://api.github.com/users/operable/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/operable/cog","description":"Bringing the power of the command line to chat","fork":false,"url":"https://api.github.com/repos/operable/cog","forks_url":"https://api.github.com/repos/operable/cog/forks","keys_url":"https://api.github.com/repos/operable/cog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/operable/cog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/operable/cog/teams","hooks_url":"https://api.github.com/repos/operable/cog/hooks","issue_events_url":"https://api.github.com/repos/operable/cog/issues/events{/number}","events_url":"https://api.github.com/repos/operable/cog/events","assignees_url":"https://api.github.com/repos/operable/cog/assignees{/user}","branches_url":"https://api.github.com/repos/operable/cog/branches{/branch}","tags_url":"https://api.github.com/repos/operable/cog/tags","blobs_url":"https://api.github.com/repos/operable/cog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/operable/cog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/operable/cog/git/refs{/sha}","trees_url":"https://api.github.com/repos/operable/cog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/operable/cog/statuses/{sha}","languages_url":"https://api.github.com/repos/operable/cog/languages","stargazers_url":"https://api.github.com/repos/operable/cog/stargazers","contributors_url":"https://api.github.com/repos/operable/cog/contributors","subscribers_url":"https://api.github.com/repos/operable/cog/subscribers","subscription_url":"https://api.github.com/repos/operable/cog/subscription","commits_url":"https://api.github.com/repos/operable/cog/commits{/sha}","git_commits_url":"https://api.github.com/repos/operable/cog/git/commits{/sha}","comments_url":"https://api.github.com/repos/operable/cog/comments{/number}","issue_comment_url":"https://api.github.com/repos/operable/cog/issues/comments{/number}","contents_url":"https://api.github.com/repos/operable/cog/contents/{+path}","compare_url":"https://api.github.com/repos/operable/cog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/operable/cog/merges","archive_url":"https://api.github.com/repos/operable/cog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/operable/cog/downloads","issues_url":"https://api.github.com/repos/operable/cog/issues{/number}","pulls_url":"https://api.github.com/repos/operable/cog/pulls{/number}","milestones_url":"https://api.github.com/repos/operable/cog/milestones{/number}","notifications_url":"https://api.github.com/repos/operable/cog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/operable/cog/labels{/name}","releases_url":"https://api.github.com/repos/operable/cog/releases{/id}","deployments_url":"https://api.github.com/repos/operable/cog/deployments","created_at":"2016-01-08T19:45:06Z","updated_at":"2016-06-24T03:26:28Z","pushed_at":"2016-06-24T21:39:04Z","git_url":"git://github.com/operable/cog.git","ssh_url":"git@github.com:operable/cog.git","clone_url":"https://github.com/operable/cog.git","svn_url":"https://github.com/operable/cog","homepage":"http://operable.io","size":1996,"stargazers_count":360,"watchers_count":360,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":140,"forks":23,"open_issues":140,"watchers":360,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/operable/cog/pulls/811"},"html":{"href":"https://github.com/operable/cog/pull/811"},"issue":{"href":"https://api.github.com/repos/operable/cog/issues/811"},"comments":{"href":"https://api.github.com/repos/operable/cog/issues/811/comments"},"review_comments":{"href":"https://api.github.com/repos/operable/cog/pulls/811/comments"},"review_comment":{"href":"https://api.github.com/repos/operable/cog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/operable/cog/pulls/811/commits"},"statuses":{"href":"https://api.github.com/repos/operable/cog/statuses/e442fabbd477fc3dba40a02e98146a0ead57ae7a"}}}}
{"actor":{"display_login":"christophermaier"}}