-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup and condense get deployment logic
- Loading branch information
Showing
4 changed files
with
149 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package abstractions | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
apiv1 "github.com/beam-cloud/beta9/pkg/api/v1" | ||
"github.com/beam-cloud/beta9/pkg/auth" | ||
"github.com/beam-cloud/beta9/pkg/repository" | ||
"github.com/beam-cloud/beta9/pkg/types" | ||
) | ||
|
||
func ParseAndValidateDeploymentStubId( | ||
ctx context.Context, | ||
authInfo *auth.AuthInfo, | ||
stubId string, | ||
deploymentName string, | ||
version string, | ||
stubType string, | ||
backendRepo repository.BackendRepository, | ||
) (string, error) { | ||
if deploymentName != "" { | ||
var deployment *types.DeploymentWithRelated | ||
|
||
if version == "" { | ||
var err error | ||
deployment, err = backendRepo.GetLatestDeploymentByName(ctx, authInfo.Workspace.Id, deploymentName, stubType, true) | ||
if err != nil { | ||
return "", apiv1.HTTPBadRequest("Invalid deployment") | ||
} | ||
} else { | ||
version, err := strconv.Atoi(version) | ||
if err != nil { | ||
return "", apiv1.HTTPBadRequest("Invalid deployment version") | ||
} | ||
|
||
deployment, err = backendRepo.GetDeploymentByNameAndVersion(ctx, authInfo.Workspace.Id, deploymentName, uint(version), stubType) | ||
if err != nil { | ||
return "", apiv1.HTTPBadRequest("Invalid deployment") | ||
} | ||
} | ||
|
||
if deployment == nil { | ||
return "", apiv1.HTTPBadRequest("Invalid deployment") | ||
} | ||
|
||
if !deployment.Active { | ||
return "", apiv1.HTTPBadRequest("Deployment is not active") | ||
} | ||
|
||
stubId = deployment.Stub.ExternalId | ||
} | ||
|
||
return stubId, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.