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"
|
name = "test2"
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = 80
|
port = 80
|
||||||
default = false
|
default = true
|
||||||
|
|
||||||
[[remote]]
|
[[remote]]
|
||||||
name = "test4"
|
name = "test4"
|
||||||
@@ -27,7 +27,7 @@ remotebranches = ["master", "test", "test2"]
|
|||||||
name = "test5"
|
name = "test5"
|
||||||
host = "localhost1"
|
host = "localhost1"
|
||||||
port = 9997
|
port = 9997
|
||||||
default = true
|
default = false
|
||||||
|
|
||||||
[[remote]]
|
[[remote]]
|
||||||
name = "test6"
|
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")
|
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if len(remoteInfoCmd.OtherArgs()) == 0 {
|
var server string
|
||||||
remoteInfoCmd.PrintHelp()
|
if len(remoteInfoCmd.OtherArgs()) == 0 { //Notify that we are using default server if none specified
|
||||||
return fmt.Errorf("Please supply a server name to test a remote")
|
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)
|
connectionString, err := clientcmd.FindServer(server, "master", conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -40,7 +40,7 @@ func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconf
|
|||||||
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 //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)
|
fmt.Println("Generated connection string: ", connectionString)
|
||||||
return connectionString, nil
|
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
|
// 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 {
|
||||||
serverURL := connectionString + "/info/" //creating the full string to get info
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
resp, err := client.R().
|
resp, err := client.R().Get(connectionString + "/info") //creating the full string to get info
|
||||||
SetPathParams(map[string]string{
|
|
||||||
"repoName": repoName,
|
|
||||||
}).
|
|
||||||
Get(serverURL + "{repoName}")
|
|
||||||
if err != nil {
|
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.IsError() {
|
||||||
if resp.StatusCode() == 404 {
|
if resp.StatusCode() == 404 {
|
||||||
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
|
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)
|
fmt.Println(resp)
|
||||||
return nil
|
return nil
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
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)
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Connection String; ", connectionString) //TODO: Remove not needed
|
client := resty.New()
|
||||||
//TODO: Now refresh content
|
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
|
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
|
// 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 {
|
switch inputType {
|
||||||
case "file":
|
case "file":
|
||||||
fileExt := filepath.Ext(input) // TODO more sanity checking on ext
|
fileExt := filepath.Ext(input) // TODO more sanity checking on ext
|
||||||
for _, ignoredExt := range ignores.Exts {
|
for _, suppliedExt := range excludeList.Exts {
|
||||||
if fileExt == ignoredExt {
|
if fileExt == suppliedExt { //Check to make sure the file is not already on the list via ext
|
||||||
return fmt.Errorf("file ext is on ignored list, cannot add file with file ext %s", fileExt)
|
return fmt.Errorf("file ext is on excludeList, cannot add file ext %s", fileExt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ignoredFile := range ignores.Files {
|
for _, suppliedFile := range excludeList.Files {
|
||||||
if input == ignoredFile {
|
if input == suppliedFile {
|
||||||
return fmt.Errorf("file name is on ignored list, cannot add file with name %s", input)
|
return fmt.Errorf("file name is on excludeList, cannot add file with name %s", input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "folder":
|
case "folder":
|
||||||
for _, ignoredFolder := range ignores.Folders {
|
for _, suppliedFolder := range excludeList.Folders {
|
||||||
if input == ignoredFolder {
|
if input == suppliedFolder {
|
||||||
return fmt.Errorf("folder name is on the ignored list, cannot add folder with name %s", input)
|
return fmt.Errorf("folder name is on the excludeList, cannot add folder with name %s", input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "wildcard":
|
case "wildcard":
|
||||||
for _, ignoredExt := range ignores.Exts {
|
for _, suppliedExt := range excludeList.Exts {
|
||||||
if input == ignoredExt {
|
if input == suppliedExt {
|
||||||
return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input)
|
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"`
|
Exts []string `toml:"exts"`
|
||||||
Folders []string `toml:"folders"`
|
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"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/deranjer/gvc/common"
|
||||||
|
serverconfig "github.com/deranjer/gvc/server/serverconfig"
|
||||||
"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("repoName")
|
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 {
|
||||||
@@ -31,14 +34,57 @@ func (Server *GVCServer) GetInfo(context echo.Context) error {
|
|||||||
func (Server *GVCServer) LockFile(context echo.Context) error {
|
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")
|
||||||
|
var repo serverconfig.RepoConfig
|
||||||
|
for i, knownRepo := range Server.Config.Repos {
|
||||||
|
if knownRepo.RepoName == repoName {
|
||||||
|
repo = Server.Config.Repos[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
switch fileType {
|
switch fileType {
|
||||||
case "file":
|
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)
|
fmt.Println("Filename: ", fileName)
|
||||||
}
|
}
|
||||||
return nil
|
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
|
// Hello just verifies the server is running //TODO remove this, just extra shit we are sending
|
||||||
func (Server *GVCServer) Hello(context echo.Context) error {
|
func (Server *GVCServer) Hello(context echo.Context) error {
|
||||||
helloMsg := "server alive"
|
helloMsg := "server alive"
|
||||||
|
@@ -49,7 +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("/info/:repoName", server.GetInfo)
|
e.GET("/:repo/info/", server.GetInfo)
|
||||||
e.GET("/lock/:type/:name", server.LockFile)
|
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)))
|
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ reporootpath = "F:\\repos"
|
|||||||
key = "12345"
|
key = "12345"
|
||||||
lastcommit = "4343434343434"
|
lastcommit = "4343434343434"
|
||||||
[repo.locked]
|
[repo.locked]
|
||||||
|
files = ["client1.exe", "client2.exe"]
|
||||||
[repo.defaultignore]
|
[repo.defaultignore]
|
||||||
[repo.nocompress]
|
[repo.nocompress]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user