jenkins-rest icon indicating copy to clipboard operation
jenkins-rest copied to clipboard

Usage of Custom headers?

Open darewreck54 opened this issue 4 years ago • 3 comments
trafficstars

This is more of a question. Does the JenkinsClient support the ability to add custom headers? I'm not seeing that in the interface.

At my company, we require to have a specific header too authenticate for any traffic internally. So in order for me to talk to the jenkins server, I need to add a header.

darewreck54 avatar Nov 03 '21 18:11 darewreck54

Not currently supported but could certainly be added with not too much work if you wanted to knock things out.

cdancy avatar Nov 03 '21 18:11 cdancy

Took a look at the JenkinsClient

        return ContextBuilder
                .newBuilder(new JenkinsApiMetadata.Builder().build())
                .endpoint(endPoint)
                .modules(allModules)
                .overrides(overrides)
                .buildApi(JenkinsApi.class);

I haven't really used jcloud before. How would you inject headers in this use case. Can you give some pointers on where this logic should live?

darewreck54 avatar Nov 06 '21 16:11 darewreck54

@darewreck54 I'd probably add something to the builder to take in a map of headers. Within that code path you can set those on the JenkinsAuthentication object. Then, within the JenkinsAuthenticationFilter, you can read any potential headers found within the JenkinsAuthentication object and apply them to the HttpRequest builder wtihin at the appropriate spot. Something like that should work. Keeping those headers in memory however, especially if they are holding creds, might not be the most secure thing in the world but if your use-case is secure enough then you will probably be alright.

cdancy avatar Nov 08 '21 01:11 cdancy