2023-02-03 16:05:58 +00:00
|
|
|
package root
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/databricks/databricks-sdk-go/useragent"
|
|
|
|
)
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
// Environment variables that caller can set to convey what is upstream to this CLI.
|
2023-02-03 16:05:58 +00:00
|
|
|
const upstreamEnvVar = "BRICKS_UPSTREAM"
|
|
|
|
const upstreamVersionEnvVar = "BRICKS_UPSTREAM_VERSION"
|
|
|
|
|
|
|
|
// Keys in the user agent.
|
|
|
|
const upstreamKey = "upstream"
|
|
|
|
const upstreamVersionKey = "upstream-version"
|
|
|
|
|
|
|
|
func withUpstreamInUserAgent(ctx context.Context) context.Context {
|
|
|
|
value := os.Getenv(upstreamEnvVar)
|
|
|
|
if value == "" {
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = useragent.InContext(ctx, upstreamKey, value)
|
|
|
|
|
|
|
|
// Include upstream version as well, if set.
|
|
|
|
value = os.Getenv(upstreamVersionEnvVar)
|
|
|
|
if value == "" {
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
return useragent.InContext(ctx, upstreamVersionKey, value)
|
|
|
|
}
|