adding more server/client communication commands, need to fix echo path params
This commit is contained in:
@@ -9,7 +9,7 @@ remotebranches = ["master", "test", "test2"]
|
||||
name = "test2"
|
||||
host = "localhost"
|
||||
port = 80
|
||||
default = false
|
||||
default = true
|
||||
|
||||
[[remote]]
|
||||
name = "test4"
|
||||
@@ -27,7 +27,7 @@ remotebranches = ["master", "test", "test2"]
|
||||
name = "test5"
|
||||
host = "localhost1"
|
||||
port = 9997
|
||||
default = true
|
||||
default = false
|
||||
|
||||
[[remote]]
|
||||
name = "test6"
|
||||
|
@@ -323,11 +323,18 @@ func infoCommands(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(remoteInfoCmd.OtherArgs()) == 0 {
|
||||
remoteInfoCmd.PrintHelp()
|
||||
return fmt.Errorf("Please supply a server name to test a remote")
|
||||
var server string
|
||||
if len(remoteInfoCmd.OtherArgs()) == 0 { //Notify that we are using default server if none specified
|
||||
fmt.Println("No server specified, using default...")
|
||||
for _, remote := range conf.Remotes {
|
||||
if remote.Default {
|
||||
server = remote.Name
|
||||
}
|
||||
}
|
||||
} else { // Server name was specified, using that server
|
||||
server = remoteInfoCmd.OtherArgs()[0]
|
||||
}
|
||||
server := remoteInfoCmd.OtherArgs()[0]
|
||||
|
||||
connectionString, err := clientcmd.FindServer(server, "master", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -40,7 +40,7 @@ func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconf
|
||||
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 //Create our connection string
|
||||
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?
|
||||
fmt.Println("Generated connection string: ", connectionString)
|
||||
return connectionString, nil
|
||||
}
|
||||
|
@@ -8,21 +8,16 @@ 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 {
|
||||
serverURL := connectionString + "/info/" //creating the full string to get info
|
||||
client := resty.New()
|
||||
resp, err := client.R().
|
||||
SetPathParams(map[string]string{
|
||||
"repoName": repoName,
|
||||
}).
|
||||
Get(serverURL + "{repoName}")
|
||||
resp, err := client.R().Get(connectionString + "/info") //creating the full string to get info
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", serverURL, err)
|
||||
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)
|
||||
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
|
||||
}
|
||||
fmt.Println(resp)
|
||||
return nil
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
|
||||
@@ -15,8 +16,24 @@ func RefreshContent(conf *clientconfig.Gvcconfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Connection String; ", connectionString) //TODO: Remove not needed
|
||||
//TODO: Now refresh content
|
||||
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
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -6,29 +6,30 @@ import (
|
||||
)
|
||||
|
||||
// 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 {
|
||||
// Since Ignore, NoCompress, and Locked have the same structure, you can provide the exclude list for any of them and this func will check that list to see if it already exists
|
||||
func CheckFileTypes(input string, inputType string, excludeList 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 _, suppliedExt := range excludeList.Exts {
|
||||
if fileExt == suppliedExt { //Check to make sure the file is not already on the list via ext
|
||||
return fmt.Errorf("file ext is on excludeList, cannot add 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)
|
||||
for _, suppliedFile := range excludeList.Files {
|
||||
if input == suppliedFile {
|
||||
return fmt.Errorf("file name is on excludeList, 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)
|
||||
for _, suppliedFolder := range excludeList.Folders {
|
||||
if input == suppliedFolder {
|
||||
return fmt.Errorf("folder name is on the excludeList, cannot add folder with name %s", input)
|
||||
}
|
||||
}
|
||||
case "wildcard":
|
||||
for _, ignoredExt := range ignores.Exts {
|
||||
if input == ignoredExt {
|
||||
for _, suppliedExt := range excludeList.Exts {
|
||||
if input == suppliedExt {
|
||||
return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input)
|
||||
}
|
||||
}
|
||||
|
@@ -6,3 +6,11 @@ type FileTypes struct {
|
||||
Exts []string `toml:"exts"`
|
||||
Folders []string `toml:"folders"`
|
||||
}
|
||||
|
||||
// RepoRefreshRequest returns locks, ignores, and commits/branches. Server marshals into this, client unmarshals
|
||||
type RepoRefreshRequest struct {
|
||||
Branches []string // List of known branches on server
|
||||
Commits string //TODO: This will be pulled from DB and be a different type
|
||||
Locked FileTypes
|
||||
Ignores FileTypes
|
||||
}
|
||||
|
@@ -4,12 +4,15 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/deranjer/gvc/common"
|
||||
serverconfig "github.com/deranjer/gvc/server/serverconfig"
|
||||
"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("repoName")
|
||||
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 {
|
||||
@@ -31,14 +34,57 @@ func (Server *GVCServer) GetInfo(context echo.Context) error {
|
||||
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]
|
||||
}
|
||||
}
|
||||
switch fileType {
|
||||
case "file":
|
||||
//common.CheckFileTypes(fileName, fileType,)
|
||||
err := common.CheckFileTypes(fileName, fileType, repo.Locked)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed checking file lock: %s", err)
|
||||
}
|
||||
fmt.Println("Filename: ", fileName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Refresh sends all updated information to client (like git fetch)
|
||||
func (Server *GVCServer) Refresh(context echo.Context) error {
|
||||
repoName := context.Param("repo")
|
||||
var serverRepo serverconfig.RepoConfig
|
||||
for i, repo := range Server.Config.Repos {
|
||||
if repo.RepoName == repoName {
|
||||
serverRepo = Server.Config.Repos[i]
|
||||
}
|
||||
}
|
||||
// pull the locks and ignores to send back to client
|
||||
branches := serverRepo.LocalBranches
|
||||
serverLocks := serverRepo.Locked
|
||||
serverIgnores := serverRepo.DefaultIgnores
|
||||
refreshResult := common.RepoRefreshRequest{
|
||||
Branches: branches,
|
||||
Locked: serverLocks,
|
||||
Ignores: serverIgnores,
|
||||
}
|
||||
return context.JSON(http.StatusOK, refreshResult)
|
||||
}
|
||||
|
||||
// Revert fetches the supplied file (or entire repo) at version X and pushes it to the client // TODO: This should perhaps just be part of PULL?
|
||||
func (Server *GVCServer) Revert(context echo.Context) error {
|
||||
repoName := context.Param("repo")
|
||||
return context.JSON(http.StatusOK, repoName)
|
||||
}
|
||||
|
||||
// Pull fetches the latest changes from the server to the client.
|
||||
func (Server *GVCServer) Pull(context echo.Context) error {
|
||||
helloMsg := "server alive"
|
||||
return context.JSON(http.StatusOK, helloMsg)
|
||||
}
|
||||
|
||||
// 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"
|
||||
|
@@ -49,7 +49,10 @@ func main() {
|
||||
server.Echo = e
|
||||
//Start the routes
|
||||
//e.GET("/hello", server.Hello)
|
||||
e.GET("/info/:repoName", server.GetInfo)
|
||||
e.GET("/lock/:type/:name", server.LockFile)
|
||||
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.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ reporootpath = "F:\\repos"
|
||||
key = "12345"
|
||||
lastcommit = "4343434343434"
|
||||
[repo.locked]
|
||||
files = ["client1.exe", "client2.exe"]
|
||||
[repo.defaultignore]
|
||||
[repo.nocompress]
|
||||
|
||||
|
Reference in New Issue
Block a user