Set a User-Agent header with the AtlasBoard version

Issue #92 resolved
Joseph Walton created an issue

While rolling out an AtlasBoard upgrade across a company it would be useful to know which versions are currently deployed. A User-Agent header like:

User-Agent: atlasboard/0.10.0

would be helpful.

Comments (5)

  1. Iván Loire

    Thanks for creating the issue Joseph. Adding default headers to request should be similar to what you already did to add a default cookie jar:

    https://github.com/request/request

    request.defaults(options)
    
    This method returns a wrapper around the normal request API that defaults to whatever options you pass to it.
    
    Note: request.defaults() does not modify the global request API; instead, it returns a wrapper that has your default settings applied to it.
    
    Note: You can call .defaults() on the wrapper that is returned from request.defaults to add/override defaults that were previously defaulted.
    
    For example:
    
    //requests using baseRequest() will set the 'x-token' header
    var baseRequest = request.defaults({
      headers: {x-token: 'my-token'}
    })
    
    //requests using specialRequest() will include the 'x-token' header set in
    //baseRequest and will also include the 'special' header
    var specialRequest = baseRequest.defaults({
      headers: {special: 'special value'}
    })
    

    Getting the version would be a bit more challenging though. We are already doing it in cli.js:

      var projectPackageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../..", "package.json")));
      console.log("\nAtlasBoard Version %s\n", projectPackageJson.version);
    

    Not sure if we should pay the perfomance hit of doing synchronous IO just for this. Maybe the user agent footprint could be just "atlasboard" for now.

  2. Joseph Walton reporter

    Getting the version would be a bit more challenging though.

    Yes, I was expecting that to be more difficult. Can it be set at release time? Or is that synchronous IO hit just once on startup?

  3. Iván Loire

    It was easy enough to double check to confirm. Since the dependencies are resolved and cached on the job instance, that code only gets executed once per job on startup which is close to zero overhead, so we should be fine.

  4. Iván Loire

    Obviously we will only get the header set on the jobs that use the request dependency provided by Atlasboard

  5. Log in to comment