Skip to content

Commit

Permalink
refactor: make provider manifests fetch through API only (#1725)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Brecic <[email protected]>
  • Loading branch information
lbrecic authored and Tpuljak committed Jan 21, 2025
1 parent 9c2da10 commit 1b401df
Show file tree
Hide file tree
Showing 34 changed files with 1,350 additions and 1,058 deletions.
31 changes: 0 additions & 31 deletions internal/util/apiclient/conversion/provider.go

This file was deleted.

30 changes: 22 additions & 8 deletions pkg/api/controllers/runner/provider/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"

"github.com/daytonaio/daytona/pkg/server"
"github.com/daytonaio/daytona/pkg/services"
"github.com/gin-gonic/gin"
)

Expand All @@ -17,25 +16,40 @@ import (
// @Tags provider
// @Summary Install provider
// @Description Install provider
// @Param installProviderDto body InstallProviderDTO true "Install provider"
// @Param runnerId path string true "Runner ID"
// @Param runnerId path string true "Runner ID"
// @Param providerName path string true "Provider name"
// @Param providerVersion query string false "Provider version - defaults to 'latest'"
// @Success 200
// @Router /runner/{runnerId}/provider/install [post]
// @Router /runner/{runnerId}/provider/{providerName}/install [post]
//
// @id InstallProvider
func InstallProvider(ctx *gin.Context) {
runnerId := ctx.Param("runnerId")
providerName := ctx.Param("providerName")
providerVersion := ctx.DefaultQuery("providerVersion", "latest")

var installProviderMetadataDto services.InstallProviderDTO
err := ctx.BindJSON(&installProviderMetadataDto)
config, err := server.GetConfig()
if err != nil {
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid request body: %w", err))
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to get config: %w", err))
return
}

server := server.GetInstance(nil)

err = server.RunnerService.InstallProvider(ctx.Request.Context(), runnerId, installProviderMetadataDto)
installedProviders, err := server.RunnerService.ListProviders(ctx, &runnerId)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to fetch installed providers: %w", err))
return
}

for _, provider := range installedProviders {
if provider.Name == providerName {
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("provider %s is already installed", providerName))
return
}
}

err = server.RunnerService.InstallProvider(ctx.Request.Context(), runnerId, providerName, providerVersion, config.RegistryUrl)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to install provider: %w", err))
return
Expand Down
28 changes: 28 additions & 0 deletions pkg/api/controllers/runner/provider/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,31 @@ func ListProviders(ctx *gin.Context) {

ctx.JSON(200, providers)
}

// ListProvidersForInstall godoc
//
// @Tags provider
// @Summary List providers available for installation
// @Description List providers available for installation
// @Produce json
// @Success 200 {array} ProviderDTO
// @Router /runner/provider/for-install [get]
//
// @id ListProvidersForInstall
func ListProvidersForInstall(ctx *gin.Context) {
config, err := server.GetConfig()
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to get config: %w", err))
return
}

server := server.GetInstance(nil)

providers, err := server.RunnerService.ListProvidersForInstall(ctx.Request.Context(), config.RegistryUrl)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to list providers for install: %w", err))
return
}

ctx.JSON(200, providers)
}
15 changes: 7 additions & 8 deletions pkg/api/controllers/runner/provider/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

_ "github.com/daytonaio/daytona/pkg/models"
"github.com/daytonaio/daytona/pkg/server"
"github.com/daytonaio/daytona/pkg/services"
"github.com/gin-gonic/gin"
)

Expand All @@ -18,27 +17,27 @@ import (
// @Tags provider
// @Summary Update provider
// @Description Update provider
// @Param updateProviderDto body UpdateProviderDTO true "Update provider"
// @Param runnerId path string true "Runner ID"
// @Param providerName path string true "Provider name"
// @Param runnerId path string true "Runner ID"
// @Param providerName path string true "Provider name"
// @Param providerVersion query string false "Provider version - defaults to 'latest'"
// @Success 200
// @Router /runner/{runnerId}/provider/{providerName}/update [post]
//
// @id UpdateProvider
func UpdateProvider(ctx *gin.Context) {
runnerId := ctx.Param("runnerId")
providerName := ctx.Param("providerName")
providerVersion := ctx.DefaultQuery("providerVersion", "latest")

var updateProviderMetadataDto services.UpdateProviderDTO
err := ctx.BindJSON(&updateProviderMetadataDto)
config, err := server.GetConfig()
if err != nil {
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid request body: %w", err))
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to get config: %w", err))
return
}

server := server.GetInstance(nil)

err = server.RunnerService.UpdateProvider(ctx.Request.Context(), runnerId, providerName, updateProviderMetadataDto)
err = server.RunnerService.UpdateProvider(ctx.Request.Context(), runnerId, providerName, providerVersion, config.RegistryUrl)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to update provider: %w", err))
return
Expand Down
125 changes: 66 additions & 59 deletions pkg/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,30 @@ const docTemplate = `{
}
}
},
"/runner/provider/for-install": {
"get": {
"description": "List providers available for installation",
"produces": [
"application/json"
],
"tags": [
"provider"
],
"summary": "List providers available for installation",
"operationId": "ListProvidersForInstall",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ProviderDTO"
}
}
}
}
}
},
"/runner/{runnerId}": {
"get": {
"description": "Find a runner",
Expand Down Expand Up @@ -1235,7 +1259,7 @@ const docTemplate = `{
}
}
},
"/runner/{runnerId}/provider/install": {
"/runner/{runnerId}/provider/{providerName}/install": {
"post": {
"description": "Install provider",
"tags": [
Expand All @@ -1244,21 +1268,25 @@ const docTemplate = `{
"summary": "Install provider",
"operationId": "InstallProvider",
"parameters": [
{
"description": "Install provider",
"name": "installProviderDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/InstallProviderDTO"
}
},
{
"type": "string",
"description": "Runner ID",
"name": "runnerId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Provider name",
"name": "providerName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Provider version - defaults to 'latest'",
"name": "providerVersion",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -1308,15 +1336,6 @@ const docTemplate = `{
"summary": "Update provider",
"operationId": "UpdateProvider",
"parameters": [
{
"description": "Update provider",
"name": "updateProviderDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateProviderDTO"
}
},
{
"type": "string",
"description": "Runner ID",
Expand All @@ -1330,6 +1349,12 @@ const docTemplate = `{
"name": "providerName",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Provider version - defaults to 'latest'",
"name": "providerVersion",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -4377,12 +4402,6 @@ const docTemplate = `{
}
}
},
"DownloadUrls": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"EnvironmentVariable": {
"type": "object",
"required": [
Expand Down Expand Up @@ -4878,25 +4897,6 @@ const docTemplate = `{
}
}
},
"InstallProviderDTO": {
"type": "object",
"required": [
"downloadUrls",
"name",
"version"
],
"properties": {
"downloadUrls": {
"$ref": "#/definitions/DownloadUrls"
},
"name": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"Job": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5230,6 +5230,28 @@ const docTemplate = `{
}
}
},
"ProviderDTO": {
"type": "object",
"required": [
"latest",
"name",
"version"
],
"properties": {
"label": {
"type": "string"
},
"latest": {
"type": "boolean"
},
"name": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"ProviderInfo": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5825,21 +5847,6 @@ const docTemplate = `{
}
}
},
"UpdateProviderDTO": {
"type": "object",
"required": [
"downloadUrls",
"version"
],
"properties": {
"downloadUrls": {
"$ref": "#/definitions/DownloadUrls"
},
"version": {
"type": "string"
}
}
},
"UpdateRunnerMetadataDTO": {
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit 1b401df

Please sign in to comment.