Add framework for remote liveness check

This commit is contained in:
Ryan McGuire 2024-01-16 11:24:06 -05:00
parent d7181b1cf6
commit 5337ea544b
2 changed files with 21 additions and 3 deletions

View File

@ -13,12 +13,21 @@ type RemoteInfo struct {
Token string
}
type RemoteProto string
const (
RemoteProtoSSH RemoteProto = "ssh"
RemoteProtoHTTP RemoteProto = "http"
RemoteProtoHTTPS RemoteProto = "https"
)
// Any remote needs to be able to return
// the number of projects the user has access to and also
// stream all projects along with updates to channels
// provided by *load.ProgressInfo
type Remote interface {
GetInfo() *RemoteInfo
GetNumProjects(*RemoteQueryOpts) int
StreamProjects(*load.ProgressInfo, *RemoteQueryOpts)
GetInfo() *RemoteInfo // Returns basic RemoteInfo struct
IsAlive(RemoteProto) bool // Indicates if the remote is reachable by either SSH or HTTP
GetNumProjects(*RemoteQueryOpts) int // Returns total number of accessible projects
StreamProjects(*load.ProgressInfo, *RemoteQueryOpts) // Streams projects to chans provided in load.ProgressInfo
}

View File

@ -21,6 +21,15 @@ func (r *Remotes) AddRemote(remote remote.Remote) {
*r = append(*r, remote)
}
func (r *Remotes) GetRemoteByHost(host string) remote.Remote {
for _, remote := range *r {
if remote.GetInfo().Host == host {
return remote
}
}
return nil
}
// Launches project streamsers for all remotes in goroutines
// returns slice of load.ProgressInfo
func (r *Remotes) StreamRemotes(opts *remote.RemoteQueryOpts) []*load.ProgressInfo {