working on lock command
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user