102 lines
2.1 KiB
Go
102 lines
2.1 KiB
Go
package daemon
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"src.dualinventive.com/go/devsim"
|
|
"src.dualinventive.com/go/devsim/repository"
|
|
)
|
|
|
|
type repositoryClient struct {
|
|
c devsim.RepositoryServiceClient
|
|
}
|
|
|
|
var _ repository.Service = &repositoryClient{}
|
|
|
|
type repositoryClientObj struct {
|
|
rep *devsim.RepositoryInfo
|
|
}
|
|
|
|
var _ repository.Repository = &repositoryClientObj{}
|
|
|
|
func (rco *repositoryClientObj) Versions() ([]string, error) {
|
|
return rco.rep.Versions, nil
|
|
}
|
|
|
|
func (rco *repositoryClientObj) Poll() error {
|
|
return nil
|
|
}
|
|
|
|
func (rco *repositoryClientObj) Name() string {
|
|
return ""
|
|
}
|
|
|
|
func (rco *repositoryClientObj) URI() string {
|
|
return rco.rep.Uri
|
|
}
|
|
|
|
func (rco *repositoryClientObj) Key(version string) (string, error) {
|
|
return "", nil
|
|
}
|
|
|
|
func (rco *repositoryClientObj) Template(key string) (repository.Template, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
// Add adds the URI to the list of managed repositories
|
|
func (sc *repositoryClient) Add(uri string) error {
|
|
_, err := sc.c.Create(context.TODO(), &devsim.RepositoryRequest{Uri: uri})
|
|
return err
|
|
}
|
|
|
|
// Remove removes the URI from the managed repositories
|
|
func (sc *repositoryClient) Remove(uri string) error {
|
|
_, err := sc.c.Remove(context.TODO(), &devsim.RepositoryRequest{Uri: uri})
|
|
return err
|
|
}
|
|
|
|
// Poll polls all the repositories
|
|
func (sc *repositoryClient) Poll() []error {
|
|
return nil
|
|
}
|
|
|
|
// Find finds the repository using the URI
|
|
func (sc *repositoryClient) Find(uri string) (repository.Repository, error) {
|
|
repos, err := sc.list(uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(repos) == 0 {
|
|
return nil, fmt.Errorf("not found")
|
|
}
|
|
return repos[0], nil
|
|
}
|
|
|
|
// List returns all the repositories
|
|
func (sc *repositoryClient) List() []repository.Repository {
|
|
repos, err := sc.list("")
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return repos
|
|
}
|
|
|
|
func (sc *repositoryClient) list(uri string) ([]repository.Repository, error) {
|
|
repoInfoC, err := sc.c.Info(context.TODO(), &devsim.RepositoryRequest{Uri: uri})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var repos []repository.Repository
|
|
|
|
for {
|
|
rep, err := repoInfoC.Recv()
|
|
if err != nil {
|
|
break
|
|
}
|
|
repos = append(repos, &repositoryClientObj{rep: rep})
|
|
}
|
|
return repos, nil
|
|
}
|