Skip to content

Instantly share code, notes, and snippets.

@op-ct
Last active March 6, 2018 20:52
Show Gist options
  • Select an option

  • Save op-ct/1b1aa2dddea32822e4d783daa75a3307 to your computer and use it in GitHub Desktop.

Select an option

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
# 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