refactor platform -> forge

This commit is contained in:
Massaki Archambault 2024-08-04 21:45:51 -04:00
parent 0e5fed0bbd
commit 1a01c9ecea
15 changed files with 30 additions and 30 deletions

View File

@ -6,9 +6,9 @@ fs:
# See mount.fuse(8) for the full list of options. # See mount.fuse(8) for the full list of options.
#mountoptions: nodev,nosuid #mountoptions: nodev,nosuid
# The git platform to use as the backend. # The git forge to use as the backend.
# Must be one of "gitlab", or "github" # Must be one of "gitlab" or "github"
platform: gitlab forge: gitlab
gitlab: gitlab:
# The gitlab url. # The gitlab url.

View File

@ -1,7 +1,7 @@
fs: fs:
mountpoint: /tmp/gitlabfs/test/mnt/gitlab mountpoint: /tmp/gitlabfs/test/mnt/gitlab
mountoptions: nodev mountoptions: nodev
platform: gitlab forge: gitlab
gitlab: gitlab:
url: https://example.com url: https://example.com

View File

@ -9,8 +9,8 @@ import (
) )
const ( const (
PlatformGitlab = "gitlab" ForgeGitlab = "gitlab"
PlatformGithub = "github" ForgeGithub = "github"
PullMethodHTTP = "http" PullMethodHTTP = "http"
PullMethodSSH = "ssh" PullMethodSSH = "ssh"
@ -30,7 +30,7 @@ type (
FSConfig struct { FSConfig struct {
Mountpoint string `yaml:"mountpoint,omitempty"` Mountpoint string `yaml:"mountpoint,omitempty"`
MountOptions string `yaml:"mountoptions,omitempty"` MountOptions string `yaml:"mountoptions,omitempty"`
Platform string `yaml:"platform,omitempty"` Forge string `yaml:"forge,omitempty"`
} }
GitlabClientConfig struct { GitlabClientConfig struct {
URL string `yaml:"url,omitempty"` URL string `yaml:"url,omitempty"`
@ -76,7 +76,7 @@ func LoadConfig(configPath string) (*Config, error) {
FS: FSConfig{ FS: FSConfig{
Mountpoint: "", Mountpoint: "",
MountOptions: "nodev,nosuid", MountOptions: "nodev,nosuid",
Platform: "", Forge: "",
}, },
Gitlab: GitlabClientConfig{ Gitlab: GitlabClientConfig{
URL: "https://gitlab.com", URL: "https://gitlab.com",
@ -119,9 +119,9 @@ func LoadConfig(configPath string) (*Config, error) {
} }
} }
// validate platform is set // validate forge is set
if config.FS.Platform != PlatformGithub && config.FS.Platform != PlatformGitlab { if config.FS.Forge != ForgeGithub && config.FS.Forge != ForgeGitlab {
return nil, fmt.Errorf("fs.platform must be either \"%v\", or \"%v\"", PlatformGitlab, PlatformGithub) return nil, fmt.Errorf("fs.forge must be either \"%v\", or \"%v\"", ForgeGitlab, ForgeGithub)
} }
return config, nil return config, nil

View File

@ -18,7 +18,7 @@ func TestLoadConfig(t *testing.T) {
FS: config.FSConfig{ FS: config.FSConfig{
Mountpoint: "/tmp/gitlabfs/test/mnt/gitlab", Mountpoint: "/tmp/gitlabfs/test/mnt/gitlab",
MountOptions: "nodev", MountOptions: "nodev",
Platform: "gitlab", Forge: "gitlab",
}, },
Gitlab: config.GitlabClientConfig{ Gitlab: config.GitlabClientConfig{
URL: "https://example.com", URL: "https://example.com",
@ -70,7 +70,7 @@ func TestMakeGitConfig(t *testing.T) {
"ValidConfig": { "ValidConfig": {
input: &config.Config{ input: &config.Config{
FS: config.FSConfig{ FS: config.FSConfig{
Platform: "gitlab", Forge: "gitlab",
}, },
Git: config.GitClientConfig{ Git: config.GitClientConfig{
CloneLocation: "/tmp", CloneLocation: "/tmp",
@ -95,7 +95,7 @@ func TestMakeGitConfig(t *testing.T) {
"InvalidOnClone": { "InvalidOnClone": {
input: &config.Config{ input: &config.Config{
FS: config.FSConfig{ FS: config.FSConfig{
Platform: "gitlab", Forge: "gitlab",
}, },
Git: config.GitClientConfig{ Git: config.GitClientConfig{
CloneLocation: "/tmp", CloneLocation: "/tmp",
@ -132,7 +132,7 @@ func TestMakeGitlabConfig(t *testing.T) {
"ValidConfig": { "ValidConfig": {
input: &config.Config{ input: &config.Config{
FS: config.FSConfig{ FS: config.FSConfig{
Platform: "gitlab", Forge: "gitlab",
}, },
Gitlab: config.GitlabClientConfig{ Gitlab: config.GitlabClientConfig{
URL: "https://gitlab.com", URL: "https://gitlab.com",
@ -157,7 +157,7 @@ func TestMakeGitlabConfig(t *testing.T) {
"InvalidPullMethod": { "InvalidPullMethod": {
input: &config.Config{ input: &config.Config{
FS: config.FSConfig{ FS: config.FSConfig{
Platform: "gitlab", Forge: "gitlab",
}, },
Gitlab: config.GitlabClientConfig{ Gitlab: config.GitlabClientConfig{
URL: "https://gitlab.com", URL: "https://gitlab.com",

View File

@ -39,7 +39,7 @@ func newGroupNodeFromSource(source GroupSource, param *FSParam) (*groupNode, err
} }
func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) { func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
groups, repositories, err := n.param.GitPlatform.FetchGroupContent(n.source.GetGroupID()) groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
if err != nil { if err != nil {
n.param.logger.Error(err.Error()) n.param.logger.Error(err.Error())
} }
@ -70,7 +70,7 @@ func (n *groupNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
} }
func (n *groupNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) { func (n *groupNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
groups, repositories, err := n.param.GitPlatform.FetchGroupContent(n.source.GetGroupID()) groups, repositories, err := n.param.GitForge.FetchGroupContent(n.source.GetGroupID())
if err != nil { if err != nil {
n.param.logger.Error(err.Error()) n.param.logger.Error(err.Error())
} else { } else {

View File

@ -26,14 +26,14 @@ type GitClient interface {
FetchLocalRepositoryPath(source RepositorySource) (string, error) FetchLocalRepositoryPath(source RepositorySource) (string, error)
} }
type GitPlatform interface { type GitForge interface {
FetchRootGroupContent() (map[string]GroupSource, error) FetchRootGroupContent() (map[string]GroupSource, error)
FetchGroupContent(gid uint64) (map[string]GroupSource, map[string]RepositorySource, error) FetchGroupContent(gid uint64) (map[string]GroupSource, map[string]RepositorySource, error)
} }
type FSParam struct { type FSParam struct {
GitClient GitClient GitClient GitClient
GitPlatform GitPlatform GitForge GitForge
logger *slog.Logger logger *slog.Logger
staticInoChan chan uint64 staticInoChan chan uint64
@ -77,7 +77,7 @@ func Start(logger *slog.Logger, mountpoint string, mountoptions []string, param
} }
func (n *rootNode) OnAdd(ctx context.Context) { func (n *rootNode) OnAdd(ctx context.Context) {
rootGroups, err := n.param.GitPlatform.FetchRootGroupContent() rootGroups, err := n.param.GitForge.FetchRootGroupContent()
if err != nil { if err != nil {
panic(err) panic(err)
} }

16
main.go
View File

@ -8,10 +8,10 @@ import (
"strings" "strings"
"github.com/badjware/gitlabfs/config" "github.com/badjware/gitlabfs/config"
"github.com/badjware/gitlabfs/forges/github"
"github.com/badjware/gitlabfs/forges/gitlab"
"github.com/badjware/gitlabfs/fstree" "github.com/badjware/gitlabfs/fstree"
"github.com/badjware/gitlabfs/git" "github.com/badjware/gitlabfs/git"
"github.com/badjware/gitlabfs/platforms/github"
"github.com/badjware/gitlabfs/platforms/gitlab"
) )
func main() { func main() {
@ -65,23 +65,23 @@ func main() {
} }
gitClient, _ := git.NewClient(logger, *gitClientParam) gitClient, _ := git.NewClient(logger, *gitClientParam)
var gitPlatformClient fstree.GitPlatform var gitForgeClient fstree.GitForge
if loadedConfig.FS.Platform == config.PlatformGitlab { if loadedConfig.FS.Forge == config.ForgeGitlab {
// Create the gitlab client // Create the gitlab client
GitlabClientConfig, err := config.MakeGitlabConfig(loadedConfig) GitlabClientConfig, err := config.MakeGitlabConfig(loadedConfig)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
gitPlatformClient, _ = gitlab.NewClient(logger, *GitlabClientConfig) gitForgeClient, _ = gitlab.NewClient(logger, *GitlabClientConfig)
} else if loadedConfig.FS.Platform == config.PlatformGithub { } else if loadedConfig.FS.Forge == config.ForgeGithub {
// Create the github client // Create the github client
GithubClientConfig, err := config.MakeGithubConfig(loadedConfig) GithubClientConfig, err := config.MakeGithubConfig(loadedConfig)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
gitPlatformClient, _ = github.NewClient(logger, *GithubClientConfig) gitForgeClient, _ = github.NewClient(logger, *GithubClientConfig)
} }
// Start the filesystem // Start the filesystem
@ -89,7 +89,7 @@ func main() {
logger, logger,
mountpoint, mountpoint,
parsedMountoptions, parsedMountoptions,
&fstree.FSParam{GitClient: gitClient, GitPlatform: gitPlatformClient}, &fstree.FSParam{GitClient: gitClient, GitForge: gitForgeClient},
*debug, *debug,
) )
if err != nil { if err != nil {