From 6629990fd597f06d7436c939fd55e3a6542cad5b Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 27 Oct 2021 11:02:10 +0000 Subject: [PATCH] feat: implement single microvm query API --- core/application/query.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/application/query.go b/core/application/query.go index 3b4e54c69..21427ec9f 100644 --- a/core/application/query.go +++ b/core/application/query.go @@ -2,12 +2,35 @@ package application import ( "context" + "fmt" "github.com/weaveworks/flintlock/core/models" + "github.com/weaveworks/flintlock/pkg/log" ) func (a *app) GetMicroVM(ctx context.Context, id, namespace string) (*models.MicroVM, error) { - return nil, errNotImplemeted + logger := log.GetLogger(ctx).WithField("component", "app") + logger.Trace("querying microvm: ", id, "with namespace: ", namespace) + + if id == "" { + return nil, errIDRequired + } + + foundMvm, err := a.ports.Repo.Get(ctx, id, namespace) + if err != nil { + return nil, fmt.Errorf("error attempting to locate microvm with id: %s, in namespace: %s: %w", id, namespace, err) + } + + if foundMvm == nil { + if foundMvm == nil { + return nil, specNotFoundError{ + name: id, + namespace: namespace, + } + } + } + + return foundMvm, nil } func (a *app) GetAllMicroVM(ctx context.Context, namespace string) ([]*models.MicroVM, error) {