-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DeviceCode: Send
engflow_auth
version in requests
This change modifies the HTTP client used by the `DeviceCode` Authenticator implementation to send version information in each request. The version info is sent in the `User-Agent` header, using the format: engflow_auth vX.Y.Z The version string is generated by the `buildstamp` library and is a semver string in a release binary, or a "pseudoversion" in a dev binary, similar go Go module pseudoversions. Tested: Added unit tests Bug: linear/CUS-387
- Loading branch information
1 parent
10d8b09
commit ec9e18f
Showing
5 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "httputil", | ||
srcs = ["header_transport.go"], | ||
importpath = "github.com/EngFlow/auth/internal/httputil", | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 EngFlow Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package httputil provides additional types/helpers for HTTP communication. | ||
package httputil | ||
|
||
import "net/http" | ||
|
||
// HeaderInsertingTransport wraps an http.RoundTripper and inserts headers into | ||
// the request before propagating it to the underlying implementation. | ||
type HeaderInsertingTransport struct { | ||
// Transport is the underlying transport actually performing requests. | ||
Transport http.RoundTripper | ||
// Headers specify the headers to add on each request. These headers will | ||
// override existing headers on the request with the same name; headers on | ||
// the request not mentioned here are not modified. | ||
Headers http.Header | ||
} | ||
|
||
func (t *HeaderInsertingTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
for k := range t.Headers { | ||
req.Header.Del(k) | ||
} | ||
for k, vals := range t.Headers { | ||
for _, val := range vals { | ||
req.Header.Add(k, val) | ||
} | ||
} | ||
return t.Transport.RoundTrip(req) | ||
} |