From c53f14e2f56492d277aa8a2966c20b5455c38042 Mon Sep 17 00:00:00 2001 From: Eno Compton Date: Wed, 7 Dec 2022 08:59:08 -0700 Subject: [PATCH] fix: restore openbsd and freebsd support (#191) This is a port of https://github.com/GoogleCloudPlatform/cloud-sql-proxy/pull/1442 --- .github/workflows/tests.yaml | 12 ++++++ internal/proxy/fuse.go | 4 +- .../{proxy_windows.go => fuse_freebsd.go} | 14 +++---- internal/proxy/fuse_openbsd.go | 38 +++++++++++++++++++ internal/proxy/fuse_windows.go | 25 +++++++++++- internal/proxy/proxy_other.go | 11 +----- internal/proxy/unix.go | 27 +++++++++++++ 7 files changed, 110 insertions(+), 21 deletions(-) rename internal/proxy/{proxy_windows.go => fuse_freebsd.go} (72%) create mode 100644 internal/proxy/fuse_openbsd.go create mode 100644 internal/proxy/unix.go diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ec7fd0ef41..6d9e5847e3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -24,6 +24,18 @@ on: - cron: '0 2 * * *' jobs: + compilation: + if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" + name: FreeBSD and OpenBSD compilation check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: 'actions/checkout@v3' + + - name: Verify FreeBSD and OpenBSD Builds + run: | + CGO_ENABLED=0 GOOS=freebsd go build + CGO_ENABLED=0 GOOS=openbsd go build integration: # run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label) if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" diff --git a/internal/proxy/fuse.go b/internal/proxy/fuse.go index a3ef47ab1e..21e8de6644 100644 --- a/internal/proxy/fuse.go +++ b/internal/proxy/fuse.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !windows -// +build !windows +//go:build !windows && !openbsd && !freebsd +// +build !windows,!openbsd,!freebsd package proxy diff --git a/internal/proxy/proxy_windows.go b/internal/proxy/fuse_freebsd.go similarity index 72% rename from internal/proxy/proxy_windows.go rename to internal/proxy/fuse_freebsd.go index 2f4fe9924f..c675a8e7b9 100644 --- a/internal/proxy/proxy_windows.go +++ b/internal/proxy/fuse_freebsd.go @@ -17,21 +17,17 @@ package proxy import ( "context" "errors" - "path/filepath" - "strings" ) -var errFUSENotSupported = errors.New("FUSE is not supported on Windows") +var errFUSENotSupported = errors.New("FUSE is not supported on FreeBSD") -// UnixAddress returns the Unix socket for a given instance in the provided -// directory, by replacing all colons in the instance's name with periods. -func UnixAddress(dir, inst string) string { - inst2 := strings.ReplaceAll(inst, ":", ".") - return filepath.Join(dir, inst2) +// SupportsFUSE is false on FreeBSD. +func SupportsFUSE() error { + return errFUSENotSupported } type fuseMount struct { - // fuseDir is always an empty string on Windows. + // fuseDir is always an empty string on FreeBSD. fuseDir string } diff --git a/internal/proxy/fuse_openbsd.go b/internal/proxy/fuse_openbsd.go new file mode 100644 index 0000000000..cebf80c92d --- /dev/null +++ b/internal/proxy/fuse_openbsd.go @@ -0,0 +1,38 @@ +// 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 proxy + +import ( + "context" + "errors" +) + +var errFUSENotSupported = errors.New("FUSE is not supported on OpenBSD") + +// SupportsFUSE is false on OpenBSD. +func SupportsFUSE() error { + return errFUSENotSupported +} + +type fuseMount struct { + // fuseDir is always an empty string on OpenBSD. + fuseDir string +} + +func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported } +func (c *Client) fuseMounts() []*socketMount { return nil } +func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported } +func (c *Client) unmountFUSE() error { return nil } +func (c *Client) waitForFUSEMounts() {} diff --git a/internal/proxy/fuse_windows.go b/internal/proxy/fuse_windows.go index 6e5289cf4a..dd1e3b2655 100644 --- a/internal/proxy/fuse_windows.go +++ b/internal/proxy/fuse_windows.go @@ -15,10 +15,33 @@ package proxy import ( + "context" "errors" + "path/filepath" + "strings" ) +var errFUSENotSupported = errors.New("FUSE is not supported on Windows") + // SupportsFUSE is false on Windows. func SupportsFUSE() error { - return errors.New("fuse is not supported on Windows") + return errFUSENotSupported +} + +// UnixAddress returns the Unix socket for a given instance in the provided +// directory, by replacing all colons in the instance's name with periods. +func UnixAddress(dir, inst string) string { + inst2 := strings.ReplaceAll(inst, ":", ".") + return filepath.Join(dir, inst2) } + +type fuseMount struct { + // fuseDir is always an empty string on Windows. + fuseDir string +} + +func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported } +func (c *Client) fuseMounts() []*socketMount { return nil } +func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported } +func (c *Client) unmountFUSE() error { return nil } +func (c *Client) waitForFUSEMounts() {} diff --git a/internal/proxy/proxy_other.go b/internal/proxy/proxy_other.go index 818652eabc..3f64ec60b4 100644 --- a/internal/proxy/proxy_other.go +++ b/internal/proxy/proxy_other.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !windows -// +build !windows +//go:build !windows && !openbsd && !freebsd +// +build !windows,!openbsd,!freebsd package proxy @@ -29,13 +29,6 @@ import ( "github.com/hanwen/go-fuse/v2/fuse" ) -// UnixAddress is defined as a function to distinguish between Linux-based -// implementations where the dir and inst and simply joins, and Windows-based -// implementations where the inst must be further altered. -func UnixAddress(dir, inst string) string { - return filepath.Join(dir, inst) -} - type socketSymlink struct { socket *socketMount symlink *symlink diff --git a/internal/proxy/unix.go b/internal/proxy/unix.go new file mode 100644 index 0000000000..523c494511 --- /dev/null +++ b/internal/proxy/unix.go @@ -0,0 +1,27 @@ +// 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. + +//go:build !windows +// +build !windows + +package proxy + +import "path/filepath" + +// UnixAddress is defined as a function to distinguish between Unix-based +// implementations where the dir and inst are simply joined, and Windows-based +// implementations where the inst must be further altered. +func UnixAddress(dir, inst string) string { + return filepath.Join(dir, inst) +}