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

WIP #290

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

WIP #290

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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/adevinta/vulcan-api

go 1.21.0
go 1.21.2

toolchain go1.21.5

require (
Expand Down
2 changes: 1 addition & 1 deletion pkg/asyncapi/_gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "",
"type": "module",
"dependencies": {
"@asyncapi/modelina": "^0.59.2",
"@asyncapi/modelina": "^1.0.0",
"@asyncapi/parser": "^1.15.1"
}
}
45 changes: 33 additions & 12 deletions pkg/asyncapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AssetPayload struct {
Scannable bool
AssetType *AssetType
Identifier string
Annotations []*Annotation
Annotations []interface{}
}

// Team represents a Team model.
Expand All @@ -24,21 +24,42 @@ type Team struct {
Tag string
}

// AssetType represents an enum of string.
type AssetType string
// AssetType represents an enum of AssetType.
type AssetType uint

const (
AssetTypeIp AssetType = "IP"
AssetTypeDomainName = "DomainName"
AssetTypeHostname = "Hostname"
AssetTypeAwsAccount = "AWSAccount"
AssetTypeIpRange = "IPRange"
AssetTypeDockerImage = "DockerImage"
AssetTypeWebAddress = "WebAddress"
AssetTypeGitRepository = "GitRepository"
AssetTypeGcpProject = "GCPProject"
AssetTypeIp AssetType = iota
AssetTypeDomainName
AssetTypeHostname
AssetTypeAwsAccount
AssetTypeIpRange
AssetTypeDockerImage
AssetTypeWebAddress
AssetTypeGitRepository
AssetTypeGcpProject
)

// Value returns the value of the enum.
func (op AssetType) Value() any {
if op >= AssetType(len(AssetTypeValues)) {
return nil
}
return AssetTypeValues[op]
}

var AssetTypeValues = []any{"IP", "DomainName", "Hostname", "AWSAccount", "IPRange", "DockerImage", "WebAddress", "GitRepository", "GCPProject"}
var ValuesToAssetType = map[any]AssetType{
AssetTypeValues[AssetTypeIp]: AssetTypeIp,
AssetTypeValues[AssetTypeDomainName]: AssetTypeDomainName,
AssetTypeValues[AssetTypeHostname]: AssetTypeHostname,
AssetTypeValues[AssetTypeAwsAccount]: AssetTypeAwsAccount,
AssetTypeValues[AssetTypeIpRange]: AssetTypeIpRange,
AssetTypeValues[AssetTypeDockerImage]: AssetTypeDockerImage,
AssetTypeValues[AssetTypeWebAddress]: AssetTypeWebAddress,
AssetTypeValues[AssetTypeGitRepository]: AssetTypeGitRepository,
AssetTypeValues[AssetTypeGcpProject]: AssetTypeGcpProject,
}

// Annotation represents a Annotation model.
type Annotation struct {
Key string
Expand Down
7 changes: 4 additions & 3 deletions pkg/asyncapi/vulcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (v *Vulcan) DeleteAsset(asset AssetPayload) error {

// NullVulcan implements an Async Vulcan API interface that does not send the
// events to any [EventStreamClient]. It's intended to be used when the async
// API is disabled but other components still need to fullfill a dependency
// API is disabled but other components still need to fullfil a dependency
// with the Vulcan Async Server.
type NullVulcan struct {
}
Expand All @@ -124,10 +124,11 @@ func (v *NullVulcan) PushAsset(asset AssetPayload) error {
}

func metadata(asset AssetPayload) map[string][]byte {
// The asset type can't be nil.
// The asset type can't be nil and its value is a string.
at := asset.AssetType.Value().(string)
return map[string][]byte{
"identifier": []byte(asset.Identifier),
"type": []byte(*asset.AssetType),
"type": []byte(at),
"version": []byte(Version),
}
}
4 changes: 2 additions & 2 deletions pkg/asyncapi/vulcan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var assetFixtures = map[string]AssetPayload{
"Asset1": {
Id: "Asset1",
Identifier: "example.com",
AssetType: (*AssetType)(strToPtr(AssetTypeDomainName)),
AssetType: assettypeToPtr(AssetTypeDomainName),
Team: &Team{
Id: "Team1",
Name: "Team1",
Expand Down Expand Up @@ -117,6 +117,6 @@ func mustJSONMarshal(assset AssetPayload) []byte {
return content
}

func strToPtr(v string) *string {
func assettypeToPtr(v AssetType) *AssetType {
return &v
}