cli icon indicating copy to clipboard operation
cli copied to clipboard

cli-plugins: include plugin metadata in User-Agent

Open milas opened this issue 3 years ago • 2 comments

What I did Automatically add plugin metadata to the CLI/API client User-Agent.

How I did it Add support to the cli/command package to accept a custom User Agent to pass to the underlying client.

Use said support to automatically append CLI plugin-specific info (name & version) to the User-Agent value.

For example, for a hypothetical CLI plugin named mycmd with version 1.0.0 would become docker-cli-plugin-mycmd/1.0.0. The docker-cli-plugin- prefix is added automatically for clarity.

This is used as the UpstreamClient portion of the User-Agent when the Moby daemon makes requests.

For example, pushing and pulling images with Compose might result in the registry seeing a User-Agent value of:

docker/24.0.7 go/go1.20.10 git-commit/311b9ff kernel/6.5.13-linuxkit os/linux arch/arm64 UpstreamClient(docker-cli-plugin-compose/v2.24.0)

See also:

  • #4363
  • moby/moby#45677

- How to verify it Build a CLI plugin against latest HEAD, update its SchemaVersion to 0.2.0, and inspect network traffic.

- Description for the changelog

- CLI plugin name and version included in User-Agent for HTTP requests.

- A picture of a cute animal (not mandatory but encouraged) several baby skunks with bushy tails

milas avatar Sep 20 '23 18:09 milas

Codecov Report

Merging #4574 (0bfe13b) into master (8812e0a) will decrease coverage by 0.32%. The diff coverage is 71.87%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4574      +/-   ##
==========================================
- Coverage   59.64%   59.32%   -0.32%     
==========================================
  Files         287      288       +1     
  Lines       24771    24943     +172     
==========================================
+ Hits        14774    14797      +23     
- Misses       9111     9258     +147     
- Partials      886      888       +2     

codecov-commenter avatar Jan 04 '24 20:01 codecov-commenter

@thaJeztah PTAL - I refactored and there's no changes in the plugin metadata needed any longer.

I'm using the plugin.Name() now, which is the Cobra subcommand (e.g. compose, buildx). The UA will have docker-cli-plugin- prepended.

[See updated PR description for more details]

milas avatar Jan 04 '24 20:01 milas