Skip to content

Commit

Permalink
Fix create policy API and descriptor to return Conflict status (#4350)
Browse files Browse the repository at this point in the history
* Fix API description for create user and policy

- Return status conlict on auth already exists
- Update swagger of create user and policy - can return conflict

* fix esti test to verify conflict instead of bad request
  • Loading branch information
nopcoder authored Oct 11, 2022
1 parent 649d93d commit 5d7107d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
8 changes: 6 additions & 2 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,8 @@ paths:
$ref: "#/components/schemas/Error"
401:
$ref: "#/components/responses/Unauthorized"
409:
$ref: "#/components/responses/Conflict"
default:
$ref: "#/components/responses/ServerError"

Expand Down Expand Up @@ -1474,10 +1476,12 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Policy"
401:
$ref: "#/components/responses/Unauthorized"
400:
$ref: "#/components/responses/ValidationError"
401:
$ref: "#/components/responses/Unauthorized"
409:
$ref: "#/components/responses/Conflict"
default:
$ref: "#/components/responses/ServerError"

Expand Down
16 changes: 14 additions & 2 deletions clients/java/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion clients/java/docs/AuthApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions clients/java/src/main/java/io/lakefs/clients/api/AuthApi.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion clients/python/docs/AuthApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func TestLakectlHelp(t *testing.T) {
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" --help", false, "lakectl_help", emptyVars)
RunCmdAndVerifySuccessWithFile(t, Lakectl(), true, "lakectl_help", emptyVars)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" --help", true, "lakectl_help", emptyVars)

}

func TestLakectlBasicRepoActions(t *testing.T) {
Expand Down Expand Up @@ -165,7 +164,6 @@ func TestLakectlBranchAndTagValidation(t *testing.T) {
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" tag create lakefs://"+repoName+"/"+vars["TAG"]+" lakefs://"+repoName+"/"+mainBranch+"^1", false, "lakectl_tag_create", vars)
vars["TAG"] = "tag4"
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" tag create lakefs://"+repoName+"/"+vars["TAG"]+" lakefs://"+repoName+"/"+mainBranch+"~", false, "lakectl_tag_create", vars)

}

func TestLakectlMergeAndStrategies(t *testing.T) {
Expand Down Expand Up @@ -214,7 +212,7 @@ func TestLakectlMergeAndStrategies(t *testing.T) {
vars["MESSAGE"] = commitMessage
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" commit lakefs://"+repoName+"/"+mainBranch+" -m \""+commitMessage+"\"", false, "lakectl_commit", vars)

//upload 'file2' on 'feature', delete 'file1' and commit
// upload 'file2' on 'feature', delete 'file1' and commit
vars["BRANCH"] = featureBranch
vars["FILE_PATH"] = filePath2
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" fs upload -s files/ro_1k lakefs://"+repoName+"/"+featureBranch+"/"+filePath2, false, "lakectl_fs_upload", vars)
Expand All @@ -239,7 +237,7 @@ func TestLakectlMergeAndStrategies(t *testing.T) {
vars["MESSAGE"] = commitMessage
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" commit lakefs://"+repoName+"/"+mainBranch+" -m \""+commitMessage+"\"", false, "lakectl_commit", vars)

//delete 'file1' on 'feature' again, and commit
// delete 'file1' on 'feature' again, and commit
vars["BRANCH"] = featureBranch
RunCmdAndVerifySuccess(t, Lakectl()+" fs rm lakefs://"+repoName+"/"+featureBranch+"/"+filePath1, false, "", vars)
commitMessage = "delete file on feature branch again"
Expand Down Expand Up @@ -323,7 +321,6 @@ func TestLakectlAnnotate(t *testing.T) {

RunCmdAndVerifySuccessWithFile(t, Lakectl()+" annotate lakefs://"+repoName+"/"+mainBranch+"/iii/kkk/l", false, "lakectl_annotate_iiikkklll", vars)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" annotate lakefs://"+repoName+"/"+mainBranch+"/iii/kkk/l --recursive", false, "lakectl_annotate_iiikkklll", vars)

}

func TestLakectlAuthUsers(t *testing.T) {
Expand All @@ -333,12 +330,12 @@ func TestLakectlAuthUsers(t *testing.T) {
"ID": userName,
}

//Not Found
// Not Found
RunCmdAndVerifyFailure(t, Lakectl()+" auth users delete --id "+userName, false, "user not found\n404 Not Found\n", vars)

// Check unique
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" auth users create --id "+userName, false, "lakectl_auth_users_create_success", vars)
RunCmdAndVerifyFailure(t, Lakectl()+" auth users create --id "+userName, false, "Already exists\n400 Bad Request\n", vars)
RunCmdAndVerifyFailure(t, Lakectl()+" auth users create --id "+userName, false, "Already exists\n409 Conflict\n", vars)

// Cleanup
RunCmdAndVerifySuccess(t, Lakectl()+" auth users delete --id "+userName, false, "User deleted successfully\n", vars)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request, body Cre
Source: "internal",
Email: parsedEmail,
}
_, err := c.Auth.CreateUser(ctx, u)

_, err := c.Auth.CreateUser(ctx, u)
if c.handleAPIError(ctx, w, err) {
c.Logger.WithError(err).WithField("username", u.Username).Warn("failed creating user")
return
Expand Down Expand Up @@ -1742,7 +1742,7 @@ func (c *Controller) handleAPIError(ctx context.Context, w http.ResponseWriter,
writeError(w, http.StatusGone, "No data")

case errors.Is(err, auth.ErrAlreadyExists):
writeError(w, http.StatusBadRequest, "Already exists")
writeError(w, http.StatusConflict, "Already exists")

case errors.Is(err, graveler.ErrTooManyTries):
writeError(w, http.StatusLocked, "Too many attempts, try again later")
Expand Down

0 comments on commit 5d7107d

Please sign in to comment.