diff --git a/client/clientcmd/add.go b/client/clientcmd/add.go index f9b25af..9374a3e 100644 --- a/client/clientcmd/add.go +++ b/client/clientcmd/add.go @@ -6,10 +6,11 @@ import ( "path/filepath" clientconfig "github.com/deranjer/gvc/client/clientconfig" + "github.com/deranjer/gvc/common" ) //AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all -func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) error { +func AddFiles(input string, inputType string, ignore common.FileTypes) error { err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa if err != nil { return err @@ -25,7 +26,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err if err != nil { return fmt.Errorf("unable to add file %s", err) } - err = checkFileTypes(input, "file", ignore) + err = common.CheckFileTypes(input, "file", ignore) if err != nil { return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input) } @@ -49,9 +50,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err return fmt.Errorf("failure accessing path %s", err) } if info.IsDir() { - err = checkFileTypes(currentFile, "folder", ignore) + err = common.CheckFileTypes(currentFile, "folder", ignore) } else { - err = checkFileTypes(currentFile, "file", ignore) + err = common.CheckFileTypes(currentFile, "file", ignore) } if err != nil { fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile) @@ -72,7 +73,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err } else { wildcard = input } - err := checkFileTypes(wildcard, "wildcard", ignore) + err := common.CheckFileTypes(wildcard, "wildcard", ignore) if err != nil { return err } @@ -82,9 +83,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err return fmt.Errorf("failure accessing path %s", err) } if info.IsDir() { - err = checkFileTypes(currentFile, "folder", ignore) + err = common.CheckFileTypes(currentFile, "folder", ignore) } else { - err = checkFileTypes(currentFile, "file", ignore) + err = common.CheckFileTypes(currentFile, "file", ignore) } if err != nil { fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile) @@ -108,9 +109,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err return fmt.Errorf("failure accessing path %s", err) } if info.IsDir() { - err = checkFileTypes(currentFile, "folder", ignore) + err = common.CheckFileTypes(currentFile, "folder", ignore) } else { - err = checkFileTypes(currentFile, "file", ignore) + err = common.CheckFileTypes(currentFile, "file", ignore) } if err != nil { fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile) diff --git a/client/clientcmd/commonlib.go b/client/clientcmd/commonlib.go index 2d28c97..3489b44 100644 --- a/client/clientcmd/commonlib.go +++ b/client/clientcmd/commonlib.go @@ -31,36 +31,6 @@ func validateFileType(path string, inputType string) error { return nil } -func checkFileTypes(input string, inputType string, ignores clientconfig.FileTypes) error { - switch inputType { - case "file": - fileExt := filepath.Ext(input) // TODO more sanity checking on ext - for _, ignoredExt := range ignores.Exts { - if fileExt == ignoredExt { - return fmt.Errorf("file ext is on ignored list, cannot add file with file ext %s", fileExt) - } - } - for _, ignoredFile := range ignores.Files { - if input == ignoredFile { - return fmt.Errorf("file name is on ignored list, cannot add file with name %s", input) - } - } - case "folder": - for _, ignoredFolder := range ignores.Folders { - if input == ignoredFolder { - return fmt.Errorf("folder name is on the ignored list, cannot add folder with name %s", input) - } - } - case "wildcard": - for _, ignoredExt := range ignores.Exts { - if input == ignoredExt { - return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input) - } - } - } - return nil -} - // FindServer finds the supplied server connection settings, creates a connection string and returns it func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) (connectionString string, err error) { if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch diff --git a/client/clientcmd/ignore.go b/client/clientcmd/ignore.go index f5d4dc3..ed39745 100644 --- a/client/clientcmd/ignore.go +++ b/client/clientcmd/ignore.go @@ -4,18 +4,19 @@ import ( "fmt" clientconfig "github.com/deranjer/gvc/client/clientconfig" + "github.com/deranjer/gvc/common" ) //IgnoreFiles ignores file(s)/folder based on name/wildcard, etc func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error { - err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa + err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa //TODO: Not needed I don't think we need user to be able to add ignores before files are there if err != nil { return err } ignore := conf.Ignores switch inputType { // TODO: add default case for generic error handling case "file": - err := checkFileTypes(input, "file", ignore) + err := common.CheckFileTypes(input, "file", ignore) if err != nil { return fmt.Errorf("%s already ignored: %s", input, err) } @@ -23,7 +24,7 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e conf.Ignores.Files = append(conf.Ignores.Files, input) return nil case "folder": - err := checkFileTypes(input, "folder", ignore) + err := common.CheckFileTypes(input, "folder", ignore) if err != nil { return fmt.Errorf("%s is already ignored: %s", input, err) } @@ -37,7 +38,7 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e } else { wildcard = input } - err := checkFileTypes(wildcard, "wildcard", ignore) + err := common.CheckFileTypes(wildcard, "wildcard", ignore) if err != nil { return fmt.Errorf("%s is already ignored: %s", input, err) } @@ -50,14 +51,14 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e // RemoveIgnoreFiles removes files/folders/wildcards from the ignore list func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error { - err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa + err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa //TODO: Not needed I don't think we need user to be able to add ignores before files are there if err != nil { return err } ignore := conf.Ignores switch inputType { // TODO: add default case for generic error handling case "file": - err := checkFileTypes(input, "file", ignore) + err := common.CheckFileTypes(input, "file", ignore) if err != nil { fmt.Println("Removing file from ignores: ", input) for i, fileIgnore := range ignore.Files { @@ -72,7 +73,7 @@ func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvccon fmt.Println("File not found in ingores, unable to remove: ", input) return nil case "folder": - err := checkFileTypes(input, "folder", ignore) + err := common.CheckFileTypes(input, "folder", ignore) if err != nil { for i, folderIgnore := range ignore.Folders { if input == folderIgnore { @@ -92,7 +93,7 @@ func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvccon } else { wildcard = input } - err := checkFileTypes(wildcard, "wildcard", ignore) + err := common.CheckFileTypes(wildcard, "wildcard", ignore) if err != nil { for i, wildcardIgnore := range ignore.Exts { if input == wildcardIgnore { diff --git a/client/clientcmd/lock.go b/client/clientcmd/lock.go index e3ac494..6d46a2c 100644 --- a/client/clientcmd/lock.go +++ b/client/clientcmd/lock.go @@ -4,6 +4,7 @@ import ( "fmt" clientconfig "github.com/deranjer/gvc/client/clientconfig" + "github.com/deranjer/gvc/common" ) //LockFiles locks file(s)/folder based on name/wildcard, etc @@ -15,7 +16,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err locked := conf.Locked switch inputType { // TODO: add default case for generic error handling case "file": - err := checkFileTypes(input, "file", locked) + err := common.CheckFileTypes(input, "file", locked) if err != nil { return fmt.Errorf("%s already locked: %s", input, err) } @@ -23,7 +24,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err conf.Locked.Files = append(conf.Locked.Files, input) return nil case "folder": - err := checkFileTypes(input, "folder", locked) + err := common.CheckFileTypes(input, "folder", locked) if err != nil { return fmt.Errorf("%s is already locked: %s", input, err) } @@ -37,7 +38,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err } else { wildcard = input } - err := checkFileTypes(wildcard, "wildcard", locked) + err := common.CheckFileTypes(wildcard, "wildcard", locked) if err != nil { return fmt.Errorf("%s is already locked: %s", input, err) } @@ -57,7 +58,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi locked := conf.Locked switch inputType { // TODO: add default case for generic error handling case "file": - err := checkFileTypes(input, "file", locked) + err := common.CheckFileTypes(input, "file", locked) if err != nil { fmt.Println("Removing file from locked: ", input) for i, fileLock := range locked.Files { @@ -72,7 +73,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi fmt.Println("File not found in ingores, unable to remove: ", input) return nil case "folder": - err := checkFileTypes(input, "folder", locked) + err := common.CheckFileTypes(input, "folder", locked) if err != nil { for i, folderLock := range locked.Folders { if input == folderLock { @@ -92,7 +93,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi } else { wildcard = input } - err := checkFileTypes(wildcard, "wildcard", locked) + err := common.CheckFileTypes(wildcard, "wildcard", locked) if err != nil { for i, wildcardLock := range locked.Exts { if input == wildcardLock { diff --git a/client/clientconfig/structures.go b/client/clientconfig/structures.go index 341f12d..4f692b6 100644 --- a/client/clientconfig/structures.go +++ b/client/clientconfig/structures.go @@ -1,17 +1,19 @@ package config +import "github.com/deranjer/gvc/common" + //Gvcconfig will be the struct that holds the entire client settings type Gvcconfig struct { - Version string `toml:"version"` - RootPath string `toml:"rootpath"` - RepoName string `toml:"reponame"` - Remotes []Remote `toml:"remote"` //The remote servers for the repo - CurrentBranch string `toml:"currentbranch"` - LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches - RemoteBranches []string `toml:"remotebranches"` // RemoteBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches - Locked FileTypes `toml:"locked"` - Ignores FileTypes `toml:"ignore"` //These files will be ignored for all add functions - NoCompress FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings + Version string `toml:"version"` + RootPath string `toml:"rootpath"` + RepoName string `toml:"reponame"` + Remotes []Remote `toml:"remote"` //The remote servers for the repo + CurrentBranch string `toml:"currentbranch"` + LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches + RemoteBranches []string `toml:"remotebranches"` // RemoteBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches + Locked common.FileTypes `toml:"locked"` + Ignores common.FileTypes `toml:"ignore"` //These files will be ignored for all add functions + NoCompress common.FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings } //Remote will be a slice of remote server information @@ -21,10 +23,3 @@ type Remote struct { Port int `toml:"port"` Default bool `toml:"default"` //Is this repo the default repo? } - -//FileTypes is for ignoring files to add or ignoring compress, or for locked files, all use the same type of struct (files, folders and exts) -type FileTypes struct { - Files []string `toml:"files"` - Exts []string `toml:"exts"` - Folders []string `toml:"folders"` -} diff --git a/common/commonlib.go b/common/commonlib.go new file mode 100644 index 0000000..057b84a --- /dev/null +++ b/common/commonlib.go @@ -0,0 +1,37 @@ +package common + +import ( + "fmt" + "path/filepath" +) + +// CheckFileTypes allows the server and client to do some basic validation on adding/removing file types to the toml file +func CheckFileTypes(input string, inputType string, ignores FileTypes) error { + switch inputType { + case "file": + fileExt := filepath.Ext(input) // TODO more sanity checking on ext + for _, ignoredExt := range ignores.Exts { + if fileExt == ignoredExt { + return fmt.Errorf("file ext is on ignored list, cannot add file with file ext %s", fileExt) + } + } + for _, ignoredFile := range ignores.Files { + if input == ignoredFile { + return fmt.Errorf("file name is on ignored list, cannot add file with name %s", input) + } + } + case "folder": + for _, ignoredFolder := range ignores.Folders { + if input == ignoredFolder { + return fmt.Errorf("folder name is on the ignored list, cannot add folder with name %s", input) + } + } + case "wildcard": + for _, ignoredExt := range ignores.Exts { + if input == ignoredExt { + return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input) + } + } + } + return nil +} diff --git a/common/structures.go b/common/structures.go new file mode 100644 index 0000000..0104505 --- /dev/null +++ b/common/structures.go @@ -0,0 +1,8 @@ +package common + +//FileTypes is for ignoring files to add or ignoring compress, or for locked files, all use the same type of struct (files, folders and exts) +type FileTypes struct { + Files []string `toml:"files"` + Exts []string `toml:"exts"` + Folders []string `toml:"folders"` +} diff --git a/messages/structure.go b/messages/structure.go deleted file mode 100644 index 6a115e4..0000000 --- a/messages/structure.go +++ /dev/null @@ -1,30 +0,0 @@ -package messages - -// ID forces the command IDs to always be a certain type. -type ID int - -// ID forces all these commands to be locked in -const ( - ERROR ID = iota - COMMIT - CONNECTED - REFRESH - INFO - PUSH - PULL - REVERT - LOCK -) - -// Modifiers contains any arguments/modifiers to the command ID -type Modifiers struct { - ModifierID string - ModifierData func() -} - -// Command is the structure that all messages must adhere to -type Command struct { - CmdID ID //locked into the ID type - Mods []Modifiers - Body []byte -} diff --git a/server/engine/engine.go b/server/engine/engine.go index 26b0d06..7dc1693 100644 --- a/server/engine/engine.go +++ b/server/engine/engine.go @@ -1,6 +1,7 @@ package engine import ( + "fmt" "net/http" "github.com/labstack/echo" @@ -18,16 +19,26 @@ func (Server *GVCServer) GetInfo(context echo.Context) error { repoInfo.RawPort = config.RawPort repoInfo.Version = config.Version repoInfo.Repo = knownRepo - clients := repoInfo.Repo.KnownClients - for _, client := range clients { // Blank out the client keys - client.Key = "" + for i := range repoInfo.Repo.KnownClients { // Blank out the client keys + repoInfo.Repo.KnownClients[i].Key = "REDACTED" } - repoInfo.Repo.KnownClients = clients } } return context.JSONPretty(http.StatusAccepted, repoInfo, " ") } +// LockFile just locks the file/folder/wildcard +func (Server *GVCServer) LockFile(context echo.Context) error { + fileType := context.Param("type") + fileName := context.Param("name") + switch fileType { + case "file": + //common.CheckFileTypes(fileName, fileType,) + fmt.Println("Filename: ", fileName) + } + return nil +} + // Hello just verifies the server is running //TODO remove this, just extra shit we are sending func (Server *GVCServer) Hello(context echo.Context) error { helloMsg := "server alive" diff --git a/server/server.go b/server/server.go index 49f8521..b13af11 100644 --- a/server/server.go +++ b/server/server.go @@ -50,5 +50,6 @@ func main() { //Start the routes //e.GET("/hello", server.Hello) e.GET("/info/:repoName", server.GetInfo) + e.GET("/lock/:type/:name", server.LockFile) e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port))) } diff --git a/server/serverConfig.toml b/server/serverConfig.toml index 7e8fb67..1b63793 100644 --- a/server/serverConfig.toml +++ b/server/serverConfig.toml @@ -9,6 +9,20 @@ reporootpath = "F:\\repos" reponame = "gvc" defaultbranch = "master" localbranches = ["master"] + + [[repo.client]] + name = "deranjer" + key = "12345" + lastcommit = "4343434343434" + [repo.locked] + [repo.defaultignore] + [repo.nocompress] + +[[repo]] + rootpath = "" + reponame = "testrepo" + defaultbranch = "master" + localbranches = ["master", "feature1"] [repo.locked] [repo.defaultignore] [repo.nocompress] diff --git a/server/serverconfig/structures.go b/server/serverconfig/structures.go index 260451f..6d7d1ad 100644 --- a/server/serverconfig/structures.go +++ b/server/serverconfig/structures.go @@ -1,5 +1,7 @@ package config +import "github.com/deranjer/gvc/common" + // GvcServerConfig will hold the base server settings type GvcServerConfig struct { Version string `toml:"version"` // The server version @@ -12,14 +14,14 @@ type GvcServerConfig struct { // RepoConfig will be the struct that holds the config for a single repo type RepoConfig struct { - KnownClients []Clients `toml:"client"` //The remote servers for the repo - RootPath string `toml:"rootpath"` // The absolute path to the root of this particular repo - RepoName string `toml:"reponame"` - DefaultBranch string `toml:"defaultbranch"` - LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches - Locked FileTypes `toml:"locked"` - DefaultIgnores FileTypes `toml:"defaultignore"` //These are the recommended ignores that clients can pull - NoCompress FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings + KnownClients []Clients `toml:"client"` //The remote servers for the repo + RootPath string `toml:"rootpath"` // The absolute path to the root of this particular repo + RepoName string `toml:"reponame"` + DefaultBranch string `toml:"defaultbranch"` + LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches + Locked common.FileTypes `toml:"locked"` + DefaultIgnores common.FileTypes `toml:"defaultignore"` //These are the recommended ignores that clients can pull + NoCompress common.FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings } //Clients will be a slice of clients that have authenticated to the server @@ -28,10 +30,3 @@ type Clients struct { Key string `toml:"key"` //TODO will change this once we figure out authentication LastCommit string `toml:"lastcommit"` //Last commit that this client pushed to the server? not sure if useful } - -//FileTypes is for ignoring files to add or ignoring compress, or for locked files, all use the same type of struct (files, folders and exts) -type FileTypes struct { - Files []string `toml:"files"` - Exts []string `toml:"exts"` - Folders []string `toml:"folders"` -}