Skip to content

Commit

Permalink
feat: provider requirement handling (#1300)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: provider interface change

Signed-off-by: Philip-21 <[email protected]>
  • Loading branch information
Philip-21 authored Nov 22, 2024
1 parent e2e5818 commit ea2db7f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type Provider interface {
Initialize(InitializeProviderRequest) (*util.Empty, error)
GetInfo() (ProviderInfo, error)
CheckRequirements() (*[]RequirementStatus, error)

GetTargetManifest() (*ProviderTargetManifest, error)
GetPresetTargets() (*[]ProviderTarget, error)
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func (m *ProviderRPCClient) GetInfo() (ProviderInfo, error) {
return resp, err
}

func (m *ProviderRPCClient) CheckRequirements() (*[]RequirementStatus, error) {
var result []RequirementStatus
err := m.client.Call("Plugin.CheckRequirements", new(interface{}), &result)
return &result, err
}

func (m *ProviderRPCClient) GetTargetManifest() (*ProviderTargetManifest, error) {
var resp ProviderTargetManifest
err := m.client.Call("Plugin.GetTargetManifest", new(interface{}), &resp)
Expand Down
9 changes: 9 additions & 0 deletions pkg/provider/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func (m *ProviderRPCServer) GetInfo(arg interface{}, resp *ProviderInfo) error {
return nil
}

func (m *ProviderRPCServer) CheckRequirements(arg interface{}, resp *[]RequirementStatus) error {
result, err := m.Impl.CheckRequirements()
if err != nil {
return err
}
*resp = *result
return nil
}

func (m *ProviderRPCServer) GetTargetManifest(arg interface{}, resp *ProviderTargetManifest) error {
targetManifest, err := m.Impl.GetTargetManifest()
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ type ProviderTargetProperty struct {
// Suggestions is an optional list of auto-complete values to assist the user while filling the field
Suggestions []string
}

type RequirementStatus struct {
Name string
Met bool
Reason string
} // @name RequirementStatus
11 changes: 11 additions & 0 deletions pkg/server/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func (s *Server) registerProviders() error {
log.Error(err)
continue
}
requirements, err := (*provider).CheckRequirements()
if err != nil {
return err
}
for _, req := range *requirements {
if req.Met {
log.Infof("Provider requirement met: %s", req.Reason)
} else {
log.Warnf("Provider requirement not met: %s", req.Reason)
}
}

if manifest.HasUpdateAvailable(info.Name, info.Version) {
log.Infof("Update available for %s. Update with `daytona provider update`.", info.Name)
Expand Down

0 comments on commit ea2db7f

Please sign in to comment.