working on lock command

This commit is contained in:
2020-06-08 22:52:40 -04:00
parent c2e74ce7f4
commit 441a9ed233
9 changed files with 132 additions and 48 deletions

View File

@@ -36,7 +36,7 @@ remotebranches = ["master", "test", "test2"]
default = false default = false
[locked] [locked]
files = ["test1\\client8.exe", "client1.exe"] files = ["test1\\client8.exe", "client1.exe", "client.go"]
exts = [".png"] exts = [".png"]
[ignore] [ignore]

View File

@@ -55,6 +55,9 @@ func main() {
// Adding the ignore commands // Adding the ignore commands
ignoreCommands(cli, &conf) ignoreCommands(cli, &conf)
// Adding the lock commands
lockCommands(cli, &conf)
// Adding the test commands // Adding the test commands
infoCommands(cli, &conf) infoCommands(cli, &conf)
@@ -98,7 +101,7 @@ func refreshCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first") fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0) os.Exit(0)
} }
err := clientcmd.RefreshContent(conf) err := clientcmd.RefreshContent(conf, conf.RepoName)
if err != nil { if err != nil {
return fmt.Errorf("unable to refresh content: %s", err) return fmt.Errorf("unable to refresh content: %s", err)
} }
@@ -432,7 +435,7 @@ func remoteCommands(cli *clir.Cli, conf *config.Gvcconfig) {
}) })
} }
func lockCommands(cli clir.Cli, conf *clientconfig.Gvcconfig) { func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
//All the lock commands and subcommands //All the lock commands and subcommands
//The lock subcommand //The lock subcommand
@@ -454,7 +457,11 @@ func lockCommands(cli clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first") fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0) os.Exit(0)
} }
if len(lockCmd.OtherArgs()) > 0 { if len(lockCmd.OtherArgs()) == 0 && file == "" && folder == "" && wildcard == "" { // if no input
lockCmd.PrintHelp()
return fmt.Errorf("please provide a file/folder/ext flag and name to be locked")
}
if len(lockCmd.OtherArgs()) > 1 {
lockCmd.PrintHelp() lockCmd.PrintHelp()
return fmt.Errorf("incorrect input detected, please fix and retry") return fmt.Errorf("incorrect input detected, please fix and retry")
} }

View File

@@ -36,11 +36,18 @@ func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconf
if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch
branchName = "master" branchName = "master"
} }
if serverName == "" { // if no serverName is specified, just use the default
for _, remote := range conf.Remotes {
if remote.Default {
serverName = remote.Name
}
}
}
for _, remote := range conf.Remotes { for _, remote := range conf.Remotes {
if serverName == remote.Name { if serverName == remote.Name {
fmt.Printf("Server found in config, connecting to: %s, host: %s, port: %d \n", remote.Name, remote.Host, remote.Port) fmt.Printf("Server found in config, connecting to: %s, host: %s, port: %d \n", remote.Name, remote.Host, remote.Port)
port := ":" + strconv.Itoa(remote.Port) port := ":" + strconv.Itoa(remote.Port)
connectionString := "http://" + remote.Host + port + "/" + conf.RepoName //Create our connection string //'http://server:port/:repo' //TODO, what about admin commands for entire server management, not just one repo? connectionString := "http://" + remote.Host + port //Create our connection string //'http://server:port'
fmt.Println("Generated connection string: ", connectionString) fmt.Println("Generated connection string: ", connectionString)
return connectionString, nil return connectionString, nil
} }

View File

@@ -9,7 +9,11 @@ import (
// GetServerInfo queries the supplied connection string for server info and uses the provided repoName to get repo specific information // GetServerInfo queries the supplied connection string for server info and uses the provided repoName to get repo specific information
func GetServerInfo(connectionString string, repoName string) error { func GetServerInfo(connectionString string, repoName string) error {
client := resty.New() client := resty.New()
resp, err := client.R().Get(connectionString + "/info") //creating the full string to get info resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
}).
Get(connectionString + "/info/" + "{repoName}") //creating the full string to get info
if err != nil { if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err) return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
} }

View File

@@ -5,6 +5,7 @@ import (
clientconfig "github.com/deranjer/gvc/client/clientconfig" clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common" "github.com/deranjer/gvc/common"
"github.com/go-resty/resty/v2"
) )
//LockFiles locks file(s)/folder based on name/wildcard, etc //LockFiles locks file(s)/folder based on name/wildcard, etc
@@ -14,7 +15,8 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
return err return err
} }
locked := conf.Locked locked := conf.Locked
switch inputType { // TODO: add default case for generic error handling connectionString, err := FindServer("", conf.CurrentBranch, conf) //TODO: Maybe allow user to specify lock server? Seems like they should just use the default server though
switch inputType { // TODO: add default case for generic error handling // TODO: there is no user supplied input here, so WHY?
case "file": case "file":
err := common.CheckFileTypes(input, "file", locked) err := common.CheckFileTypes(input, "file", locked)
if err != nil { if err != nil {
@@ -22,6 +24,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
} }
fmt.Println("Adding file to locked: ", input) fmt.Println("Adding file to locked: ", input)
conf.Locked.Files = append(conf.Locked.Files, input) conf.Locked.Files = append(conf.Locked.Files, input)
err = SendLockToServer(connectionString, conf.RepoName, "file", input)
if err != nil {
return fmt.Errorf("error sending lock to server: %s", err)
}
return nil return nil
case "folder": case "folder":
err := common.CheckFileTypes(input, "folder", locked) err := common.CheckFileTypes(input, "folder", locked)
@@ -109,3 +115,26 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
} }
return fmt.Errorf("This... should not have happened, some kind of internal error on RemoveLockFiles function call, switch failure") return fmt.Errorf("This... should not have happened, some kind of internal error on RemoveLockFiles function call, switch failure")
} }
// SendLockToServer sends an updated lock file to the server
func SendLockToServer(connectionString string, repoName string, fileType string, fileName string) error {
client := resty.New()
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
"type": fileType,
"name": fileName,
}).
Get(connectionString + "/lock/" + "{repoName}/" + "{type}/" + "{name}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}

View File

@@ -8,33 +8,26 @@ import (
) )
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch) // RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
func RefreshContent(conf *clientconfig.Gvcconfig) error { func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TODO: need to change command to be able to target user specified servers
remotes := conf.Remotes connectionString, err := FindServer("", conf.CurrentBranch, conf)
for _, remote := range remotes { if err != nil {
if remote.Default { return err
connectionString, err := FindServer(remote.Name, conf.CurrentBranch, conf)
if err != nil {
return err
}
client := resty.New()
resp, err := client.R().
// SetPathParams(map[string]string{
// "repoName": repoName,
// }).
//Get(connectionString + "{repoName}" + "/info") //creating the full string to get info
Get(connectionString + "/refresh")
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}
} }
client := resty.New()
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": repoName,
}).
Get(connectionString + "/refresh" + "{repoName}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil return nil
} }

