Skip to content

Commit

Permalink
feat: set X-Opsmx-Agent-Name header (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
skandragon authored Oct 4, 2022
1 parent 181a024 commit af94e49
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/forwarder-agent/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func handleHTTPControl(in *tunnel.MessageWrapper, httpids *util.SessionList, end
found := false
for _, endpoint := range endpoints {
if endpoint.Configured && endpoint.Type == req.Type && endpoint.Name == req.Name {
go endpoint.Instance.ExecuteHTTPRequest(dataflow, req)
go endpoint.Instance.ExecuteHTTPRequest("", dataflow, req)
found = true
break
}
Expand Down
6 changes: 3 additions & 3 deletions app/forwarder-controller/grpc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *agentTunnelServer) EventTunnel(stream tunnel.AgentTunnelService_EventTu
}
zap.S().Infow("agent-handshake-complete", "route", state.String())
case *tunnel.MessageWrapper_HttpTunnelControl:
handleHTTPControl(in, httpids, s.endpoints, dataflow)
handleHTTPControl(state.Name, in, httpids, s.endpoints, dataflow)
case nil:
// ignore for now
default:
Expand Down Expand Up @@ -243,7 +243,7 @@ func (s *agentTunnelServer) sendHello(stream tunnel.AgentTunnelService_EventTunn
return stream.Send(hello)
}

func handleHTTPControl(in *tunnel.MessageWrapper, httpids *util.SessionList, endpoints []serviceconfig.ConfiguredEndpoint, dataflow chan *tunnel.MessageWrapper) {
func handleHTTPControl(agentName string, in *tunnel.MessageWrapper, httpids *util.SessionList, endpoints []serviceconfig.ConfiguredEndpoint, dataflow chan *tunnel.MessageWrapper) {
tunnelControl := in.GetHttpTunnelControl() // caller ensures this will work
switch controlMessage := tunnelControl.ControlType.(type) {
case *tunnel.HttpTunnelControl_CancelRequest:
Expand All @@ -253,7 +253,7 @@ func handleHTTPControl(in *tunnel.MessageWrapper, httpids *util.SessionList, end
found := false
for _, endpoint := range endpoints {
if endpoint.Configured && endpoint.Type == req.Type && endpoint.Name == req.Name {
go endpoint.Instance.ExecuteHTTPRequest(dataflow, req)
go endpoint.Instance.ExecuteHTTPRequest(agentName, dataflow, req)
found = true
break
}
Expand Down
2 changes: 1 addition & 1 deletion internal/serviceconfig/awsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func MakeAwsEndpoint(name string, configBytes []byte, secretsLoader secrets.Secr

// ExecuteHTTPRequest does the actual call to connect to HTTP, and will send the data back over the
// tunnel.
func (a *AwsEndpoint) ExecuteHTTPRequest(dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
func (a *AwsEndpoint) ExecuteHTTPRequest(_ string, dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
zap.S().Debugf("Running request %v", req)
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
Expand Down
2 changes: 1 addition & 1 deletion internal/serviceconfig/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ConfiguredEndpoint struct {
}

type httpRequestProcessor interface {
ExecuteHTTPRequest(chan *tunnel.MessageWrapper, *tunnel.OpenHTTPTunnelRequest)
ExecuteHTTPRequest(agentName string, dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest)
}

func (e *ConfiguredEndpoint) String() string {
Expand Down
6 changes: 5 additions & 1 deletion internal/serviceconfig/generic_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (ep *GenericEndpoint) unmutateURI(typ string, method string, uri string, cl

// ExecuteHTTPRequest does the actual call to connect to HTTP, and will send the data back over the
// tunnel.
func (ep *GenericEndpoint) ExecuteHTTPRequest(dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
func (ep *GenericEndpoint) ExecuteHTTPRequest(agentName string, dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
zap.S().Debugf("Running request %v", req)
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
Expand Down Expand Up @@ -250,6 +250,10 @@ func (ep *GenericEndpoint) ExecuteHTTPRequest(dataflow chan *tunnel.MessageWrapp
return
}

if agentName != "" {
httpRequest.Header.Set("x-opsmx-agent-name", agentName)
}

creds := ep.config.Credentials
switch creds.Type {
case "basic":
Expand Down
2 changes: 1 addition & 1 deletion internal/serviceconfig/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (ke *KubernetesEndpoint) loadServiceAccount() (*kubeContext, error) {

// ExecuteHTTPRequest does the actual call to connect to HTTP, and will send the data back over the
// tunnel.
func (ke *KubernetesEndpoint) ExecuteHTTPRequest(dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
func (ke *KubernetesEndpoint) ExecuteHTTPRequest(_ string, dataflow chan *tunnel.MessageWrapper, req *tunnel.OpenHTTPTunnelRequest) {
c := ke.makeServerContextFields()

// TODO: A ServerCA is technically optional, but we might want to fail if it's not present...
Expand Down

0 comments on commit af94e49

Please sign in to comment.