~ knotless Search/
↑↓ move↵ open⇧↵ all results

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0
30 lines · 1.2 KB Raw History
package componentcore

import (
	"context"
	"fmt"

	"k8s.io/apimachinery/pkg/runtime/schema"

	commonv1 "github.com/johnandersen777/socialweb-computer-kcp/api/common/v1alpha1"
	"github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1"
	"github.com/johnandersen777/socialweb-computer-kcp/internal/bus"
	"github.com/johnandersen777/socialweb-computer-kcp/internal/component"
	sshcontract "github.com/johnandersen777/socialweb-computer-kcp/internal/contract/ssh"
	"github.com/johnandersen777/socialweb-computer-kcp/internal/services/requester"
)

func (c *Core) provideComponents() {
	bus.Provide(c.handlers, schema.GroupKind{Group: v1alpha1.GroupName, Kind: requester.Kind}, sshcontract.CapabilityRun,
		func(ctx context.Context, to commonv1.ObjectRef, _ []string) (sshcontract.Runner, error) {
			service, ok := c.runtime.AwaitDeclared(ctx, component.Key{Workspace: to.Workspace, Kind: to.Kind, Name: to.Name}, nil)
			if !ok {
				return nil, fmt.Errorf("componentcore: the Requester %s/%s is not registered", to.Workspace, to.Name)
			}
			runner, ok := service.(sshcontract.Runner)
			if !ok {
				return nil, fmt.Errorf("componentcore: the Requester %s/%s does not run commands", to.Workspace, to.Name)
			}
			return runner, nil
		})
}