cli: support more user friendly userfile upload semantics#51353
cli: support more user friendly userfile upload semantics#51353craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
Commit depends on #50981, I will rebase once merged. |
de81a03 to
925ff78
Compare
miretskiy
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @adityamaru, @dt, and @miretskiy)
pkg/cli/userfiletable_test.go, line 41 at r3 (raw file):
// User passes no destination so we use the basename of the source as the // filename. c.Run(fmt.Sprintf("userfile upload %s", file))
any way to check if the upload path is what you expect it to be?
pkg/cli/flags.go
Outdated
| clientCmds = append(clientCmds, nodeLocalCmds...) | ||
| clientCmds = append(clientCmds, userFileCmds...) | ||
| clientCmds = append(clientCmds, stmtDiagCmds...) | ||
| clientCmds = append(clientCmds, userFileCmds...) |
There was a problem hiding this comment.
i think you somehow doubled this line in a rebase since you also have an extra commit
925ff78 to
0b262cb
Compare
adityamaru
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt and @miretskiy)
pkg/cli/flags.go, line 544 at r3 (raw file):
Previously, dt (David Taylor) wrote…
i think you somehow doubled this line in a rebase since you also have an extra commit
Done.
pkg/cli/userfiletable_test.go, line 41 at r3 (raw file):
Previously, miretskiy (Yevgeniy Miretskiy) wrote…
any way to check if the upload path is what you expect it to be?
I'm not sure I understand, the comments at the end of this test are parsed as the expected outputs.
knz
left a comment
There was a problem hiding this comment.
@aaron-crl I'd like to put this in your radar as well. Ideally, you'd come up with some guidelines / evaluation criteria to help Aditya assert on his own whether the path handling is sane.
Reviewed 3 of 3 files at r3, 1 of 1 files at r4.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru, @dt, and @miretskiy)
pkg/cli/userfile.go, line 91 at r4 (raw file):
userFileURL := url.URL{ Scheme: defaultUserfileScheme, Host: defaultQualifiedNamePrefix + user,
see my comment about the username in the other PR.
35c3d9d to
1990865
Compare
adityamaru
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt, @knz, and @miretskiy)
pkg/cli/userfile.go, line 91 at r4 (raw file):
Previously, knz (kena) wrote…
see my comment about the username in the other PR.
addressed in the previous PR by unescaping the URI before we use it. This allows for arbitrary Unicode characters.
|
RFAL, please |
knz
left a comment
There was a problem hiding this comment.
Reviewed 8 of 8 files at r5.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru, @dt, @knz, and @miretskiy)
pkg/storage/cloudimpl/file_table_storage.go, line 118 at r5 (raw file):
if path.Clean(basename) != basename { return "", errors.Newf("basename %s changes to %s on normalization. "+
I'm OK with this test but I'd like a unit test that demonstrates the error: under which circumstances would client code encounter this?
1990865 to
def15e3
Compare
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt, @knz, and @miretskiy)
pkg/storage/cloudimpl/file_table_storage.go, line 118 at r5 (raw file):
Previously, knz (kena) wrote…
I'm OK with this test but I'd like a unit test that demonstrates the error: under which circumstances would client code encounter this?
CLI related code should not encounter this because all the FileTableStorage methods are passed an empty basename, as a result of which all operations occur on the prefix.
BACKUP uses the basename when writing data, manifest files, and encryption information. I have added a specialized test to file_table_storage_test.go to ensure we're rejecting what we think we are. external_storage_test.go has tests in testExportStore which test valid basename constructs.
64cd0bf to
0e90fe8
Compare
knz
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r6.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru, @dt, @knz, and @miretskiy)
pkg/cli/userfiletable_test.go, line 159 at r6 (raw file):
} require.NoError(t, os.RemoveAll(dir))
Can you double-check what the cleanFn returned by TempDir does? It seems to me that you do not need this RemoveAll here.
pkg/storage/cloudimpl/file_table_storage.go, line 118 at r5 (raw file):
Previously, adityamaru (Aditya Maru) wrote…
Client code should not encounter this because all the FileTableStorage methods are passed an empty basename, as a result of which all operations occur on the prefix.
BACKUP uses the basename when writing data, manifest files, and encryption information. I have added a specialized test tofile_table_storage_test.goto ensure we're rejecting what we think we are.external_storage_test.gohas tests intestExportStorewhich test valid basename constructs.
Yes that works thanks
0e90fe8 to
ea15683
Compare
adityamaru
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt, @knz, and @miretskiy)
pkg/cli/userfiletable_test.go, line 159 at r6 (raw file):
Previously, knz (kena) wrote…
Can you double-check what the
cleanFnreturned byTempDirdoes? It seems to me that you do not need this RemoveAll here.
Done.
knz
left a comment
There was a problem hiding this comment.
Thanks. You'll want your final PR approval from someone in your team.
Reviewed 1 of 1 files at r7.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @dt, @knz, and @miretskiy)
miretskiy
left a comment
There was a problem hiding this comment.
Reviewed 1 of 8 files at r5.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @adityamaru, @dt, and @knz)
pkg/cli/userfiletable_test.go, line 131 at r7 (raw file):
if err != nil { t.Fatal(err) }
require.NoError(t, err) here and throughout?
pkg/storage/cloudimpl/cloudimpltests/file_table_storage_test.go, line 64 at r7 (raw file):
require.True(t, testutils.IsError(store.WriteFile(ctx, testfile, bytes.NewReader([]byte{0})), "basename listing-test/../basepath changes to basepath on normalization. "+ "userfile does not permit such constructs."))
you don't have to specify full error message. Just substring (does not permit such).
Also, I would pull out write file call and pass in err to require.True so that if the test fails, you'll see what kind of error you got (as opposed to "expected true")
err := store.WriteFile()
require.True(t, testutils.IsError(err, "changes to basepath", err))
Previously, the user would have to specify both the source and detination args when using `userfile upload`. This change tweaks the semantics to be as follows: - Users must specify a source path. - If the user does not specify a destination URI/path, we use the default URI scheme and host, and the basename from the source arg as the path. - If the destination is a well-formed userfile URI of the form userfile://db.schema.tablename_prefix/path/to/file, then we use that as the final URI. - If destination is not a well-formed userfile URI, we use the default userfile URI schema and host, and the destination as the path. File paths are never cleaned during upload or interaction with the UserFileStorage. Thus, the filename is the exact string represented by the path of the constructed userfile URI. This is in keeping with the semantics of s3 and gcsutil. To prevent user surprises we still reject constructs where the URI post normalization != URI pre normalization. egs: test/./test.csv or test/../../test.csv Release note (cli change): Improves the user semantics for `userfile upload` by supporting different patterns of specifying the source and destination CLI args. The source arg is required, while the destination arg is now optional.
ea15683 to
aeab5d3
Compare
|
TFTRs! bors r+ |
Build succeeded |
Previously, the user would have to specify both the source and
detination args when using
userfile upload. This change tweaks thesemantics to be as follows:
Users must specify a source path.
If the user does not specify a destination URI/path, we use the
default URI scheme and host, and the basename from the source arg as
the path.
If the destination is a well-formed userfile URI of the form
userfile://db.schema.tablename_prefix/path/to/file, then we use that
as the final URI.
If destination is not a well-formed userfile URI, we use the default
userfile URI schema and host, and the destination as the path.
File paths are never cleaned during upload or interaction with the
UserFileStorage. Thus, the filename is the exact string represented by
the path of the constructed userfile URI. This is in keeping with the
semantics of s3 and gcsutil. To prevent user surprises we still reject
constructs where the URI post normalization != URI pre normalization.
egs: test/./test.csv or test/../../test.csv
Informs: #51222
Release note (cli change): Improves the user semantics for
userfile uploadby supporting different patterns of specifying the source anddestination CLI args. The source arg is required, while the destination
arg is now optional.