From 855e9ce023790136607206f2412246f1f9618c11 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Thu, 24 Feb 2022 14:29:28 +0200 Subject: [PATCH 01/10] avoiding redirect automatically --- cmd/lakectl/cmd/root.go | 9 +++++++++ pkg/api/ui_handler.go | 1 + 2 files changed, 10 insertions(+) diff --git a/cmd/lakectl/cmd/root.go b/cmd/lakectl/cmd/root.go index e669538914c..f4b3e843d91 100644 --- a/cmd/lakectl/cmd/root.go +++ b/cmd/lakectl/cmd/root.go @@ -108,9 +108,18 @@ func getClient() *api.ClientWithResponses { if u.Path == "" || u.Path == "/" { serverEndpoint = strings.TrimRight(serverEndpoint, "/") + api.BaseURL } + //httpClient := &http.Client{ + // + // // avoid redirect automatically + // CheckRedirect: func(req *http.Request, via []*http.Request) error { + // return http.ErrUseLastResponse + // }, + //} + client, err := api.NewClientWithResponses( serverEndpoint, api.WithRequestEditorFn(basicAuthProvider.Intercept), + //api.WithHTTPClient(httpClient), ) if err != nil { Die(fmt.Sprintf("could not initialize API client: %s", err), 1) diff --git a/pkg/api/ui_handler.go b/pkg/api/ui_handler.go index d210197c4b9..1b062149592 100644 --- a/pkg/api/ui_handler.go +++ b/pkg/api/ui_handler.go @@ -80,6 +80,7 @@ func NewHandlerWithDefault(root http.FileSystem, handler http.Handler, defaultPa } _, err := root.Open(path.Clean(urlPath)) if err != nil && os.IsNotExist(err) { + //http.Redirect(w, r, defaultPath, http.StatusFound) r.URL.Path = defaultPath } // consistent content-type From 704cacda10138160f67ce2e520f51e71c87eb3dc Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Thu, 24 Feb 2022 19:04:43 +0200 Subject: [PATCH 02/10] Changed all CLI commands to fail on unexpected status code returned --- cmd/lakectl/cmd/abuse.go | 4 +-- cmd/lakectl/cmd/annotate.go | 11 ++++--- cmd/lakectl/cmd/auth.go | 53 +++++++++++++++--------------- cmd/lakectl/cmd/branch.go | 13 ++++---- cmd/lakectl/cmd/branch_protect.go | 7 ++-- cmd/lakectl/cmd/cat_hook_output.go | 3 +- cmd/lakectl/cmd/commit.go | 3 +- cmd/lakectl/cmd/common_helpers.go | 29 ++++++++++++++++ cmd/lakectl/cmd/diff.go | 5 +-- cmd/lakectl/cmd/fs.go | 8 ++--- cmd/lakectl/cmd/gc.go | 7 ++-- cmd/lakectl/cmd/ingest.go | 3 +- cmd/lakectl/cmd/log.go | 3 +- cmd/lakectl/cmd/merge.go | 3 +- cmd/lakectl/cmd/metastore.go | 3 +- cmd/lakectl/cmd/refs.go | 5 +-- cmd/lakectl/cmd/repo.go | 13 ++++---- cmd/lakectl/cmd/root.go | 16 ++++----- cmd/lakectl/cmd/runs_describe.go | 4 +-- cmd/lakectl/cmd/runs_list.go | 3 +- cmd/lakectl/cmd/show.go | 3 +- cmd/lakectl/cmd/tag.go | 13 ++++---- docs/reference/commands.md | 2 +- pkg/api/ui_handler.go | 3 +- 24 files changed, 130 insertions(+), 87 deletions(-) diff --git a/cmd/lakectl/cmd/abuse.go b/cmd/lakectl/cmd/abuse.go index a88db02417b..abd53253210 100644 --- a/cmd/lakectl/cmd/abuse.go +++ b/cmd/lakectl/cmd/abuse.go @@ -119,7 +119,7 @@ var abuseRandomWritesCmd = &cobra.Command{ client := getClient() resp, err := client.GetRepositoryWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) repo := resp.JSON200 storagePrefix := repo.StorageNamespace @@ -177,7 +177,7 @@ var abuseCreateBranchesCmd = &cobra.Command{ After: ¤tOffset, Amount: &amount, }) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) for _, ref := range res.JSON200.Results { if !strings.HasPrefix(ref.Id, branchPrefix) { diff --git a/cmd/lakectl/cmd/annotate.go b/cmd/lakectl/cmd/annotate.go index 6358b331de0..bce21fb75d8 100644 --- a/cmd/lakectl/cmd/annotate.go +++ b/cmd/lakectl/cmd/annotate.go @@ -1,6 +1,7 @@ package cmd import ( + "net/http" "strings" "github.com/spf13/cobra" @@ -31,8 +32,8 @@ var annotateCmd = &cobra.Command{ client := getClient() pfx := api.PaginationPrefix(*pathURI.Path) context := cmd.Context() - res, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, &api.ListObjectsParams{Prefix: &pfx}) - DieOnResponseError(res, err) + resp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, &api.ListObjectsParams{Prefix: &pfx}) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) var from string for { params := &api.ListObjectsParams{ @@ -40,20 +41,20 @@ var annotateCmd = &cobra.Command{ After: api.PaginationAfterPtr(from), } resp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, params) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) for _, obj := range resp.JSON200.Results { logCommitsParams := &api.LogCommitsParams{ Amount: api.PaginationAmountPtr(1), Objects: &[]string{obj.Path}, } res, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) data := objectCommitData{ Object: obj.Path, } if len(res.JSON200.Results) > 0 { data.Commit = res.JSON200.Results[0] - data.CommitMessage = splitOnNewLine(stringTrimLen((res.JSON200.Results[0].Message), annotateMessageSize)) + data.CommitMessage = splitOnNewLine(stringTrimLen(res.JSON200.Results[0].Message, annotateMessageSize)) } Write(annotateTemplate, data) } diff --git a/cmd/lakectl/cmd/auth.go b/cmd/lakectl/cmd/auth.go index 2ee921397e9..99ba3d5b267 100644 --- a/cmd/lakectl/cmd/auth.go +++ b/cmd/lakectl/cmd/auth.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "io" + "net/http" "os" "strings" "time" @@ -63,7 +64,7 @@ var authUsersList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) users := resp.JSON200.Results rows := make([][]interface{}, len(users)) @@ -87,7 +88,7 @@ var authUsersCreate = &cobra.Command{ resp, err := clt.CreateUserWithResponse(cmd.Context(), api.CreateUserJSONRequestBody{ Id: id, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) user := resp.JSON201 Write(userCreatedTemplate, user) }, @@ -101,7 +102,7 @@ var authUsersDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeleteUserWithResponse(cmd.Context(), id) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("User deleted successfully\n") }, } @@ -125,7 +126,7 @@ var authUsersGroupsList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) groups := resp.JSON200.Results rows := make([][]interface{}, len(groups)) @@ -160,7 +161,7 @@ var authUsersPoliciesList = &cobra.Command{ Amount: api.PaginationAmountPtr(amount), Effective: &effective, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) policies := resp.JSON200.Results rows := make([][]interface{}, 0) @@ -185,7 +186,7 @@ var authUsersPoliciesAttach = &cobra.Command{ policy, _ := cmd.Flags().GetString("policy") clt := getClient() resp, err := clt.AttachPolicyToUserWithResponse(cmd.Context(), id, policy) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Fmt("Policy attached successfully\n") }, } @@ -199,7 +200,7 @@ var authUsersPoliciesDetach = &cobra.Command{ clt := getClient() resp, err := clt.DetachPolicyFromUserWithResponse(cmd.Context(), id, policy) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Policy detached successfully\n") }, @@ -219,12 +220,12 @@ var authUsersCredentialsCreate = &cobra.Command{ if id == "" { resp, err := clt.GetCurrentUserWithResponse(cmd.Context()) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) id = resp.JSON200.User.Id } resp, err := clt.CreateCredentialsWithResponse(cmd.Context(), id) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) credentials := resp.JSON201 Write(credentialsCreatedTemplate, credentials) @@ -241,11 +242,11 @@ var authUsersCredentialsDelete = &cobra.Command{ if id == "" { resp, err := clt.GetCurrentUserWithResponse(cmd.Context()) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) id = resp.JSON200.User.Id } resp, err := clt.DeleteCredentialsWithResponse(cmd.Context(), id, accessKeyID) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Credentials deleted successfully\n") }, @@ -262,7 +263,7 @@ var authUsersCredentialsList = &cobra.Command{ clt := getClient() if id == "" { resp, err := clt.GetCurrentUserWithResponse(cmd.Context()) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) id = resp.JSON200.User.Id } @@ -270,7 +271,7 @@ var authUsersCredentialsList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) credentials := resp.JSON200.Results rows := make([][]interface{}, len(credentials)) @@ -302,7 +303,7 @@ var authGroupsList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) groups := resp.JSON200.Results rows := make([][]interface{}, len(groups)) @@ -326,7 +327,7 @@ var authGroupsCreate = &cobra.Command{ resp, err := clt.CreateGroupWithResponse(cmd.Context(), api.CreateGroupJSONRequestBody{ Id: id, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) group := resp.JSON201 Write(groupCreatedTemplate, group) }, @@ -340,7 +341,7 @@ var authGroupsDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeleteGroupWithResponse(cmd.Context(), id) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Group deleted successfully\n") }, } @@ -364,7 +365,7 @@ var authGroupsListMembers = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) users := resp.JSON200.Results rows := make([][]interface{}, len(users)) @@ -386,7 +387,7 @@ var authGroupsAddMember = &cobra.Command{ clt := getClient() resp, err := clt.AddGroupMembershipWithResponse(cmd.Context(), id, user) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Fmt("User successfully added\n") }, } @@ -400,7 +401,7 @@ var authGroupsRemoveMember = &cobra.Command{ clt := getClient() resp, err := clt.DeleteGroupMembershipWithResponse(cmd.Context(), id, user) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("User successfully removed\n") }, } @@ -424,7 +425,7 @@ var authGroupsPoliciesList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) policies := resp.JSON200.Results rows := make([][]interface{}, 0) @@ -450,7 +451,7 @@ var authGroupsPoliciesAttach = &cobra.Command{ clt := getClient() resp, err := clt.AttachPolicyToGroupWithResponse(cmd.Context(), id, policy) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Fmt("Policy attached successfully\n") }, @@ -465,7 +466,7 @@ var authGroupsPoliciesDetach = &cobra.Command{ clt := getClient() resp, err := clt.DetachPolicyFromGroupWithResponse(cmd.Context(), id, policy) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Policy detached successfully\n") }, @@ -490,7 +491,7 @@ var authPoliciesList = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) policies := resp.JSON200.Results rows := make([][]interface{}, len(policies)) @@ -534,7 +535,7 @@ var authPoliciesCreate = &cobra.Command{ Id: id, Statement: doc.Statement, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) createdPolicy := resp.JSON201 Write(policyCreatedTemplate, struct { @@ -561,7 +562,7 @@ var authPoliciesShow = &cobra.Command{ clt := getClient() resp, err := clt.GetPolicyWithResponse(cmd.Context(), id) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) policy := *resp.JSON200 Write(policyDetailsTemplate, struct { @@ -584,7 +585,7 @@ var authPoliciesDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeletePolicyWithResponse(cmd.Context(), id) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Policy deleted successfully\n") }, } diff --git a/cmd/lakectl/cmd/branch.go b/cmd/lakectl/cmd/branch.go index 37f7e4707c9..2189be6978b 100644 --- a/cmd/lakectl/cmd/branch.go +++ b/cmd/lakectl/cmd/branch.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "net/http" "strings" "github.com/spf13/cobra" @@ -36,7 +37,7 @@ var branchListCmd = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) refs := resp.JSON200.Results rows := make([][]interface{}, len(refs)) @@ -70,7 +71,7 @@ var branchCreateCmd = &cobra.Command{ Name: u.Ref, Source: sourceURI.Ref, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Fmt("created branch '%s' %s\n", u.Ref, string(resp.Body)) }, } @@ -88,7 +89,7 @@ var branchDeleteCmd = &cobra.Command{ u := MustParseRefURI("branch", args[0]) Fmt("Branch: %s\n", u.String()) resp, err := client.DeleteBranchWithResponse(cmd.Context(), u.Repository, u.Ref) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) }, } @@ -122,7 +123,7 @@ var branchRevertCmd = &cobra.Command{ ParentNumber: parentNumber, Ref: commitRef, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("commit %s successfully reverted\n", commitRef) } }, @@ -178,7 +179,7 @@ var branchResetCmd = &cobra.Command{ return } resp, err := clt.ResetBranchWithResponse(cmd.Context(), u.Repository, u.Ref, api.ResetBranchJSONRequestBody(reset)) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) }, } @@ -191,7 +192,7 @@ var branchShowCmd = &cobra.Command{ u := MustParseRefURI("branch", args[0]) Fmt("Branch: %s\n", u.String()) resp, err := client.GetBranchWithResponse(cmd.Context(), u.Repository, u.Ref) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) branch := resp.JSON200 Fmt("%s\n", branch) }, diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index a12c526cfe2..ae981946f7b 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" + "net/http" ) const ( @@ -24,7 +25,7 @@ var branchProtectListCmd = &cobra.Command{ client := getClient() u := MustParseRepoURI("repository", args[0]) resp, err := client.GetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) patterns := make([][]interface{}, len(*resp.JSON200)) for i, rule := range *resp.JSON200 { patterns[i] = []interface{}{rule.Pattern} @@ -48,7 +49,7 @@ var branchProtectAddCmd = &cobra.Command{ resp, err := client.CreateBranchProtectionRuleWithResponse(cmd.Context(), u.Repository, api.CreateBranchProtectionRuleJSONRequestBody{ Pattern: args[1], }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) }, } @@ -64,7 +65,7 @@ var branchProtectDeleteCmd = &cobra.Command{ resp, err := client.DeleteBranchProtectionRuleWithResponse(cmd.Context(), u.Repository, api.DeleteBranchProtectionRuleJSONRequestBody{ Pattern: args[1], }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) }, } diff --git a/cmd/lakectl/cmd/cat_hook_output.go b/cmd/lakectl/cmd/cat_hook_output.go index a99e6042777..9067ccdfbc7 100644 --- a/cmd/lakectl/cmd/cat_hook_output.go +++ b/cmd/lakectl/cmd/cat_hook_output.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/spf13/cobra" + "net/http" ) const catHookOutputRequiredArgs = 3 @@ -20,7 +21,7 @@ var catHookOutputCmd = &cobra.Command{ client := getClient() ctx := cmd.Context() resp, err := client.GetRunHookOutputWithResponse(ctx, u.Repository, runID, hookRunID) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) Fmt("%s\n", string(resp.Body)) }, } diff --git a/cmd/lakectl/cmd/commit.go b/cmd/lakectl/cmd/commit.go index 398934c2c17..7c6a0e81771 100644 --- a/cmd/lakectl/cmd/commit.go +++ b/cmd/lakectl/cmd/commit.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + "net/http" "strings" "github.com/spf13/cobra" @@ -57,7 +58,7 @@ var commitCmd = &cobra.Command{ Message: message, Metadata: &metadata, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) commit := resp.JSON201 Write(CommitCreateTemplate, struct { diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index f9a7675a78c..7e0696ed1db 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -9,7 +9,9 @@ import ( "io" "net/http" "os" + "reflect" "regexp" + "strconv" "strings" "text/template" "time" @@ -41,6 +43,8 @@ const ( const internalPageSize = 1000 // when retreiving all records, use this page size under the hood const defaultAmountArgumentValue = 100 // when no amount is specified, use this value for the argument +const defaultResponseOnSwaggerClient = http.StatusNoContent + const resourceListTemplate = `{{.Table | table -}} {{.Pagination | paginate }} ` @@ -206,7 +210,32 @@ func DieOnResponseError(response interface{}, err error) { DieErr(retrievedErr) } } +func DieOnErrorOrUnexpectedStatusCode(response interface{}, err error, expectedStatusCode int) { + DieOnResponseError(response, err) + var statusCode int + if httpResponse, ok := response.(*http.Response); ok { + statusCode = httpResponse.StatusCode + } else { + r := reflect.Indirect(reflect.ValueOf(response)) + f := r.FieldByName("HTTPResponse") + httpResponse, _ := f.Interface().(*http.Response) + if httpResponse != nil { + statusCode = httpResponse.StatusCode + } + } + + if statusCode == 0 { + DieErr(fmt.Errorf("could not get status code from response")) + } + if statusCode != expectedStatusCode { + // redirect to not found page + if statusCode == 302 { + DieErr(fmt.Errorf("got not found error, probablly wrong endpoint url")) + } + DieErr(fmt.Errorf("got unexpected status code: " + strconv.Itoa(statusCode) + ", expected: " + strconv.Itoa(expectedStatusCode))) + } +} func DieOnHTTPError(httpResponse *http.Response) { err := helpers.HTTPResponseAsError(httpResponse) if err != nil { diff --git a/cmd/lakectl/cmd/diff.go b/cmd/lakectl/cmd/diff.go index 2e29668cc7a..9d36e0c5092 100644 --- a/cmd/lakectl/cmd/diff.go +++ b/cmd/lakectl/cmd/diff.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "net/http" "os" "github.com/jedib0t/go-pretty/v6/text" @@ -83,7 +84,7 @@ func printDiffBranch(ctx context.Context, client api.ClientWithResponsesInterfac After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(int(pageSize)), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) for _, line := range resp.JSON200.Results { FmtDiff(line, false) @@ -111,7 +112,7 @@ func printDiffRefs(ctx context.Context, client api.ClientWithResponsesInterface, Amount: api.PaginationAmountPtr(amount), Type: diffType, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) for _, line := range resp.JSON200.Results { FmtDiff(line, true) diff --git a/cmd/lakectl/cmd/fs.go b/cmd/lakectl/cmd/fs.go index 5eeacbf172c..7fc765c3c00 100644 --- a/cmd/lakectl/cmd/fs.go +++ b/cmd/lakectl/cmd/fs.go @@ -44,7 +44,7 @@ var fsStatCmd = &cobra.Command{ res, err := client.StatObjectWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, &api.StatObjectParams{ Path: *pathURI.Path, }) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) stat := res.JSON200 Write(fsStatTemplate, stat) @@ -88,7 +88,7 @@ var fsListCmd = &cobra.Command{ Delimiter: ¶msDelimiter, } resp, err := client.ListObjectsWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, params) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) results := resp.JSON200.Results // trim prefix if non recursive @@ -292,7 +292,7 @@ var fsStageCmd = &cobra.Command{ resp, err := client.StageObjectWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, &api.StageObjectParams{ Path: *pathURI.Path, }, api.StageObjectJSONRequestBody(obj)) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Write(fsStatTemplate, resp.JSON201) }, @@ -365,7 +365,7 @@ var fsRmCmd = &cobra.Command{ Delimiter: ¶msDelimiter, } resp, err := client.ListObjectsWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, params) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) results := resp.JSON200.Results for i := range results { diff --git a/cmd/lakectl/cmd/gc.go b/cmd/lakectl/cmd/gc.go index 6752c028851..47c7f02bb35 100644 --- a/cmd/lakectl/cmd/gc.go +++ b/cmd/lakectl/cmd/gc.go @@ -70,10 +70,7 @@ Example configuration file: } client := getClient() resp, err := client.SetGarbageCollectionRulesWithResponse(cmd.Context(), u.Repository, body) - DieOnResponseError(resp, err) - if resp.StatusCode() != http.StatusNoContent { - Die("Failed to update config", 1) - } + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) }, } @@ -87,7 +84,7 @@ var gcGetConfigCmd = &cobra.Command{ isJSON := MustBool(cmd.Flags().GetBool(jsonFlagName)) client := getClient() resp, err := client.GetGarbageCollectionRulesWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) if isJSON { Write("{{ . | json }}", resp.JSON200) } else { diff --git a/cmd/lakectl/cmd/ingest.go b/cmd/lakectl/cmd/ingest.go index f15fa0b0927..9631c5ab1fd 100644 --- a/cmd/lakectl/cmd/ingest.go +++ b/cmd/lakectl/cmd/ingest.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "net/http" "strings" "sync" "time" @@ -27,7 +28,7 @@ func stageWorker(ctx context.Context, client api.ClientWithResponsesInterface, w for req := range requests { resp, err := client.StageObjectWithResponse( ctx, req.repository, req.branch, req.params, req.body) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) responses <- resp } } diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index c9b3a00599a..f5cf8f0ba00 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" + "net/http" ) const commitsTemplate = `{{ range $val := .Commits }} @@ -54,7 +55,7 @@ var logCmd = &cobra.Command{ } for pagination.HasMore { res, err := client.LogCommitsWithResponse(cmd.Context(), branchURI.Repository, branchURI.Ref, logCommitsParams) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) pagination = res.JSON200.Pagination logCommitsParams.After = api.PaginationAfterPtr(pagination.NextOffset) data := struct { diff --git a/cmd/lakectl/cmd/merge.go b/cmd/lakectl/cmd/merge.go index b710774339f..3b00af9459f 100644 --- a/cmd/lakectl/cmd/merge.go +++ b/cmd/lakectl/cmd/merge.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" + "net/http" ) const ( @@ -35,7 +36,7 @@ var mergeCmd = &cobra.Command{ if resp != nil && resp.JSON409 != nil { Die("Conflict found.", 1) } - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) Write(mergeCreateTemplate, struct { Merge FromTo diff --git a/cmd/lakectl/cmd/metastore.go b/cmd/lakectl/cmd/metastore.go index 6b92d815a5c..657dc42e6e3 100644 --- a/cmd/lakectl/cmd/metastore.go +++ b/cmd/lakectl/cmd/metastore.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "net/http" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -286,7 +287,7 @@ var createSymlinkCmd = &cobra.Command{ if err != nil { DieErr(err) } - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusCreated) location := res.JSON201.Location err = metastore.CopyOrMergeToSymlink(cmd.Context(), fromClient, toClient, fromDB, fromTable, toDB, toTable, location, cfg.GetFixSparkPlaceholder()) diff --git a/cmd/lakectl/cmd/refs.go b/cmd/lakectl/cmd/refs.go index 41a5923e4c8..4be4b7c6e17 100644 --- a/cmd/lakectl/cmd/refs.go +++ b/cmd/lakectl/cmd/refs.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "io" + "net/http" "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" @@ -48,7 +49,7 @@ Since a bare repo is expected, in case of transient failure, delete the reposito // execute the restore operation client := getClient() resp, err := client.RestoreRefsWithResponse(cmd.Context(), repoURI.Repository, api.RestoreRefsJSONRequestBody(manifest)) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) Write(refsRestoreSuccess, nil) }, } @@ -63,7 +64,7 @@ var refsDumpCmd = &cobra.Command{ Fmt("Repository: %s\n", repoURI.String()) client := getClient() resp, err := client.DumpRefsWithResponse(cmd.Context(), repoURI.Repository) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) Write(metadataDumpTemplate, struct { Response interface{} diff --git a/cmd/lakectl/cmd/repo.go b/cmd/lakectl/cmd/repo.go index 36e38bb2a08..69f695ff19c 100644 --- a/cmd/lakectl/cmd/repo.go +++ b/cmd/lakectl/cmd/repo.go @@ -1,6 +1,7 @@ package cmd import ( + "net/http" "time" "github.com/spf13/cobra" @@ -30,7 +31,7 @@ var repoListCmd = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) repos := res.JSON200.Results rows := make([][]interface{}, len(repos)) for i, repo := range repos { @@ -64,10 +65,10 @@ var repoCreateCmd = &cobra.Command{ StorageNamespace: args[1], DefaultBranch: &defaultBranch, }) - DieOnResponseError(respCreateRepo, err) + DieOnErrorOrUnexpectedStatusCode(respCreateRepo, err, http.StatusCreated) respGetRepo, err := clt.GetRepositoryWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(respGetRepo, err) + DieOnErrorOrUnexpectedStatusCode(respGetRepo, err, http.StatusOK) repo := respGetRepo.JSON200 Fmt("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n", @@ -99,10 +100,10 @@ var repoCreateBareCmd = &cobra.Command{ Name: u.Repository, StorageNamespace: args[1], }) - DieOnResponseError(respCreateRepo, err) + DieOnErrorOrUnexpectedStatusCode(respCreateRepo, err, http.StatusCreated) respGetRepo, err := clt.GetRepositoryWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(respGetRepo, err) + DieOnErrorOrUnexpectedStatusCode(respGetRepo, err, http.StatusOK) repo := respGetRepo.JSON200 Fmt("Repository '%s' created:\nstorage namespace: %s\ndefault branch: %s\ntimestamp: %d\n", @@ -125,7 +126,7 @@ var repoDeleteCmd = &cobra.Command{ DieFmt("Delete Repository '%s' aborted\n", u.Repository) } resp, err := clt.DeleteRepositoryWithResponse(cmd.Context(), u.Repository) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) Fmt("Repository '%s' deleted\n", u.Repository) }, } diff --git a/cmd/lakectl/cmd/root.go b/cmd/lakectl/cmd/root.go index f4b3e843d91..867fb960218 100644 --- a/cmd/lakectl/cmd/root.go +++ b/cmd/lakectl/cmd/root.go @@ -108,18 +108,18 @@ func getClient() *api.ClientWithResponses { if u.Path == "" || u.Path == "/" { serverEndpoint = strings.TrimRight(serverEndpoint, "/") + api.BaseURL } - //httpClient := &http.Client{ - // - // // avoid redirect automatically - // CheckRedirect: func(req *http.Request, via []*http.Request) error { - // return http.ErrUseLastResponse - // }, - //} + httpClient := &http.Client{ + + // avoid redirect automatically + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } client, err := api.NewClientWithResponses( serverEndpoint, api.WithRequestEditorFn(basicAuthProvider.Intercept), - //api.WithHTTPClient(httpClient), + api.WithHTTPClient(httpClient), ) if err != nil { Die(fmt.Sprintf("could not initialize API client: %s", err), 1) diff --git a/cmd/lakectl/cmd/runs_describe.go b/cmd/lakectl/cmd/runs_describe.go index 1e8ab0d7a31..be73261555d 100644 --- a/cmd/lakectl/cmd/runs_describe.go +++ b/cmd/lakectl/cmd/runs_describe.go @@ -37,7 +37,7 @@ var runsDescribeCmd = &cobra.Command{ // run result information runsRes, err := client.GetRunWithResponse(ctx, u.Repository, runID) - DieOnResponseError(runsRes, err) + DieOnErrorOrUnexpectedStatusCode(runsRes, err, http.StatusOK) runResult := runsRes.JSON200 Write(actionRunResultTemplate, convertRunResultTable(runResult)) @@ -51,7 +51,7 @@ var runsDescribeCmd = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amountForPagination), }) - DieOnResponseError(runHooksRes, err) + DieOnErrorOrUnexpectedStatusCode(runHooksRes, err, http.StatusOK) pagination = runHooksRes.JSON200.Pagination data := struct { Hooks []api.HookRun diff --git a/cmd/lakectl/cmd/runs_list.go b/cmd/lakectl/cmd/runs_list.go index d5f666163f0..ce2705e5a1d 100644 --- a/cmd/lakectl/cmd/runs_list.go +++ b/cmd/lakectl/cmd/runs_list.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" + "net/http" ) const actionsRunsListTemplate = `{{.ActionsRunsTable | table -}} @@ -44,7 +45,7 @@ var runsListCmd = &cobra.Command{ Branch: optionalBranch, Commit: optionalCommit, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) results := resp.JSON200.Results rows := make([][]interface{}, len(results)) diff --git a/cmd/lakectl/cmd/show.go b/cmd/lakectl/cmd/show.go index d0ebf9c2276..4a4eeb02d30 100644 --- a/cmd/lakectl/cmd/show.go +++ b/cmd/lakectl/cmd/show.go @@ -1,6 +1,7 @@ package cmd import ( + "net/http" "strings" "github.com/spf13/cobra" @@ -38,7 +39,7 @@ var showCmd = &cobra.Command{ case "commit": client := getClient() resp, err := client.GetCommitWithResponse(cmd.Context(), u.Repository, identifier) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) commit := resp.JSON200 showMetaRangeID, _ := cmd.Flags().GetBool("show-meta-range-id") diff --git a/cmd/lakectl/cmd/tag.go b/cmd/lakectl/cmd/tag.go index 1946b444e12..10a8186c9cb 100644 --- a/cmd/lakectl/cmd/tag.go +++ b/cmd/lakectl/cmd/tag.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api" + "net/http" ) const tagCreateRequiredArgs = 2 @@ -31,7 +32,7 @@ var tagListCmd = &cobra.Command{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) refs := resp.JSON200.Results rows := make([][]interface{}, len(refs)) @@ -76,11 +77,11 @@ var tagCreateCmd = &cobra.Command{ if force { // checking validity of the commitRef before deleting the old one res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef) - DieOnResponseError(res, err) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) resp, err := client.DeleteTagWithResponse(ctx, tagURI.Repository, tagURI.Ref) if err != nil && (resp == nil || resp.JSON404 == nil) { - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) } } @@ -88,7 +89,7 @@ var tagCreateCmd = &cobra.Command{ Id: tagURI.Ref, Ref: commitRef, }) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) commitID := *resp.JSON201 Fmt("Created tag '%s' (%s)\n", tagURI.Ref, commitID) @@ -110,7 +111,7 @@ var tagDeleteCmd = &cobra.Command{ ctx := cmd.Context() resp, err := client.DeleteTagWithResponse(ctx, u.Repository, u.Ref) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) }, } @@ -125,7 +126,7 @@ var tagShowCmd = &cobra.Command{ ctx := cmd.Context() resp, err := client.GetTagWithResponse(ctx, u.Repository, u.Ref) - DieOnResponseError(resp, err) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) Fmt("%s %s", resp.JSON200.Id, resp.JSON200.CommitId) }, } diff --git a/docs/reference/commands.md b/docs/reference/commands.md index 81efc7c35e2..d75a084ba9d 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -2413,7 +2413,7 @@ lakectl repo create [flags] {:.no_toc} ``` -lakectl create lakefs://some-repo-name s3://some-bucket-name +lakectl repo create lakefs://some-repo-name s3://some-bucket-name ``` #### Options diff --git a/pkg/api/ui_handler.go b/pkg/api/ui_handler.go index 1b062149592..f50d0d3f8d2 100644 --- a/pkg/api/ui_handler.go +++ b/pkg/api/ui_handler.go @@ -80,7 +80,8 @@ func NewHandlerWithDefault(root http.FileSystem, handler http.Handler, defaultPa } _, err := root.Open(path.Clean(urlPath)) if err != nil && os.IsNotExist(err) { - //http.Redirect(w, r, defaultPath, http.StatusFound) + fmt.Println("redirecting...") + http.Redirect(w, r, defaultPath, http.StatusFound) r.URL.Path = defaultPath } // consistent content-type From 3066a9cdd3e71fd0518d5b08328d682e335a420e Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Thu, 24 Feb 2022 19:32:09 +0200 Subject: [PATCH 03/10] Format fixes --- cmd/lakectl/cmd/common_helpers.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 7e0696ed1db..fa23bb87b0e 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -225,17 +225,17 @@ func DieOnErrorOrUnexpectedStatusCode(response interface{}, err error, expectedS } if statusCode == 0 { - DieErr(fmt.Errorf("could not get status code from response")) + Die("could not get status code from response", 1) } if statusCode != expectedStatusCode { - // redirect to not found page + // redirected to not found page if statusCode == 302 { - DieErr(fmt.Errorf("got not found error, probablly wrong endpoint url")) + Die("got not found error, probably wrong endpoint url", 1) } - DieErr(fmt.Errorf("got unexpected status code: " + strconv.Itoa(statusCode) + ", expected: " + strconv.Itoa(expectedStatusCode))) + Die("got unexpected status code: "+strconv.Itoa(statusCode)+", expected: "+strconv.Itoa(expectedStatusCode), 1) } - } + func DieOnHTTPError(httpResponse *http.Response) { err := helpers.HTTPResponseAsError(httpResponse) if err != nil { From 574c76569ed4dd5a4d2bf83808c75f86474c291d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Thu, 24 Feb 2022 19:41:18 +0200 Subject: [PATCH 04/10] Fixed expected status for git repository create with bare flag --- cmd/lakectl/cmd/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/repo.go b/cmd/lakectl/cmd/repo.go index 69f695ff19c..dd8c3a1da9c 100644 --- a/cmd/lakectl/cmd/repo.go +++ b/cmd/lakectl/cmd/repo.go @@ -100,7 +100,7 @@ var repoCreateBareCmd = &cobra.Command{ Name: u.Repository, StorageNamespace: args[1], }) - DieOnErrorOrUnexpectedStatusCode(respCreateRepo, err, http.StatusCreated) + DieOnErrorOrUnexpectedStatusCode(respCreateRepo, err, http.StatusOK) respGetRepo, err := clt.GetRepositoryWithResponse(cmd.Context(), u.Repository) DieOnErrorOrUnexpectedStatusCode(respGetRepo, err, http.StatusOK) From f7bb6ea46024319f075297c4b004804139834eae Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Fri, 25 Feb 2022 12:02:50 +0300 Subject: [PATCH 05/10] Fixed Lakectl doctor commmand due to changes in changes on redirect response --- cmd/lakectl/cmd/doctor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 9582384caab..559d2adeffa 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -127,7 +127,7 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error { case resp.JSON401 != nil: return &CredentialsError{msgOnErrCredential, resp.JSON401.Message} // In case we get the "not found" HTML page (the status is 200 and not 404 in this case). - case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200: + case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 302: return &WrongEndpointURIError{msgOnErrWrongEndpointURI, ""} case resp.JSONDefault != nil: return &UnknownConfigError{msgOnErrUnknownConfig, resp.JSONDefault.Message} From 3160b531ad9aef6cdb7507ba0535924fa230400f Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Fri, 25 Feb 2022 12:38:32 +0300 Subject: [PATCH 06/10] Reformated import order --- cmd/lakectl/cmd/abuse.go | 1 + cmd/lakectl/cmd/action_validate.go | 1 + cmd/lakectl/cmd/annotate.go | 1 + cmd/lakectl/cmd/auth.go | 1 + cmd/lakectl/cmd/branch.go | 1 + cmd/lakectl/cmd/branch_protect.go | 4 +++- cmd/lakectl/cmd/cat_hook_output.go | 3 ++- cmd/lakectl/cmd/commit.go | 1 + cmd/lakectl/cmd/common_helpers.go | 8 ++++---- cmd/lakectl/cmd/common_helpers_test.go | 4 +++- cmd/lakectl/cmd/config.go | 1 + cmd/lakectl/cmd/config/config.go | 1 + cmd/lakectl/cmd/dbt.go | 1 + cmd/lakectl/cmd/diff.go | 1 + cmd/lakectl/cmd/doctor.go | 1 + cmd/lakectl/cmd/fs.go | 1 + cmd/lakectl/cmd/gc.go | 1 + cmd/lakectl/cmd/ingest.go | 1 + cmd/lakectl/cmd/log.go | 4 +++- cmd/lakectl/cmd/merge.go | 4 +++- cmd/lakectl/cmd/metastore.go | 1 + cmd/lakectl/cmd/refs.go | 1 + cmd/lakectl/cmd/repo.go | 1 + cmd/lakectl/cmd/root.go | 1 + cmd/lakectl/cmd/runs_describe.go | 1 + cmd/lakectl/cmd/runs_list.go | 4 +++- cmd/lakectl/cmd/show.go | 1 + cmd/lakectl/cmd/sst.go | 3 ++- cmd/lakectl/cmd/tag.go | 4 +++- 29 files changed, 46 insertions(+), 12 deletions(-) diff --git a/cmd/lakectl/cmd/abuse.go b/cmd/lakectl/cmd/abuse.go index abd53253210..17c8b6a2124 100644 --- a/cmd/lakectl/cmd/abuse.go +++ b/cmd/lakectl/cmd/abuse.go @@ -11,6 +11,7 @@ import ( "time" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" "github.com/treeverse/lakefs/pkg/testutil/stress" diff --git a/cmd/lakectl/cmd/action_validate.go b/cmd/lakectl/cmd/action_validate.go index e44d3361c45..864410adec5 100644 --- a/cmd/lakectl/cmd/action_validate.go +++ b/cmd/lakectl/cmd/action_validate.go @@ -4,6 +4,7 @@ import ( "io" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/actions" "github.com/treeverse/lakefs/pkg/cmdutils" ) diff --git a/cmd/lakectl/cmd/annotate.go b/cmd/lakectl/cmd/annotate.go index bce21fb75d8..82eda94f90e 100644 --- a/cmd/lakectl/cmd/annotate.go +++ b/cmd/lakectl/cmd/annotate.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/auth.go b/cmd/lakectl/cmd/auth.go index 99ba3d5b267..9326a220272 100644 --- a/cmd/lakectl/cmd/auth.go +++ b/cmd/lakectl/cmd/auth.go @@ -9,6 +9,7 @@ import ( "time" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/branch.go b/cmd/lakectl/cmd/branch.go index 2189be6978b..d6337c4929f 100644 --- a/cmd/lakectl/cmd/branch.go +++ b/cmd/lakectl/cmd/branch.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/uri" ) diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index ae981946f7b..baed4f5f300 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -1,9 +1,11 @@ package cmd import ( + "net/http" + "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" - "net/http" ) const ( diff --git a/cmd/lakectl/cmd/cat_hook_output.go b/cmd/lakectl/cmd/cat_hook_output.go index 9067ccdfbc7..2330ea37a1a 100644 --- a/cmd/lakectl/cmd/cat_hook_output.go +++ b/cmd/lakectl/cmd/cat_hook_output.go @@ -1,8 +1,9 @@ package cmd import ( - "github.com/spf13/cobra" "net/http" + + "github.com/spf13/cobra" ) const catHookOutputRequiredArgs = 3 diff --git a/cmd/lakectl/cmd/commit.go b/cmd/lakectl/cmd/commit.go index 7c6a0e81771..f185a559a2e 100644 --- a/cmd/lakectl/cmd/commit.go +++ b/cmd/lakectl/cmd/commit.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/uri" ) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index fa23bb87b0e..8a0107d562c 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -16,13 +16,13 @@ import ( "text/template" "time" - "github.com/treeverse/lakefs/pkg/uri" - "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" + "golang.org/x/term" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" - "golang.org/x/term" + "github.com/treeverse/lakefs/pkg/uri" ) var isTerminal = true @@ -229,7 +229,7 @@ func DieOnErrorOrUnexpectedStatusCode(response interface{}, err error, expectedS } if statusCode != expectedStatusCode { // redirected to not found page - if statusCode == 302 { + if statusCode == http.StatusFound { Die("got not found error, probably wrong endpoint url", 1) } Die("got unexpected status code: "+strconv.Itoa(statusCode)+", expected: "+strconv.Itoa(expectedStatusCode), 1) diff --git a/cmd/lakectl/cmd/common_helpers_test.go b/cmd/lakectl/cmd/common_helpers_test.go index 88fcc155741..22ae23342d2 100644 --- a/cmd/lakectl/cmd/common_helpers_test.go +++ b/cmd/lakectl/cmd/common_helpers_test.go @@ -1,6 +1,8 @@ package cmd -import "testing" +import ( + "testing" +) func TestIsValidAccessKeyID(t *testing.T) { type args struct { diff --git a/cmd/lakectl/cmd/config.go b/cmd/lakectl/cmd/config.go index 5f61ef56220..fc51a0645a9 100644 --- a/cmd/lakectl/cmd/config.go +++ b/cmd/lakectl/cmd/config.go @@ -9,6 +9,7 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" ) diff --git a/cmd/lakectl/cmd/config/config.go b/cmd/lakectl/cmd/config/config.go index 002f2314bfd..d0ad0eb8cd2 100644 --- a/cmd/lakectl/cmd/config/config.go +++ b/cmd/lakectl/cmd/config/config.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/spf13/viper" + "github.com/treeverse/lakefs/pkg/config" "github.com/treeverse/lakefs/pkg/logging" ) diff --git a/cmd/lakectl/cmd/dbt.go b/cmd/lakectl/cmd/dbt.go index 310bd84de3f..3ad8145d108 100644 --- a/cmd/lakectl/cmd/dbt.go +++ b/cmd/lakectl/cmd/dbt.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/metastore" mserrors "github.com/treeverse/lakefs/pkg/metastore/errors" ) diff --git a/cmd/lakectl/cmd/diff.go b/cmd/lakectl/cmd/diff.go index 9d36e0c5092..f537df771e9 100644 --- a/cmd/lakectl/cmd/diff.go +++ b/cmd/lakectl/cmd/diff.go @@ -8,6 +8,7 @@ import ( "github.com/jedib0t/go-pretty/v6/text" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 559d2adeffa..ca176221c5e 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/fs.go b/cmd/lakectl/cmd/fs.go index 7fc765c3c00..63b9c460f4c 100644 --- a/cmd/lakectl/cmd/fs.go +++ b/cmd/lakectl/cmd/fs.go @@ -13,6 +13,7 @@ import ( "sync" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" "github.com/treeverse/lakefs/pkg/uri" diff --git a/cmd/lakectl/cmd/gc.go b/cmd/lakectl/cmd/gc.go index 47c7f02bb35..1f6815e15df 100644 --- a/cmd/lakectl/cmd/gc.go +++ b/cmd/lakectl/cmd/gc.go @@ -7,6 +7,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/ingest.go b/cmd/lakectl/cmd/ingest.go index 9631c5ab1fd..dea411c01d4 100644 --- a/cmd/lakectl/cmd/ingest.go +++ b/cmd/lakectl/cmd/ingest.go @@ -8,6 +8,7 @@ import ( "time" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/cmd/lakectl/cmd/store" "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index f5cf8f0ba00..fd3d86da729 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -1,9 +1,11 @@ package cmd import ( + "net/http" + "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" - "net/http" ) const commitsTemplate = `{{ range $val := .Commits }} diff --git a/cmd/lakectl/cmd/merge.go b/cmd/lakectl/cmd/merge.go index 3b00af9459f..4c4d7f37c1f 100644 --- a/cmd/lakectl/cmd/merge.go +++ b/cmd/lakectl/cmd/merge.go @@ -1,9 +1,11 @@ package cmd import ( + "net/http" + "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" - "net/http" ) const ( diff --git a/cmd/lakectl/cmd/metastore.go b/cmd/lakectl/cmd/metastore.go index 657dc42e6e3..0772a45fa74 100644 --- a/cmd/lakectl/cmd/metastore.go +++ b/cmd/lakectl/cmd/metastore.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/logging" "github.com/treeverse/lakefs/pkg/metastore" diff --git a/cmd/lakectl/cmd/refs.go b/cmd/lakectl/cmd/refs.go index 4be4b7c6e17..eca7755b3d2 100644 --- a/cmd/lakectl/cmd/refs.go +++ b/cmd/lakectl/cmd/refs.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/repo.go b/cmd/lakectl/cmd/repo.go index dd8c3a1da9c..81d2679f494 100644 --- a/cmd/lakectl/cmd/repo.go +++ b/cmd/lakectl/cmd/repo.go @@ -5,6 +5,7 @@ import ( "time" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/root.go b/cmd/lakectl/cmd/root.go index 867fb960218..38428054da3 100644 --- a/cmd/lakectl/cmd/root.go +++ b/cmd/lakectl/cmd/root.go @@ -13,6 +13,7 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/logging" diff --git a/cmd/lakectl/cmd/runs_describe.go b/cmd/lakectl/cmd/runs_describe.go index be73261555d..b1ab9772bc9 100644 --- a/cmd/lakectl/cmd/runs_describe.go +++ b/cmd/lakectl/cmd/runs_describe.go @@ -6,6 +6,7 @@ import ( "github.com/jedib0t/go-pretty/v6/text" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" ) diff --git a/cmd/lakectl/cmd/runs_list.go b/cmd/lakectl/cmd/runs_list.go index ce2705e5a1d..44ea4d8c76d 100644 --- a/cmd/lakectl/cmd/runs_list.go +++ b/cmd/lakectl/cmd/runs_list.go @@ -1,9 +1,11 @@ package cmd import ( + "net/http" + "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" - "net/http" ) const actionsRunsListTemplate = `{{.ActionsRunsTable | table -}} diff --git a/cmd/lakectl/cmd/show.go b/cmd/lakectl/cmd/show.go index 4a4eeb02d30..7834c1288d5 100644 --- a/cmd/lakectl/cmd/show.go +++ b/cmd/lakectl/cmd/show.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/sst.go b/cmd/lakectl/cmd/sst.go index 30a9474dec8..46be11ee541 100644 --- a/cmd/lakectl/cmd/sst.go +++ b/cmd/lakectl/cmd/sst.go @@ -9,11 +9,12 @@ import ( pebblesst "github.com/cockroachdb/pebble/sstable" "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" + "github.com/treeverse/lakefs/pkg/catalog" "github.com/treeverse/lakefs/pkg/graveler" "github.com/treeverse/lakefs/pkg/graveler/committed" "github.com/treeverse/lakefs/pkg/graveler/sstable" - "google.golang.org/protobuf/proto" ) func readStdin() (pebblesst.ReadableFile, error) { diff --git a/cmd/lakectl/cmd/tag.go b/cmd/lakectl/cmd/tag.go index 10a8186c9cb..3604f997bf8 100644 --- a/cmd/lakectl/cmd/tag.go +++ b/cmd/lakectl/cmd/tag.go @@ -1,9 +1,11 @@ package cmd import ( + "net/http" + "github.com/spf13/cobra" + "github.com/treeverse/lakefs/pkg/api" - "net/http" ) const tagCreateRequiredArgs = 2 From 08582c2db8691dc497d117add9c7a88a682f7a1d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 27 Feb 2022 12:19:21 +0200 Subject: [PATCH 07/10] Fixed expected status for branch protected add example text --- cmd/lakectl/cmd/branch_protect.go | 8 ++++---- docs/reference/commands.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index baed4f5f300..6022fc68fc9 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -21,7 +21,7 @@ var branchProtectCmd = &cobra.Command{ var branchProtectListCmd = &cobra.Command{ Use: "list ", Short: "List all branch protection rules", - Example: "lakectl list lakefs://", + Example: "lakectl branch-protect list lakefs://", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { client := getClient() @@ -43,7 +43,7 @@ var branchProtectAddCmd = &cobra.Command{ Use: "add ", Short: "Add a branch protection rule", Long: "Add a branch protection rule for a given branch name pattern", - Example: "lakectl add lakefs:// 'stable_*'", + Example: "lakectl branch-protect add lakefs:// 'stable_*'", Args: cobra.ExactArgs(branchProtectAddCmdArgs), Run: func(cmd *cobra.Command, args []string) { client := getClient() @@ -51,7 +51,7 @@ var branchProtectAddCmd = &cobra.Command{ resp, err := client.CreateBranchProtectionRuleWithResponse(cmd.Context(), u.Repository, api.CreateBranchProtectionRuleJSONRequestBody{ Pattern: args[1], }) - DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } @@ -59,7 +59,7 @@ var branchProtectDeleteCmd = &cobra.Command{ Use: "delete ", Short: "Delete a branch protection rule", Long: "Delete a branch protection rule for a given branch name pattern", - Example: "lakectl delete lakefs:// stable_*", + Example: "lakectl branch-protect delete lakefs:// stable_*", Args: cobra.ExactArgs(branchProtectDeleteCmdArgs), Run: func(cmd *cobra.Command, args []string) { client := getClient() diff --git a/docs/reference/commands.md b/docs/reference/commands.md index d75a084ba9d..fa11852dbbf 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1339,7 +1339,7 @@ lakectl branch-protect add [flags] {:.no_toc} ``` -lakectl add lakefs:// 'stable_*' +lakectl branch-protect add lakefs:// 'stable_*' ``` #### Options @@ -1368,7 +1368,7 @@ lakectl branch-protect delete [flags] {:.no_toc} ``` -lakectl delete lakefs:// stable_* +lakectl branch-protect delete lakefs:// stable_* ``` #### Options @@ -1415,7 +1415,7 @@ lakectl branch-protect list [flags] {:.no_toc} ``` -lakectl list lakefs:// +lakectl branch-protect list lakefs:// ``` #### Options @@ -2413,7 +2413,7 @@ lakectl repo create [flags] {:.no_toc} ``` -lakectl repo create lakefs://some-repo-name s3://some-bucket-name +lakectl create lakefs://some-repo-name s3://some-bucket-name ``` #### Options From 360d462e47856bc304ef23fc84f4e3e5731089f9 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 27 Feb 2022 14:57:40 +0200 Subject: [PATCH 08/10] Reverted unrelated changes to current PR --- cmd/lakectl/cmd/abuse.go | 8 ++++---- cmd/lakectl/cmd/annotate.go | 8 ++++---- cmd/lakectl/cmd/branch_protect.go | 6 +++--- cmd/lakectl/cmd/fs.go | 6 +++--- cmd/lakectl/cmd/log.go | 8 ++++---- cmd/lakectl/cmd/metastore.go | 6 +++--- cmd/lakectl/cmd/repo.go | 8 ++++---- cmd/lakectl/cmd/runs_describe.go | 8 ++++---- cmd/lakectl/cmd/tag.go | 4 ++-- docs/reference/commands.md | 6 +++--- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cmd/lakectl/cmd/abuse.go b/cmd/lakectl/cmd/abuse.go index 17c8b6a2124..229170c10c7 100644 --- a/cmd/lakectl/cmd/abuse.go +++ b/cmd/lakectl/cmd/abuse.go @@ -174,19 +174,19 @@ var abuseCreateBranchesCmd = &cobra.Command{ currentOffset := api.PaginationAfter(branchPrefix) amount := api.PaginationAmount(paginationAmount) for { - res, err := client.ListBranchesWithResponse(cmd.Context(), u.Repository, &api.ListBranchesParams{ + resp, err := client.ListBranchesWithResponse(cmd.Context(), u.Repository, &api.ListBranchesParams{ After: ¤tOffset, Amount: &amount, }) - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) - for _, ref := range res.JSON200.Results { + for _, ref := range resp.JSON200.Results { if !strings.HasPrefix(ref.Id, branchPrefix) { return } add(ref.Id) // this branch should be deleted! } - pagination := res.JSON200.Pagination + pagination := resp.JSON200.Pagination if !pagination.HasMore { return } diff --git a/cmd/lakectl/cmd/annotate.go b/cmd/lakectl/cmd/annotate.go index 82eda94f90e..3ab75a98cb3 100644 --- a/cmd/lakectl/cmd/annotate.go +++ b/cmd/lakectl/cmd/annotate.go @@ -48,14 +48,14 @@ var annotateCmd = &cobra.Command{ Amount: api.PaginationAmountPtr(1), Objects: &[]string{obj.Path}, } - res, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams) + resp, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams) DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) data := objectCommitData{ Object: obj.Path, } - if len(res.JSON200.Results) > 0 { - data.Commit = res.JSON200.Results[0] - data.CommitMessage = splitOnNewLine(stringTrimLen(res.JSON200.Results[0].Message, annotateMessageSize)) + if len(resp.JSON200.Results) > 0 { + data.Commit = resp.JSON200.Results[0] + data.CommitMessage = splitOnNewLine(stringTrimLen((resp.JSON200.Results[0].Message), annotateMessageSize)) } Write(annotateTemplate, data) } diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index 6022fc68fc9..2489d1573e9 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -21,7 +21,7 @@ var branchProtectCmd = &cobra.Command{ var branchProtectListCmd = &cobra.Command{ Use: "list ", Short: "List all branch protection rules", - Example: "lakectl branch-protect list lakefs://", + Example: "lakectl list lakefs://", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { client := getClient() @@ -43,7 +43,7 @@ var branchProtectAddCmd = &cobra.Command{ Use: "add ", Short: "Add a branch protection rule", Long: "Add a branch protection rule for a given branch name pattern", - Example: "lakectl branch-protect add lakefs:// 'stable_*'", + Example: "lakectl add lakefs:// 'stable_*'", Args: cobra.ExactArgs(branchProtectAddCmdArgs), Run: func(cmd *cobra.Command, args []string) { client := getClient() @@ -59,7 +59,7 @@ var branchProtectDeleteCmd = &cobra.Command{ Use: "delete ", Short: "Delete a branch protection rule", Long: "Delete a branch protection rule for a given branch name pattern", - Example: "lakectl branch-protect delete lakefs:// stable_*", + Example: "lakectl delete lakefs:// stable_*", Args: cobra.ExactArgs(branchProtectDeleteCmdArgs), Run: func(cmd *cobra.Command, args []string) { client := getClient() diff --git a/cmd/lakectl/cmd/fs.go b/cmd/lakectl/cmd/fs.go index 63b9c460f4c..9fa9ebb7056 100644 --- a/cmd/lakectl/cmd/fs.go +++ b/cmd/lakectl/cmd/fs.go @@ -42,12 +42,12 @@ var fsStatCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { pathURI := MustParsePathURI("path", args[0]) client := getClient() - res, err := client.StatObjectWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, &api.StatObjectParams{ + resp, err := client.StatObjectWithResponse(cmd.Context(), pathURI.Repository, pathURI.Ref, &api.StatObjectParams{ Path: *pathURI.Path, }) - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) - stat := res.JSON200 + stat := resp.JSON200 Write(fsStatTemplate, stat) }, } diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index fd3d86da729..8d5135d478a 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -56,16 +56,16 @@ var logCmd = &cobra.Command{ logCommitsParams.Prefixes = &prefixesList } for pagination.HasMore { - res, err := client.LogCommitsWithResponse(cmd.Context(), branchURI.Repository, branchURI.Ref, logCommitsParams) - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) - pagination = res.JSON200.Pagination + resp, err := client.LogCommitsWithResponse(cmd.Context(), branchURI.Repository, branchURI.Ref, logCommitsParams) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) + pagination = resp.JSON200.Pagination logCommitsParams.After = api.PaginationAfterPtr(pagination.NextOffset) data := struct { Commits []api.Commit Pagination *Pagination ShowMetaRangeID bool }{ - Commits: res.JSON200.Results, + Commits: resp.JSON200.Results, ShowMetaRangeID: showMetaRangeID, Pagination: &Pagination{ Amount: amount, diff --git a/cmd/lakectl/cmd/metastore.go b/cmd/lakectl/cmd/metastore.go index 0772a45fa74..39671c0a209 100644 --- a/cmd/lakectl/cmd/metastore.go +++ b/cmd/lakectl/cmd/metastore.go @@ -284,12 +284,12 @@ var createSymlinkCmd = &cobra.Command{ defer fromClientDeferFunc() defer toClientDeferFunc() - res, err := apiClient.CreateSymlinkFileWithResponse(cmd.Context(), repo, branch, &api.CreateSymlinkFileParams{Location: &path}) + resp, err := apiClient.CreateSymlinkFileWithResponse(cmd.Context(), repo, branch, &api.CreateSymlinkFileParams{Location: &path}) if err != nil { DieErr(err) } - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusCreated) - location := res.JSON201.Location + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated) + location := resp.JSON201.Location err = metastore.CopyOrMergeToSymlink(cmd.Context(), fromClient, toClient, fromDB, fromTable, toDB, toTable, location, cfg.GetFixSparkPlaceholder()) if err != nil { diff --git a/cmd/lakectl/cmd/repo.go b/cmd/lakectl/cmd/repo.go index 81d2679f494..73fd55e051a 100644 --- a/cmd/lakectl/cmd/repo.go +++ b/cmd/lakectl/cmd/repo.go @@ -28,18 +28,18 @@ var repoListCmd = &cobra.Command{ after := MustString(cmd.Flags().GetString("after")) clt := getClient() - res, err := clt.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{ + resp, err := clt.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{ After: api.PaginationAfterPtr(after), Amount: api.PaginationAmountPtr(amount), }) - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) - repos := res.JSON200.Results + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) + repos := resp.JSON200.Results rows := make([][]interface{}, len(repos)) for i, repo := range repos { ts := time.Unix(repo.CreationDate, 0).String() rows[i] = []interface{}{repo.Id, ts, repo.DefaultBranch, repo.StorageNamespace} } - pagination := res.JSON200.Pagination + pagination := resp.JSON200.Pagination PrintTable(rows, []interface{}{"Repository", "Creation Date", "Default Ref Name", "Storage Namespace"}, &pagination, amount) }, } diff --git a/cmd/lakectl/cmd/runs_describe.go b/cmd/lakectl/cmd/runs_describe.go index b1ab9772bc9..83f25b8c32c 100644 --- a/cmd/lakectl/cmd/runs_describe.go +++ b/cmd/lakectl/cmd/runs_describe.go @@ -81,14 +81,14 @@ var runsDescribeCmd = &cobra.Command{ func makeHookLog(ctx context.Context, client api.ClientWithResponsesInterface, repositoryID string, runID string) func(hookRunID string) (string, error) { return func(hookRunID string) (string, error) { - res, err := client.GetRunHookOutputWithResponse(ctx, repositoryID, runID, hookRunID) + resp, err := client.GetRunHookOutputWithResponse(ctx, repositoryID, runID, hookRunID) if err != nil { return "", err } - if res.StatusCode() != http.StatusOK { - return "", helpers.ResponseAsError(res) + if resp.StatusCode() != http.StatusOK { + return "", helpers.ResponseAsError(resp) } - return string(res.Body), nil + return string(resp.Body), nil } } diff --git a/cmd/lakectl/cmd/tag.go b/cmd/lakectl/cmd/tag.go index 3604f997bf8..bc0d3859db2 100644 --- a/cmd/lakectl/cmd/tag.go +++ b/cmd/lakectl/cmd/tag.go @@ -78,8 +78,8 @@ var tagCreateCmd = &cobra.Command{ force, _ := cmd.Flags().GetBool("force") if force { // checking validity of the commitRef before deleting the old one - res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef) - DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) + resp, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) resp, err := client.DeleteTagWithResponse(ctx, tagURI.Repository, tagURI.Ref) if err != nil && (resp == nil || resp.JSON404 == nil) { diff --git a/docs/reference/commands.md b/docs/reference/commands.md index fa11852dbbf..81efc7c35e2 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1339,7 +1339,7 @@ lakectl branch-protect add [flags] {:.no_toc} ``` -lakectl branch-protect add lakefs:// 'stable_*' +lakectl add lakefs:// 'stable_*' ``` #### Options @@ -1368,7 +1368,7 @@ lakectl branch-protect delete [flags] {:.no_toc} ``` -lakectl branch-protect delete lakefs:// stable_* +lakectl delete lakefs:// stable_* ``` #### Options @@ -1415,7 +1415,7 @@ lakectl branch-protect list [flags] {:.no_toc} ``` -lakectl branch-protect list lakefs:// +lakectl list lakefs:// ``` #### Options From 3513f298165f5611e5a85c3f8c0f36c229254f20 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 27 Feb 2022 15:06:41 +0200 Subject: [PATCH 09/10] Reverted changes --- cmd/lakectl/cmd/tag.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/lakectl/cmd/tag.go b/cmd/lakectl/cmd/tag.go index bc0d3859db2..3604f997bf8 100644 --- a/cmd/lakectl/cmd/tag.go +++ b/cmd/lakectl/cmd/tag.go @@ -78,8 +78,8 @@ var tagCreateCmd = &cobra.Command{ force, _ := cmd.Flags().GetBool("force") if force { // checking validity of the commitRef before deleting the old one - resp, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef) - DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) + res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef) + DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK) resp, err := client.DeleteTagWithResponse(ctx, tagURI.Repository, tagURI.Ref) if err != nil && (resp == nil || resp.JSON404 == nil) { From 688de92a8916fe9deb84d821008bd3e11a155cb2 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 28 Feb 2022 10:56:56 +0200 Subject: [PATCH 10/10] Fixed imports order and responses naming --- cmd/lakectl/cmd/abuse.go | 1 - cmd/lakectl/cmd/action_validate.go | 1 - cmd/lakectl/cmd/annotate.go | 15 +++++++-------- cmd/lakectl/cmd/auth.go | 15 +++++++-------- cmd/lakectl/cmd/branch.go | 7 +++---- cmd/lakectl/cmd/branch_protect.go | 3 +-- cmd/lakectl/cmd/commit.go | 1 - cmd/lakectl/cmd/common_helpers.go | 7 ++----- cmd/lakectl/cmd/config.go | 1 - cmd/lakectl/cmd/config/config.go | 1 - cmd/lakectl/cmd/dbt.go | 1 - cmd/lakectl/cmd/diff.go | 1 - cmd/lakectl/cmd/doctor.go | 1 - cmd/lakectl/cmd/fs.go | 1 - cmd/lakectl/cmd/gc.go | 3 +-- cmd/lakectl/cmd/ingest.go | 1 - cmd/lakectl/cmd/log.go | 1 - cmd/lakectl/cmd/merge.go | 1 - cmd/lakectl/cmd/metastore.go | 1 - cmd/lakectl/cmd/refs.go | 1 - cmd/lakectl/cmd/repo.go | 3 +-- cmd/lakectl/cmd/root.go | 2 -- cmd/lakectl/cmd/runs_describe.go | 1 - cmd/lakectl/cmd/runs_list.go | 1 - cmd/lakectl/cmd/show.go | 1 - cmd/lakectl/cmd/sst.go | 3 +-- cmd/lakectl/cmd/tag.go | 5 ++--- pkg/api/ui_handler.go | 3 +-- 28 files changed, 26 insertions(+), 57 deletions(-) diff --git a/cmd/lakectl/cmd/abuse.go b/cmd/lakectl/cmd/abuse.go index 229170c10c7..15a292cbf1e 100644 --- a/cmd/lakectl/cmd/abuse.go +++ b/cmd/lakectl/cmd/abuse.go @@ -11,7 +11,6 @@ import ( "time" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" "github.com/treeverse/lakefs/pkg/testutil/stress" diff --git a/cmd/lakectl/cmd/action_validate.go b/cmd/lakectl/cmd/action_validate.go index 864410adec5..e44d3361c45 100644 --- a/cmd/lakectl/cmd/action_validate.go +++ b/cmd/lakectl/cmd/action_validate.go @@ -4,7 +4,6 @@ import ( "io" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/actions" "github.com/treeverse/lakefs/pkg/cmdutils" ) diff --git a/cmd/lakectl/cmd/annotate.go b/cmd/lakectl/cmd/annotate.go index 3ab75a98cb3..d021915d039 100644 --- a/cmd/lakectl/cmd/annotate.go +++ b/cmd/lakectl/cmd/annotate.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -41,25 +40,25 @@ var annotateCmd = &cobra.Command{ Prefix: &pfx, After: api.PaginationAfterPtr(from), } - resp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, params) - DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) + listObjectsResp, err := client.ListObjectsWithResponse(context, pathURI.Repository, pathURI.Ref, params) + DieOnErrorOrUnexpectedStatusCode(listObjectsResp, err, http.StatusOK) for _, obj := range resp.JSON200.Results { logCommitsParams := &api.LogCommitsParams{ Amount: api.PaginationAmountPtr(1), Objects: &[]string{obj.Path}, } - resp, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams) + logCommitsResp, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams) DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) data := objectCommitData{ Object: obj.Path, } - if len(resp.JSON200.Results) > 0 { - data.Commit = resp.JSON200.Results[0] - data.CommitMessage = splitOnNewLine(stringTrimLen((resp.JSON200.Results[0].Message), annotateMessageSize)) + if len(logCommitsResp.JSON200.Results) > 0 { + data.Commit = logCommitsResp.JSON200.Results[0] + data.CommitMessage = splitOnNewLine(stringTrimLen((logCommitsResp.JSON200.Results[0].Message), annotateMessageSize)) } Write(annotateTemplate, data) } - pagination := resp.JSON200.Pagination + pagination := listObjectsResp.JSON200.Pagination if !pagination.HasMore { break } diff --git a/cmd/lakectl/cmd/auth.go b/cmd/lakectl/cmd/auth.go index 9326a220272..d35fbcd4bd0 100644 --- a/cmd/lakectl/cmd/auth.go +++ b/cmd/lakectl/cmd/auth.go @@ -9,7 +9,6 @@ import ( "time" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -103,7 +102,7 @@ var authUsersDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeleteUserWithResponse(cmd.Context(), id) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("User deleted successfully\n") }, } @@ -201,7 +200,7 @@ var authUsersPoliciesDetach = &cobra.Command{ clt := getClient() resp, err := clt.DetachPolicyFromUserWithResponse(cmd.Context(), id, policy) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Policy detached successfully\n") }, @@ -247,7 +246,7 @@ var authUsersCredentialsDelete = &cobra.Command{ id = resp.JSON200.User.Id } resp, err := clt.DeleteCredentialsWithResponse(cmd.Context(), id, accessKeyID) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Credentials deleted successfully\n") }, @@ -342,7 +341,7 @@ var authGroupsDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeleteGroupWithResponse(cmd.Context(), id) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Group deleted successfully\n") }, } @@ -402,7 +401,7 @@ var authGroupsRemoveMember = &cobra.Command{ clt := getClient() resp, err := clt.DeleteGroupMembershipWithResponse(cmd.Context(), id, user) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("User successfully removed\n") }, } @@ -467,7 +466,7 @@ var authGroupsPoliciesDetach = &cobra.Command{ clt := getClient() resp, err := clt.DetachPolicyFromGroupWithResponse(cmd.Context(), id, policy) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Policy detached successfully\n") }, @@ -586,7 +585,7 @@ var authPoliciesDelete = &cobra.Command{ clt := getClient() resp, err := clt.DeletePolicyWithResponse(cmd.Context(), id) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Policy deleted successfully\n") }, } diff --git a/cmd/lakectl/cmd/branch.go b/cmd/lakectl/cmd/branch.go index d6337c4929f..9267f8e655d 100644 --- a/cmd/lakectl/cmd/branch.go +++ b/cmd/lakectl/cmd/branch.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/uri" ) @@ -90,7 +89,7 @@ var branchDeleteCmd = &cobra.Command{ u := MustParseRefURI("branch", args[0]) Fmt("Branch: %s\n", u.String()) resp, err := client.DeleteBranchWithResponse(cmd.Context(), u.Repository, u.Ref) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } @@ -124,7 +123,7 @@ var branchRevertCmd = &cobra.Command{ ParentNumber: parentNumber, Ref: commitRef, }) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("commit %s successfully reverted\n", commitRef) } }, @@ -180,7 +179,7 @@ var branchResetCmd = &cobra.Command{ return } resp, err := clt.ResetBranchWithResponse(cmd.Context(), u.Repository, u.Ref, api.ResetBranchJSONRequestBody(reset)) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index 2489d1573e9..20281b9afb7 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -67,7 +66,7 @@ var branchProtectDeleteCmd = &cobra.Command{ resp, err := client.DeleteBranchProtectionRuleWithResponse(cmd.Context(), u.Repository, api.DeleteBranchProtectionRuleJSONRequestBody{ Pattern: args[1], }) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } diff --git a/cmd/lakectl/cmd/commit.go b/cmd/lakectl/cmd/commit.go index f185a559a2e..7c6a0e81771 100644 --- a/cmd/lakectl/cmd/commit.go +++ b/cmd/lakectl/cmd/commit.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/uri" ) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 8a0107d562c..87c14d1b454 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -18,11 +18,10 @@ import ( "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" - "golang.org/x/term" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" "github.com/treeverse/lakefs/pkg/uri" + "golang.org/x/term" ) var isTerminal = true @@ -43,8 +42,6 @@ const ( const internalPageSize = 1000 // when retreiving all records, use this page size under the hood const defaultAmountArgumentValue = 100 // when no amount is specified, use this value for the argument -const defaultResponseOnSwaggerClient = http.StatusNoContent - const resourceListTemplate = `{{.Table | table -}} {{.Pagination | paginate }} ` @@ -230,7 +227,7 @@ func DieOnErrorOrUnexpectedStatusCode(response interface{}, err error, expectedS if statusCode != expectedStatusCode { // redirected to not found page if statusCode == http.StatusFound { - Die("got not found error, probably wrong endpoint url", 1) + Die("got not-found error, probably wrong endpoint url", 1) } Die("got unexpected status code: "+strconv.Itoa(statusCode)+", expected: "+strconv.Itoa(expectedStatusCode), 1) } diff --git a/cmd/lakectl/cmd/config.go b/cmd/lakectl/cmd/config.go index fc51a0645a9..5f61ef56220 100644 --- a/cmd/lakectl/cmd/config.go +++ b/cmd/lakectl/cmd/config.go @@ -9,7 +9,6 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" ) diff --git a/cmd/lakectl/cmd/config/config.go b/cmd/lakectl/cmd/config/config.go index d0ad0eb8cd2..002f2314bfd 100644 --- a/cmd/lakectl/cmd/config/config.go +++ b/cmd/lakectl/cmd/config/config.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/spf13/viper" - "github.com/treeverse/lakefs/pkg/config" "github.com/treeverse/lakefs/pkg/logging" ) diff --git a/cmd/lakectl/cmd/dbt.go b/cmd/lakectl/cmd/dbt.go index 3ad8145d108..310bd84de3f 100644 --- a/cmd/lakectl/cmd/dbt.go +++ b/cmd/lakectl/cmd/dbt.go @@ -15,7 +15,6 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/metastore" mserrors "github.com/treeverse/lakefs/pkg/metastore/errors" ) diff --git a/cmd/lakectl/cmd/diff.go b/cmd/lakectl/cmd/diff.go index f537df771e9..9d36e0c5092 100644 --- a/cmd/lakectl/cmd/diff.go +++ b/cmd/lakectl/cmd/diff.go @@ -8,7 +8,6 @@ import ( "github.com/jedib0t/go-pretty/v6/text" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index ca176221c5e..559d2adeffa 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -8,7 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/fs.go b/cmd/lakectl/cmd/fs.go index 9fa9ebb7056..f0c6bfdde1f 100644 --- a/cmd/lakectl/cmd/fs.go +++ b/cmd/lakectl/cmd/fs.go @@ -13,7 +13,6 @@ import ( "sync" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" "github.com/treeverse/lakefs/pkg/uri" diff --git a/cmd/lakectl/cmd/gc.go b/cmd/lakectl/cmd/gc.go index 1f6815e15df..3c8e2a9143c 100644 --- a/cmd/lakectl/cmd/gc.go +++ b/cmd/lakectl/cmd/gc.go @@ -7,7 +7,6 @@ import ( "os" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -71,7 +70,7 @@ Example configuration file: } client := getClient() resp, err := client.SetGarbageCollectionRulesWithResponse(cmd.Context(), u.Repository, body) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } diff --git a/cmd/lakectl/cmd/ingest.go b/cmd/lakectl/cmd/ingest.go index dea411c01d4..9631c5ab1fd 100644 --- a/cmd/lakectl/cmd/ingest.go +++ b/cmd/lakectl/cmd/ingest.go @@ -8,7 +8,6 @@ import ( "time" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/cmd/lakectl/cmd/store" "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index 8d5135d478a..d70f74afeb4 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/merge.go b/cmd/lakectl/cmd/merge.go index 4c4d7f37c1f..a7c4b32a184 100644 --- a/cmd/lakectl/cmd/merge.go +++ b/cmd/lakectl/cmd/merge.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/metastore.go b/cmd/lakectl/cmd/metastore.go index 39671c0a209..0fbbea77e4f 100644 --- a/cmd/lakectl/cmd/metastore.go +++ b/cmd/lakectl/cmd/metastore.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/logging" "github.com/treeverse/lakefs/pkg/metastore" diff --git a/cmd/lakectl/cmd/refs.go b/cmd/lakectl/cmd/refs.go index eca7755b3d2..4be4b7c6e17 100644 --- a/cmd/lakectl/cmd/refs.go +++ b/cmd/lakectl/cmd/refs.go @@ -6,7 +6,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/repo.go b/cmd/lakectl/cmd/repo.go index 73fd55e051a..a9c306a9ff9 100644 --- a/cmd/lakectl/cmd/repo.go +++ b/cmd/lakectl/cmd/repo.go @@ -5,7 +5,6 @@ import ( "time" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -127,7 +126,7 @@ var repoDeleteCmd = &cobra.Command{ DieFmt("Delete Repository '%s' aborted\n", u.Repository) } resp, err := clt.DeleteRepositoryWithResponse(cmd.Context(), u.Repository) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) Fmt("Repository '%s' deleted\n", u.Repository) }, } diff --git a/cmd/lakectl/cmd/root.go b/cmd/lakectl/cmd/root.go index 38428054da3..a3cb54a0b6a 100644 --- a/cmd/lakectl/cmd/root.go +++ b/cmd/lakectl/cmd/root.go @@ -13,7 +13,6 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/logging" @@ -110,7 +109,6 @@ func getClient() *api.ClientWithResponses { serverEndpoint = strings.TrimRight(serverEndpoint, "/") + api.BaseURL } httpClient := &http.Client{ - // avoid redirect automatically CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse diff --git a/cmd/lakectl/cmd/runs_describe.go b/cmd/lakectl/cmd/runs_describe.go index 83f25b8c32c..0bb2cb45523 100644 --- a/cmd/lakectl/cmd/runs_describe.go +++ b/cmd/lakectl/cmd/runs_describe.go @@ -6,7 +6,6 @@ import ( "github.com/jedib0t/go-pretty/v6/text" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" "github.com/treeverse/lakefs/pkg/api/helpers" ) diff --git a/cmd/lakectl/cmd/runs_list.go b/cmd/lakectl/cmd/runs_list.go index 44ea4d8c76d..42f2e17aaa3 100644 --- a/cmd/lakectl/cmd/runs_list.go +++ b/cmd/lakectl/cmd/runs_list.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/show.go b/cmd/lakectl/cmd/show.go index 7834c1288d5..4a4eeb02d30 100644 --- a/cmd/lakectl/cmd/show.go +++ b/cmd/lakectl/cmd/show.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) diff --git a/cmd/lakectl/cmd/sst.go b/cmd/lakectl/cmd/sst.go index 46be11ee541..30a9474dec8 100644 --- a/cmd/lakectl/cmd/sst.go +++ b/cmd/lakectl/cmd/sst.go @@ -9,12 +9,11 @@ import ( pebblesst "github.com/cockroachdb/pebble/sstable" "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/treeverse/lakefs/pkg/catalog" "github.com/treeverse/lakefs/pkg/graveler" "github.com/treeverse/lakefs/pkg/graveler/committed" "github.com/treeverse/lakefs/pkg/graveler/sstable" + "google.golang.org/protobuf/proto" ) func readStdin() (pebblesst.ReadableFile, error) { diff --git a/cmd/lakectl/cmd/tag.go b/cmd/lakectl/cmd/tag.go index 3604f997bf8..254297ae8e5 100644 --- a/cmd/lakectl/cmd/tag.go +++ b/cmd/lakectl/cmd/tag.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/spf13/cobra" - "github.com/treeverse/lakefs/pkg/api" ) @@ -83,7 +82,7 @@ var tagCreateCmd = &cobra.Command{ resp, err := client.DeleteTagWithResponse(ctx, tagURI.Repository, tagURI.Ref) if err != nil && (resp == nil || resp.JSON404 == nil) { - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) } } @@ -113,7 +112,7 @@ var tagDeleteCmd = &cobra.Command{ ctx := cmd.Context() resp, err := client.DeleteTagWithResponse(ctx, u.Repository, u.Ref) - DieOnErrorOrUnexpectedStatusCode(resp, err, defaultResponseOnSwaggerClient) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent) }, } diff --git a/pkg/api/ui_handler.go b/pkg/api/ui_handler.go index f50d0d3f8d2..37cd3c8c628 100644 --- a/pkg/api/ui_handler.go +++ b/pkg/api/ui_handler.go @@ -80,9 +80,8 @@ func NewHandlerWithDefault(root http.FileSystem, handler http.Handler, defaultPa } _, err := root.Open(path.Clean(urlPath)) if err != nil && os.IsNotExist(err) { - fmt.Println("redirecting...") http.Redirect(w, r, defaultPath, http.StatusFound) - r.URL.Path = defaultPath + return } // consistent content-type contentType := gomime.TypeByExtension(filepath.Ext(r.URL.Path))