odavid / my-bloody-jenkins

Self Configured Jenkins Docker image based on Jenkins-LTS
MIT License
251 stars 71 forks source link

Config from private github repository via raw #186

Open Jasstkn opened 3 years ago

Jasstkn commented 3 years ago

Hi!

I'm trying to configure getting configuration as a code from private repository in my organization.

I was able to successfully add config with temporary token like: https://raw.githubusercontent.com/ORG/REPO/BRANCH/config.yaml?token=XXXXX

But this token expires every 7 days and I want to replace it via access token from my service account user. I've created token using doc here: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token, and paste url in format:

https://$TOKEN@raw.githubusercontent.com/ORG/REPO/BRANCH/config.yaml

And I've got 404. I'm gonna to dig into this problem a bit later, but maybe you already have a solution? If not I would like to contribute to allow pass some headers to this script: https://github.com/odavid/my-bloody-jenkins/blob/master/bin/fetchconfig.py

Jasstkn commented 3 years ago

I've been playing around and found out that if you use Basic auth it works fine and return 200.

>>> headers = {'Authorization': 'token XXXXXX'}
>>> requests.get(source, headers=header)
<Response [404]>
>>> requests.get(source, auth=('user', 'access_token'))
<Response [200]>

@odavid what do you think about such problem? I see not many solutions for that but the main blocker from my point of view is to map auth configuration with the exact URL from the list of URLs...

odavid commented 3 years ago

Hi @Jasstkn I think that maybe we need to have an environment variable named

JENKINS_ENV_FETCH_CONF_HTTP_HEADERS="HEADER: VAL, HEADER2, VAL2..."

Then in the script we can check if this env var exists, parse it and add the headers to the request. Hope it helps

Jasstkn commented 3 years ago

Hi @Jasstkn I think that maybe we need to have an environment variable named

JENKINS_ENV_FETCH_CONF_HTTP_HEADERS="HEADER: VAL, HEADER2, VAL2..."

Then in the script we can check if this env var exists, parse it and add the headers to the request. Hope it helps

Oh, it's actually a quite nice solution. Don't you mind if I try to contribute?

odavid commented 3 years ago

Hi @Jasstkn I think that maybe we need to have an environment variable named

JENKINS_ENV_FETCH_CONF_HTTP_HEADERS="HEADER: VAL, HEADER2, VAL2..."

Then in the script we can check if this env var exists, parse it and add the headers to the request. Hope it helps

Oh, it's actually a quite nice solution. Don't you mind if I try to contribute?

Will be nice...

Jasstkn commented 3 years ago

Hi @Jasstkn I think that maybe we need to have an environment variable named

JENKINS_ENV_FETCH_CONF_HTTP_HEADERS="HEADER: VAL, HEADER2, VAL2..."

Then in the script we can check if this env var exists, parse it and add the headers to the request. Hope it helps

Oh, it's actually a quite nice solution. Don't you mind if I try to contribute?

Will be nice...

Ok, I'll try to do it then. Thank you for the great idea!

gfnord commented 2 years ago

Hi @Jasstkn, have you been able to implement the JENKINS_ENV_FETCH_CONF_HTTP_HEADERS? If not, can I help? Thanks!