Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom assettypes #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/api/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func (a Asset) Validate() error {
return errors.Validation("Identifier is not a valid DomainName")
}
default:
// If none of the previous case match, force a validation error
return errors.Validation("Asset type not supported")
// If none of the previous case match, should be fine.
return nil
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/endpoint/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func makeMergeDiscoveredAssetsEndpoint(s api.VulcanitoService, logger kitlog.Log
if ar.Identifier == "" || ar.Type == "" {
return nil, errors.Validation("Asset identifier and type are required for all the assets")
}
if !api.ValidAssetType(ar.Type) {

if _, err := s.GetAssetType(ctx, ar.Type); err != nil {
return nil, errors.Validation(fmt.Errorf("Invalid asset type (%s) for asset (%v)", ar.Type, ar.Identifier))
}

Expand Down
24 changes: 9 additions & 15 deletions pkg/api/service/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ func (s vulcanitoService) CreateAssets(ctx context.Context, assets []api.Asset,

// Asset type provided by the user in the request.
if asset.AssetType != nil && asset.AssetType.Name != "" {
if !api.ValidAssetType(asset.AssetType.Name) {
return nil, errors.Validation("Asset type not found", "asset", asset.Identifier, asset.AssetType.Name)
}

// Retrieve asset type from its name.
assetTypeObj, err := s.GetAssetType(ctx, asset.AssetType.Name)
if err != nil {
if errors.IsKind(err, errors.ErrNotFound) {
return nil, errors.Validation("Asset type not found", "asset", asset.Identifier, asset.AssetType.Name)
}
return nil, err
}

Expand Down Expand Up @@ -179,18 +178,14 @@ func (s vulcanitoService) CreateAssetsMultiStatus(ctx context.Context, assets []

// If user specified the asset type.
if asset.AssetType != nil && asset.AssetType.Name != "" {
// If the asset type is invalid, abort the asset creation.
if !api.ValidAssetType(asset.AssetType.Name) {
response.Status = errors.Validation("Asset type not found", "asset", asset.Identifier, asset.AssetType.Name)
responses = append(responses, response)
continue
}

// Retrieve asset type from its name.
assetTypeObj, err := s.GetAssetType(ctx, asset.AssetType.Name)
if err != nil {
// If there is an error retrieiving the asset type information, abort the asset creation.
response.Status = err
if errors.IsKind(err, errors.ErrNotFound) {
response.Status = errors.Validation("Asset type not found", "asset", asset.Identifier, asset.AssetType.Name)
}
responses = append(responses, response)
continue
}
Expand Down Expand Up @@ -541,13 +536,12 @@ func (s vulcanitoService) detectAssets(ctx context.Context, asset api.Asset) ([]
for _, a := range assets {
asset := asset

if !api.ValidAssetType(a.assetType) {
return nil, errors.Default("invalid asset type returned by auto-detection routine")
}

// Retrieve asset type from its name.
assetTypeObj, err := s.GetAssetType(ctx, a.assetType)
if err != nil {
if errors.IsKind(err, errors.ErrNotFound) {
return nil, errors.Default("invalid asset type returned by auto-detection routine")
}
return nil, err
}

Expand Down