working on lock command
This commit is contained in:
@@ -36,7 +36,7 @@ remotebranches = ["master", "test", "test2"]
|
||||
default = false
|
||||
|
||||
[locked]
|
||||
files = ["test1\\client8.exe", "client1.exe"]
|
||||
files = ["test1\\client8.exe", "client1.exe", "client.go"]
|
||||
exts = [".png"]
|
||||
|
||||
[ignore]
|
||||
|
@@ -55,6 +55,9 @@ func main() {
|
||||
// Adding the ignore commands
|
||||
ignoreCommands(cli, &conf)
|
||||
|
||||
// Adding the lock commands
|
||||
lockCommands(cli, &conf)
|
||||
|
||||
// Adding the test commands
|
||||
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")
|
||||
os.Exit(0)
|
||||
}
|
||||
err := clientcmd.RefreshContent(conf)
|
||||
err := clientcmd.RefreshContent(conf, conf.RepoName)
|
||||
if err != nil {
|
||||
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
|
||||
//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")
|
||||
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()
|
||||
return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||
}
|
||||
|
@@ -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
|
||||
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 {
|
||||
if serverName == remote.Name {
|
||||
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)
|
||||
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)
|
||||
return connectionString, nil
|
||||
}
|
||||
|
@@ -9,7 +9,11 @@ import (
|
||||
// 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 {
|
||||
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 {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/deranjer/gvc/common"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
//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
|
||||
}
|
||||
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":
|
||||
err := common.CheckFileTypes(input, "file", locked)
|
||||
if err != nil {
|
||||
@@ -22,6 +24,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
|
||||
}
|
||||
fmt.Println("Adding file to locked: ", 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
|
||||
case "folder":
|
||||
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")
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
@@ -8,33 +8,26 @@ import (
|
||||
)
|
||||
|
||||
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
|
||||
func RefreshContent(conf *clientconfig.Gvcconfig) error {
|
||||
remotes := conf.Remotes
|
||||
for _, remote := range remotes {
|
||||
if remote.Default {
|
||||
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
|
||||
}
|
||||
func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TODO: need to change command to be able to target user specified servers
|
||||
connectionString, err := FindServer("", conf.CurrentBranch, conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
30
server/config/serverConfig.toml
Normal file
30
server/config/serverConfig.toml
Normal 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]
|
||||
|
@@ -2,17 +2,18 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/deranjer/gvc/common"
|
||||
serverconfig "github.com/deranjer/gvc/server/serverconfig"
|
||||
"github.com/deranjer/store"
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
// GetInfo return the relevant repo specific info to the client
|
||||
func (Server *GVCServer) GetInfo(context echo.Context) error {
|
||||
repo := context.Param("repo")
|
||||
fmt.Println("Asking about repo: ", repo)
|
||||
config := Server.Config
|
||||
var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info
|
||||
for _, knownRepo := range config.Repos {
|
||||
@@ -35,19 +36,32 @@ func (Server *GVCServer) LockFile(context echo.Context) error {
|
||||
fileType := context.Param("type")
|
||||
fileName := context.Param("name")
|
||||
repoName := context.Param("repo")
|
||||
var repo serverconfig.RepoConfig
|
||||
for i, knownRepo := range Server.Config.Repos {
|
||||
if knownRepo.RepoName == repoName {
|
||||
repo = Server.Config.Repos[i]
|
||||
fmt.Printf("Lockfile: %s %s %s", repoName, fileType, fileName)
|
||||
var locked common.FileTypes
|
||||
for i, repo := range Server.Config.Repos {
|
||||
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 {
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
@@ -49,10 +49,10 @@ func main() {
|
||||
server.Echo = e
|
||||
//Start the routes
|
||||
//e.GET("/hello", server.Hello)
|
||||
e.GET("/:repo/info/", server.GetInfo)
|
||||
e.GET("/:repo/lock/:type/:name", server.LockFile)
|
||||
e.GET("/:repo/refresh", server.Refresh)
|
||||
e.GET("/:repo/revert/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull?
|
||||
e.GET("/:repo/pull/:branch", server.Pull)
|
||||
e.GET("/info/:repo", server.GetInfo)
|
||||
e.GET("/lock/:repo/:type/:name", server.LockFile)
|
||||
e.GET("/refresh/:repo", server.Refresh)
|
||||
e.GET("/revert/:repo/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull?
|
||||
e.GET("/pull/:repo/:branch", server.Pull)
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user