Skip to content

Commit

Permalink
Fix overwriteEndpoint bug (#4876)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Quandt <thquad@gmail.com>
  • Loading branch information
thquad authored and richard-cox committed Apr 16, 2021
1 parent 9a2bc7c commit 2f2bf22
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/jetstream/cnsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,18 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk
}
// check if we've already got this APIEndpoint in this DB
for _, duplicate := range duplicateEndpoints {
// cant create same admin endpoint
if len(duplicate.Creator) == 0 {
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
http.StatusBadRequest,
"Can not register same admin endpoint multiple times",
"Can not register same admin endpoint multiple times",
)
}
if duplicate.Creator == userId && !overwriteEndpoints {

// cant create same user endpoint
// can create same user endpoint if overwriteEndpoint true
if duplicate.Creator == userId || !overwriteEndpoints {
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
http.StatusBadRequest,
"Can not register same endpoint multiple times",
Expand All @@ -165,12 +169,11 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk
}
}

if isAdmin {
// remove all endpoints with same APIEndpoint
for _, duplicate := range duplicateEndpoints {
p.doUnregisterCluster(duplicate.GUID)
}
// because of the check above, no admin endpoint or userendpoint without overwriteEndpoints=true will reach here
for _, duplicate := range duplicateEndpoints {
p.doUnregisterCluster(duplicate.GUID)
}

}

h := sha1.New()
Expand Down

0 comments on commit 2f2bf22

Please sign in to comment.