improving client/server info command
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
version = "0.1.5"
|
||||
rootPath = ""
|
||||
rootpath = ""
|
||||
reponame = "gvc"
|
||||
currentbranch = "master"
|
||||
localbranches = ["master"]
|
||||
remotebranches = ["master", "test", "test2"]
|
||||
|
@@ -113,8 +113,9 @@ func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
initCmd.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
clientcmd.InitializeRepo() // creates and checks the paths
|
||||
repoName := clientcmd.InitializeRepo() // creates and checks the paths
|
||||
newConf := clientconfig.Gvcconfig{
|
||||
RepoName: repoName,
|
||||
Version: version,
|
||||
CurrentBranch: "master",
|
||||
}
|
||||
@@ -327,11 +328,11 @@ func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
return fmt.Errorf("Please supply a server name to test a remote")
|
||||
}
|
||||
server := remoteInfoCmd.OtherArgs()[0]
|
||||
err := clientcmd.PingServer(server, "master", conf)
|
||||
connectionString, err := clientcmd.FindServer(server, "master", conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = clientcmd.GetServerInfo()
|
||||
err = clientcmd.GetServerInfo(connectionString, conf.RepoName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
// ConfigPath is the global path to the config that is injected from the main client package.
|
||||
@@ -62,8 +61,8 @@ func checkFileTypes(input string, inputType string, ignores clientconfig.FileTyp
|
||||
return nil
|
||||
}
|
||||
|
||||
// PingServer sends a quick hello to the server to make sure it is live and we can connect to it. //TODO Remove this is just extra shit
|
||||
func PingServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) error {
|
||||
// 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
|
||||
branchName = "master"
|
||||
}
|
||||
@@ -71,19 +70,10 @@ func PingServer(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 + "/hello" //Create our hello request
|
||||
fmt.Println("Attempting connection on: ", connectionString)
|
||||
client := resty.New()
|
||||
|
||||
resp, err := client.R().EnableTrace().Get(connectionString)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
|
||||
}
|
||||
if resp.StatusCode() == 200 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("response from server was not 200, was instead %d", resp.StatusCode())
|
||||
connectionString := "http://" + remote.Host + port //Create our connection string
|
||||
fmt.Println("Generated connection string: ", connectionString)
|
||||
return connectionString, nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("unable to find server name in config")
|
||||
return "", fmt.Errorf("unable to find server name in config")
|
||||
}
|
||||
|
@@ -6,18 +6,24 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
// GetServerInfo queries the supplied server name for information about the current repo from the server
|
||||
func GetServerInfo() error {
|
||||
serverURL := "http://localhost:80/info/"
|
||||
// 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": "testRepo",
|
||||
"repoName": repoName,
|
||||
}).
|
||||
Get(serverURL + "{repoName}")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to server at: %s: error was: %s", serverURL, 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
|
||||
}
|
||||
|
@@ -4,10 +4,11 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// InitializeRepo creates the repo directory and a new config file
|
||||
func InitializeRepo() {
|
||||
func InitializeRepo() string {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal("unable to get current working directory.. permissions issue?")
|
||||
@@ -17,4 +18,7 @@ func InitializeRepo() {
|
||||
if err != nil {
|
||||
fmt.Println(".gvc directory already exists, but no config file... continuing")
|
||||
}
|
||||
repoName := filepath.Base(cwd)
|
||||
fmt.Println("Adding new repo with name: ", repoName)
|
||||
return repoName
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package clientcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
)
|
||||
|
||||
@@ -9,10 +11,11 @@ func RefreshContent(conf *clientconfig.Gvcconfig) error {
|
||||
remotes := conf.Remotes
|
||||
for _, remote := range remotes {
|
||||
if remote.Default {
|
||||
err := PingServer(remote.Name, conf.CurrentBranch, conf)
|
||||
connectionString, err := FindServer(remote.Name, conf.CurrentBranch, conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Connection String; ", connectionString) //TODO: Remove not needed
|
||||
//TODO: Now refresh content
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,8 @@ package config
|
||||
//Gvcconfig will be the struct that holds the entire client settings
|
||||
type Gvcconfig struct {
|
||||
Version string `toml:"version"`
|
||||
RootPath string `toml:"rootPath"`
|
||||
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
|
||||
|
@@ -9,7 +9,23 @@ import (
|
||||
// GetInfo return the relevant repo specific info to the client
|
||||
func (Server *GVCServer) GetInfo(context echo.Context) error {
|
||||
repo := context.Param("repoName")
|
||||
return context.JSON(http.StatusAccepted, 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 {
|
||||
if knownRepo.RepoName == repo {
|
||||
repoInfo.BindIP = config.BindIP
|
||||
repoInfo.Port = config.Port
|
||||
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 = ""
|
||||
}
|
||||
repoInfo.Repo.KnownClients = clients
|
||||
}
|
||||
}
|
||||
return context.JSONPretty(http.StatusAccepted, repoInfo, " ")
|
||||
}
|
||||
|
||||
// Hello just verifies the server is running //TODO remove this, just extra shit we are sending
|
||||
|
@@ -10,3 +10,12 @@ type GVCServer struct {
|
||||
Config config.GvcServerConfig //contains our full server config
|
||||
Echo *echo.Echo // Contains our web server instance
|
||||
}
|
||||
|
||||
// RepoInfoRequest is for when a client requests info about a repo
|
||||
type RepoInfoRequest struct {
|
||||
Version string
|
||||
Port int // The port that the server will listed on
|
||||
BindIP string // What IP to bind the server to. If empty will bind to all interfaces
|
||||
RawPort int // The optional TCP port that the server will send raw files over
|
||||
Repo config.RepoConfig //IMPORTANT: We need to blank out the client keys when sending
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ func main() {
|
||||
e := echo.New()
|
||||
server.Echo = e
|
||||
//Start the routes
|
||||
e.GET("/hello", server.Hello)
|
||||
//e.GET("/hello", server.Hello)
|
||||
e.GET("/info/:repoName", server.GetInfo)
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
|
||||
}
|
||||
|
@@ -4,3 +4,12 @@ ip = ""
|
||||
rawport = 0
|
||||
reporootpath = "F:\\repos"
|
||||
|
||||
[[repo]]
|
||||
rootpath = ""
|
||||
reponame = "gvc"
|
||||
defaultbranch = "master"
|
||||
localbranches = ["master"]
|
||||
[repo.locked]
|
||||
[repo.defaultignore]
|
||||
[repo.nocompress]
|
||||
|
||||
|
@@ -7,13 +7,14 @@ type GvcServerConfig struct {
|
||||
BindIP string `toml:"ip"` // What IP to bind the server to. If empty will bind to all interfaces
|
||||
RawPort int `toml:"rawport"` // The optional TCP port that the server will send raw files over
|
||||
RepoRootPath string `toml:"reporootpath"` // This will be the root path where (by default) all new repos will be stored at
|
||||
Repos []RepoConfig `toml:"repos"` // A struct of all the repos and their settings for the serve
|
||||
Repos []RepoConfig `toml:"repo"` // A struct of all the repos and their settings for the serve
|
||||
}
|
||||
|
||||
// RepoConfig will be the struct that holds the config for a single repo
|
||||
type RepoConfig struct {
|
||||
KnownClients []Clients `toml:"clients"` //The remote servers for the repo
|
||||
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"`
|
||||
|
Reference in New Issue
Block a user