View File

@@ -0,0 +1,30 @@
version = "0.1"
port = 80
ip = ""
rawport = 0
reporootpath = "F:\\repos"
[[repo]]
rootpath = ""
reponame = "gvc"
defaultbranch = "master"
localbranches = ["master"]
[[repo.client]]
name = "deranjer"
key = "12345"
lastcommit = "4343434343434"
[repo.locked]
files = ["client1.exe", "client2.exe"]
[repo.defaultignore]
[repo.nocompress]
[[repo]]
rootpath = ""
reponame = "testrepo"
defaultbranch = "master"
localbranches = ["master", "feature1"]
[repo.locked]
[repo.defaultignore]
[repo.nocompress]

View File

@@ -2,17 +2,18 @@ package engine
import ( import (
"fmt" "fmt"
"log"
"net/http" "net/http"
"github.com/deranjer/gvc/common" "github.com/deranjer/gvc/common"
serverconfig "github.com/deranjer/gvc/server/serverconfig" serverconfig "github.com/deranjer/gvc/server/serverconfig"
"github.com/deranjer/store"
"github.com/labstack/echo" "github.com/labstack/echo"
) )
// GetInfo return the relevant repo specific info to the client // GetInfo return the relevant repo specific info to the client
func (Server *GVCServer) GetInfo(context echo.Context) error { func (Server *GVCServer) GetInfo(context echo.Context) error {
repo := context.Param("repo") repo := context.Param("repo")
fmt.Println("Asking about repo: ", repo)
config := Server.Config config := Server.Config
var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info
for _, knownRepo := range config.Repos { for _, knownRepo := range config.Repos {
@@ -35,19 +36,32 @@ func (Server *GVCServer) LockFile(context echo.Context) error {
fileType := context.Param("type") fileType := context.Param("type")
fileName := context.Param("name") fileName := context.Param("name")
repoName := context.Param("repo") repoName := context.Param("repo")
var repo serverconfig.RepoConfig fmt.Printf("Lockfile: %s %s %s", repoName, fileType, fileName)
for i, knownRepo := range Server.Config.Repos { var locked common.FileTypes
if knownRepo.RepoName == repoName { for i, repo := range Server.Config.Repos {
repo = Server.Config.Repos[i] if repo.RepoName == repoName {
locked = Server.Config.Repos[i].Locked
} }
} }
err := common.CheckFileTypes(fileName, fileType, locked) // making sure fi/f/wc is not already locked or cannot be locked.
if err != nil {
return fmt.Errorf("failed checking file lock: %s", err)
}
switch fileType { switch fileType {
case "file": case "file":
err := common.CheckFileTypes(fileName, fileType, repo.Locked)
if err != nil {
return fmt.Errorf("failed checking file lock: %s", err)
}
fmt.Println("Filename: ", fileName) fmt.Println("Filename: ", fileName)
locked.Files = append(locked.Files, fileName)
case "folder":
fmt.Println("Folder: ", fileName)
locked.Folders = append(locked.Folders, fileName)
case "wildcard":
fmt.Println("Wildcard: ", fileName)
locked.Exts = append(locked.Exts, fileName)
}
fmt.Println("Locked: ", locked) // TODO!!!!!!!!!!!! Write this to conf
err = store.Save(serverconfig.DefaultConfigPath, Server.Config) // Save our new default config back to TOML so it can be read in
if err != nil {
log.Fatalf("unable to save config to toml file: %s", err)
} }
return nil return nil
} }

View File

@@ -49,10 +49,10 @@ func main() {
server.Echo = e server.Echo = e
//Start the routes //Start the routes
//e.GET("/hello", server.Hello) //e.GET("/hello", server.Hello)
e.GET("/:repo/info/", server.GetInfo) e.GET("/info/:repo", server.GetInfo)
e.GET("/:repo/lock/:type/:name", server.LockFile) e.GET("/lock/:repo/:type/:name", server.LockFile)
e.GET("/:repo/refresh", server.Refresh) e.GET("/refresh/:repo", server.Refresh)
e.GET("/:repo/revert/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull? e.GET("/revert/:repo/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull?
e.GET("/:repo/pull/:branch", server.Pull) e.GET("/pull/:repo/:branch", server.Pull)
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port))) e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
} }