From 5337ea544b37ad9a46105901a4f1b0b624b58571 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Tue, 16 Jan 2024 11:24:06 -0500 Subject: [PATCH] Add framework for remote liveness check --- internal/remotes/remote/remote.go | 15 ++++++++++++--- internal/remotes/remotes.go | 9 +++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/internal/remotes/remote/remote.go b/internal/remotes/remote/remote.go index 2eb3576..c86fdd2 100644 --- a/internal/remotes/remote/remote.go +++ b/internal/remotes/remote/remote.go @@ -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 } diff --git a/internal/remotes/remotes.go b/internal/remotes/remotes.go index 87e3d04..2a5b6f9 100644 --- a/internal/remotes/remotes.go +++ b/internal/remotes/remotes.go @@ -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 {