Skip to content

Commit

Permalink
fix: fix doubled slash in path. refine how zero trust contacts consul
Browse files Browse the repository at this point in the history
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
  • Loading branch information
dovholuknf committed Mar 22, 2024
1 parent 5541125 commit 117d3ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions internal/handler/registercenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"encoding/json"
"errors"
"fmt"
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
"net/http"

"github.com/edgexfoundry/edgex-ui-go/internal/common"
"github.com/edgexfoundry/edgex-ui-go/internal/container"
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
"github.com/edgexfoundry/go-mod-registry/v3/pkg/types"
"github.com/edgexfoundry/go-mod-registry/v3/registry"
)
Expand All @@ -42,7 +42,7 @@ func (rh *ResourceHandler) GetRegisteredServiceAll(w http.ResponseWriter, r *htt
return
}
}

client, err := rh.registryCenterClient(token)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -84,13 +84,13 @@ func (rh *ResourceHandler) getAclTokenOfConsul(w http.ResponseWriter, r *http.Re
var acl struct{ SecretID string }
client := &http.Client{}
sp := bootstrapContainer.SecretProviderExtFrom(rh.dic.Get)
var consulPath string
var url string
if sp.IsZeroTrustEnabled() {
consulPath = AclOfConsulPathProxied
url = fmt.Sprintf("http://%s:%d%s", config.Registry.Host, config.APIGateway.ApplicationPort, AclOfConsulPathDirect)
} else {
consulPath = AclOfConsulPathDirect
url = fmt.Sprintf("http://%s:%d%s", config.APIGateway.Server, config.APIGateway.ApplicationPort, AclOfConsulPathProxied)
}
url := fmt.Sprintf("http://%s:%d%s", config.APIGateway.Server, config.APIGateway.ApplicationPort, consulPath)

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err, http.StatusUnauthorized
Expand All @@ -102,9 +102,11 @@ func (rh *ResourceHandler) getAclTokenOfConsul(w http.ResponseWriter, r *http.Re
if err != nil {
return "", err, resp.StatusCode
}

if err := json.NewDecoder(resp.Body).Decode(&acl); err != nil {
return "", err, http.StatusUnauthorized
}

if resp.StatusCode != http.StatusOK {
return "", errors.New(""), resp.StatusCode
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
metadataSvcName = "core-metadata"
Authorization = "Authorization"
AclOfConsulPathDirect = "/v1/acl/token/self"
AclOfConsulPathProxied = "/consul/" + AclOfConsulPathDirect
AclOfConsulPathProxied = "/consul" + AclOfConsulPathDirect
)

type ResourceHandler struct {
Expand Down

0 comments on commit 117d3ca

Please sign in to comment.