Last active
March 6, 2018 20:52
-
-
Save op-ct/1b1aa2dddea32822e4d783daa75a3307 to your computer and use it in GitHub Desktop.
Beaker snippet: acquiring a GitLab 10.4+ oauth token using only the API + user creds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Here is an example of how to grab a token under the new (10.0+ v4 API): | |
| # | |
| # It is written in the beaker DSL | |
| require 'json' | |
| # A puppet manifest to create a json file for the API query | |
| oauth_json_pp= <<-PP | |
| # passgen() is a simplib function | |
| $pw = passgen( "simp_gitlab_${trusted['certname']}" ) | |
| $json = "{\\"grant_type\\": \\"password\\", \\"username\\": \\"root\\", \\"password\\": \\"${pw}\\"}" | |
| file{ '/root/ouath_json.template': | |
| content => $json | |
| } | |
| PP | |
| # template the JSON payload | |
| apply_manifest_on(gitlab_server, oauth_json_pp, :catch_failures => true, :environment => env_vars) | |
| # use the payload on the API | |
| _r = on(gitlab_server, "curl https://#{gitlab_server.node_name}/oauth/token --capath /etc/pki/simp-testing/pki/cacerts/ -d @/root/ouath_json.template --header 'Content-Type: application/json' ") | |
| expect(_r.exit_code_in? [0,2]).to be true | |
| # Here's the tocken! | |
| token_data = JSON.parse(_r.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment