-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package wrapper | ||
|
||
import ( | ||
"code.cloudfoundry.org/cli/api/cloudcontroller" | ||
"code.cloudfoundry.org/cli/api/shared" | ||
) | ||
|
||
// TODO | ||
// 1. tests | ||
// 2. do not overwrite headers if explicitly set (cf curl) | ||
// 3. headers should go on other clients (uaa/routing) as well (with same value) | ||
// 4. environment variable override | ||
|
||
// CCTraceHeaderRequest is a wrapper that adds b3 trace headers to requests. | ||
type CCTraceHeaderRequest struct { | ||
headers *shared.TraceHeaders | ||
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 16 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
connection cloudcontroller.Connection | ||
} | ||
|
||
// NewCCTraceHeaderRequest returns a pointer to a CCTraceHeaderRequest wrapper. | ||
func NewCCTraceHeaderRequest(trace, span string) *CCTraceHeaderRequest { | ||
return &CCTraceHeaderRequest{ | ||
headers: shared.NewTraceHeaders(trace, span), | ||
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 23 in api/cloudcontroller/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
} | ||
} | ||
|
||
// Add tracing headers | ||
func (t *CCTraceHeaderRequest) Make(request *cloudcontroller.Request, passedResponse *cloudcontroller.Response) error { | ||
t.headers.SetHeaders(request.Request, passedResponse.HTTPResponse) | ||
return t.connection.Make(request, passedResponse) | ||
} | ||
|
||
// Wrap sets the connection in the CCTraceHeaderRequest and returns itself. | ||
func (t *CCTraceHeaderRequest) Wrap(innerconnection cloudcontroller.Connection) cloudcontroller.Connection { | ||
t.connection = innerconnection | ||
return t | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package wrapper | ||
|
||
import ( | ||
"code.cloudfoundry.org/cli/api/router" | ||
"code.cloudfoundry.org/cli/api/shared" | ||
) | ||
|
||
// RoutingTraceHeaderRequest is a wrapper that adds b3 trace headers to requests. | ||
type RoutingTraceHeaderRequest struct { | ||
headers *shared.TraceHeaders | ||
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 10 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
connection router.Connection | ||
} | ||
|
||
// NewRoutingTraceHeaderRequest returns a pointer to a RoutingTraceHeaderRequest wrapper. | ||
func NewRoutingTraceHeaderRequest(trace, span string) *RoutingTraceHeaderRequest { | ||
return &RoutingTraceHeaderRequest{ | ||
headers: shared.NewTraceHeaders(trace, span), | ||
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 17 in api/router/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
} | ||
} | ||
|
||
// Add tracing headers | ||
func (t *RoutingTraceHeaderRequest) Make(request *router.Request, passedResponse *router.Response) error { | ||
t.headers.SetHeaders(request.Request, passedResponse.HTTPResponse) | ||
return t.connection.Make(request, passedResponse) | ||
} | ||
|
||
// Wrap sets the connection in the RoutingTraceHeaderRequest and returns itself. | ||
func (t *RoutingTraceHeaderRequest) Wrap(innerconnection router.Connection) router.Connection { | ||
t.connection = innerconnection | ||
return t | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package wrapper | ||
|
||
import ( | ||
"net/http" | ||
|
||
"code.cloudfoundry.org/cli/api/shared" | ||
"code.cloudfoundry.org/cli/api/uaa" | ||
) | ||
|
||
// UAATraceHeaderRequest is a wrapper that adds b3 trace headers to requests. | ||
type UAATraceHeaderRequest struct { | ||
headers *shared.TraceHeaders | ||
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 12 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
connection uaa.Connection | ||
} | ||
|
||
// NewUAATraceHeaderRequest returns a pointer to a UAATraceHeaderRequest wrapper. | ||
func NewUAATraceHeaderRequest(trace, span string) *UAATraceHeaderRequest { | ||
return &UAATraceHeaderRequest{ | ||
headers: shared.NewTraceHeaders(trace, span), | ||
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-latest)
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (ubuntu-20.04)
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-latest)
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / lint
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (macos-13)
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Basic units to gate for integration tests
Check failure on line 19 in api/uaa/wrapper/b3_trace_request.go GitHub Actions / Unit Tests (windows-latest)
|
||
} | ||
} | ||
|
||
// Add tracing headers | ||
func (t *UAATraceHeaderRequest) Make(request *http.Request, passedResponse *uaa.Response) error { | ||
t.headers.SetHeaders(request, passedResponse.HTTPResponse) | ||
return t.connection.Make(request, passedResponse) | ||
} | ||
|
||
// Wrap sets the connection in the UAATraceHeaderRequest and returns itself. | ||
func (t *UAATraceHeaderRequest) Wrap(innerconnection uaa.Connection) uaa.Connection { | ||
t.connection = innerconnection | ||
return t | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package random | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
) | ||
|
||
func GenerateHex(length int) string { | ||
b := make([]byte, length/2) | ||
if _, err := rand.Read(b); err != nil { | ||
panic(err) | ||
} | ||
|
||
return hex.EncodeToString(b) | ||
} |