-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for FUSE #135
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b90964
feat: add support for FUSE
enocom 6a95bd9
Merge branch 'main' into fuse
enocom 05ecd29
go mod tidy
enocom 1dfa96f
Enable allow other for fuse
enocom 2963ab5
configure fuse in unit tests
enocom a871ff0
try without sudo
enocom e0a85ad
Skip fuse in short and configure integration tests
enocom 6423cc4
Assume fuse is installed in container
enocom 4f2f9bb
rely on container image for fuse
enocom f6c9362
Add unit tests for toFullURI
enocom e15ae62
fix: don't build FUSE paths for Windows
enocom 8757e70
woops
enocom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestNewCommandArgumentsOnLinux(t *testing.T) { | ||
defaultTmp := filepath.Join(os.TempDir(), "csql-tmp") | ||
tcs := []struct { | ||
desc string | ||
args []string | ||
wantDir string | ||
wantTempDir string | ||
}{ | ||
{ | ||
desc: "using the fuse flag", | ||
args: []string{"--fuse", "/cloudsql"}, | ||
wantDir: "/cloudsql", | ||
wantTempDir: defaultTmp, | ||
}, | ||
{ | ||
desc: "using the fuse temporary directory flag", | ||
args: []string{"--fuse", "/cloudsql", "--fuse-tmp-dir", "/mycooldir"}, | ||
wantDir: "/cloudsql", | ||
wantTempDir: "/mycooldir", | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
c := NewCommand() | ||
// Keep the test output quiet | ||
c.SilenceUsage = true | ||
c.SilenceErrors = true | ||
// Disable execute behavior | ||
c.RunE = func(*cobra.Command, []string) error { | ||
return nil | ||
} | ||
c.SetArgs(tc.args) | ||
|
||
err := c.Execute() | ||
if err != nil { | ||
t.Fatalf("want error = nil, got = %v", err) | ||
} | ||
|
||
if got, want := c.conf.FUSEDir, tc.wantDir; got != want { | ||
t.Fatalf("FUSEDir: want = %v, got = %v", want, got) | ||
} | ||
|
||
if got, want := c.conf.FUSETempDir, tc.wantTempDir; got != want { | ||
t.Fatalf("FUSEDir: want = %v, got = %v", want, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestWindowsDoesNotSupportFUSE(t *testing.T) { | ||
c := NewCommand() | ||
// Keep the test output quiet | ||
c.SilenceUsage = true | ||
c.SilenceErrors = true | ||
// Disable execute behavior | ||
c.RunE = func(*cobra.Command, []string) error { return nil } | ||
c.SetArgs([]string{"--fuse"}) | ||
|
||
err := c.Execute() | ||
if err == nil { | ||
t.Fatal("want error != nil, got = nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package proxy | ||
|
||
import ( | ||
"context" | ||
"syscall" | ||
|
||
"github.com/hanwen/go-fuse/v2/fs" | ||
"github.com/hanwen/go-fuse/v2/fuse" | ||
"github.com/hanwen/go-fuse/v2/fuse/nodefs" | ||
) | ||
|
||
// symlink implements a symbolic link, returning the underlying path when | ||
// Readlink is called. | ||
type symlink struct { | ||
fs.Inode | ||
path string | ||
} | ||
|
||
// Readlink implements fs.NodeReadlinker and returns the symlink's path. | ||
func (s *symlink) Readlink(ctx context.Context) ([]byte, syscall.Errno) { | ||
return []byte(s.path), fs.OK | ||
} | ||
|
||
// readme represents a static read-only text file. | ||
type readme struct { | ||
fs.Inode | ||
} | ||
|
||
const readmeText = ` | ||
When applications attempt to open files in this directory, a remote connection | ||
to the AlloyDB instance of the same name will be established. | ||
|
||
For example, when you run one of the following commands, the proxy will initiate | ||
a connection to the corresponding Cloud SQL instance, given you have the correct | ||
IAM permissions. | ||
|
||
psql "host=/somedir/project.region.cluster.instance dbname=mydb user=myuser" | ||
|
||
The proxy will create a directory with the instance short name, and create a | ||
socket inside that directory with the special Postgres name: .s.PGSQL.5432. | ||
|
||
Listing the contents of this directory will show all instances with active | ||
connections. | ||
` | ||
|
||
// Getattr implements fs.NodeGetattrer and indicates that this file is a regular | ||
// file. | ||
func (*readme) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno { | ||
*out = fuse.AttrOut{Attr: fuse.Attr{ | ||
Mode: 0444 | syscall.S_IFREG, | ||
Size: uint64(len(readmeText)), | ||
}} | ||
return fs.OK | ||
} | ||
|
||
// Read implements fs.NodeReader and supports incremental reads. | ||
func (*readme) Read(ctx context.Context, f fs.FileHandle, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { | ||
end := int(off) + len(dest) | ||
if end > len(readmeText) { | ||
end = len(readmeText) | ||
} | ||
return fuse.ReadResultData([]byte(readmeText[off:end])), fs.OK | ||
} | ||
|
||
// Open implements fs.NodeOpener and supports opening the README as a read-only | ||
// file. | ||
func (*readme) Open(ctx context.Context, mode uint32) (fs.FileHandle, uint32, syscall.Errno) { | ||
df := nodefs.NewDataFile([]byte(readmeText)) | ||
rf := nodefs.NewReadOnlyFile(df) | ||
return rf, 0, fs.OK | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the README for AlloyDB.