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

Develop #30

Merged
merged 4 commits into from
Feb 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ issues:
linters:
enable:
- revive
# - gocyclo # TODO: enable in future
- gocyclo
# - dupl # TODO: enable in future
# - errorlint # TODO: enable in future
# - gocognit # TODO: enable in future
Expand Down
58 changes: 40 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ Example configuration can be found [here](#example-config).

### Source

| Parameter | Description | Source Type | Type | Possible values | Default | Required |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------- | -------- | --------------------- | ---------- | -------- |
| `source.name` | Name of the data source. | all | str | any | "" | Yes |
| `source.type` | Data source type | all | str | [ovirt, vmware, dnac] | "" | Yes |
| `source.hostname` | Hostname of the data source | all | str | any | "" | Yes |
| `source.port` | Port of the data source | all | int | 0-65536 | 443 | No |
| `source.username` | Username of the data source account. | all | str | any | "" | Yes |
| `source.password` | Password of the data source account. | all | str | any | "" | Yes |
| `source.validateCert` | Enforce TLS certificate validation. | all | bool | [true, false] | false | No |
| `source.tagColor` | TagColor for the source tag. | all | string | any | Predefined | No |
| `source.hostSiteRelations` | Regex relations in format `regex = siteName`, that map each host that satisfies regex to site. | [vmware, ovirt] | []string | any | [] | No |
| `source.clusterSiteRelations` | Regex relations in format `regex = siteName`, that map each cluster that satisfies regex to site. | [vmware, ovirt] | []string | any | [] | No |
| `source.clusterTenantRelations` | Regex relations in format `regex = tenantName`, that map each cluster that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.hostTenantRelations` | Regex relations in format `regex = tenantName`, that map each host that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.vmTenantRelations` | Regex relations in format `regex = tenantName`, that map each vm that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.vlanGroupRelations` | Regex relations in format `regex = vlanGroup`, that map each vlan that satisfies regex to vlanGroup. | all | []string | any | [] | No |
| `source.vlanTenantRelations` | Regex relations in format `regex = tenantName`, that map each vlan that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.customFieldMappings` | Mappings of format `customFieldName = option`. Currently, supported options are `contact`, `owner`, `description`. | [vmware ] | []string | any | [] | No |
| Parameter | Description | Source Type | Type | Possible values | Default | Required |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------- | -------- | --------------------- | ---------- | -------- |
| `source.name` | Name of the data source. | all | str | any | "" | Yes |
| `source.type` | Data source type | all | str | [ovirt, vmware, dnac] | "" | Yes |
| `source.hostname` | Hostname of the data source | all | str | any | "" | Yes |
| `source.port` | Port of the data source | all | int | 0-65536 | 443 | No |
| `source.username` | Username of the data source account. | all | str | any | "" | Yes |
| `source.password` | Password of the data source account. | all | str | any | "" | Yes |
| `source.validateCert` | Enforce TLS certificate validation. | all | bool | [true, false] | false | No |
| `source.tagColor` | TagColor for the source tag. | all | string | any | Predefined | No |
| `source.hostSiteRelations` | Regex relations in format `regex = siteName`, that map each host that satisfies regex to site. | [vmware, ovirt] | []string | any | [] | No |
| `source.clusterSiteRelations` | Regex relations in format `regex = siteName`, that map each cluster that satisfies regex to site. | [vmware, ovirt] | []string | any | [] | No |
| `source.clusterTenantRelations` | Regex relations in format `regex = tenantName`, that map each cluster that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.hostTenantRelations` | Regex relations in format `regex = tenantName`, that map each host that satisfies regex to tenant. | [vmware, ovirt, dnac] | []string | any | [] | No |
| `source.vmTenantRelations` | Regex relations in format `regex = tenantName`, that map each vm that satisfies regex to tenant. | [vmware, ovirt] | []string | any | [] | No |
| `source.vlanGroupRelations` | Regex relations in format `regex = vlanGroup`, that map each vlan that satisfies regex to vlanGroup. | all | []string | any | [] | No |
| `source.vlanTenantRelations` | Regex relations in format `regex = tenantName`, that map each vlan that satisfies regex to tenant. | [vmware, ovirt, dnac] | []string | any | [] | No |
| `source.customFieldMappings` | Mappings of format `customFieldName = option`. Currently, supported options are `contact`, `owner`, `description`. | [vmware ] | []string | any | [] | No |

### Example config

Expand Down Expand Up @@ -98,12 +98,34 @@ source:
hostname: vcenter.example.com
username: user
password: "top_secret"
clusterSiteRelations: # regex (https://pkg.go.dev/regexp/syntax) cluster name to Site name
- .* = ExampleSite
hostSiteRelations: # regex (https://pkg.go.dev/regexp/syntax) host name to Site name
- .*_NYC = New York
- nyc.* = New York
customFieldMappings: # Here we define map of our custom field names, to 3 option [email, owner, description]
- Mail = email
- Creator = owner
- Description = description

- name: testvmare
type: vmware
hostname: vcenter-test.example.com
username: user
password: passw0rd
customFieldMappings: # Here we define map of our custom field names, to 3 option [email, owner, description]
- Email = email
- Maintainer = owner
- Notes = description


- name: dnacenter
type: dnac
hostname: dnac.example.com
username: user
password: "pa$$w0rd"
vlanTenantRelations: # regex Vlan name to Tenant name
- .* = MyTenant
```


Expand Down
78 changes: 43 additions & 35 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,47 +204,55 @@ func validateSourceConfig(config *Config) error {
default:
return fmt.Errorf("%s.type is not valid", externalSourceStr)
}
if len(externalSource.HostSiteRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.HostSiteRelations)
if err != nil {
return fmt.Errorf("%s.hostSiteRelations: %s", externalSourceStr, err)
}
err := validateSourceConfigRelations(externalSource, externalSourceStr)
if err != nil {
return err
}
if len(externalSource.ClusterSiteRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.ClusterSiteRelations)
if err != nil {
return fmt.Errorf("%s.clusterSiteRelations: %s", externalSourceStr, err)
}
}
return nil
}

func validateSourceConfigRelations(externalSource *SourceConfig, externalSourceStr string) error {
if len(externalSource.HostSiteRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.HostSiteRelations)
if err != nil {
return fmt.Errorf("%s.hostSiteRelations: %s", externalSourceStr, err)
}
if len(externalSource.ClusterTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.ClusterTenantRelations)
if err != nil {
return fmt.Errorf("%s.clusterTenantRelations: %s", externalSourceStr, err)
}
}
if len(externalSource.ClusterSiteRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.ClusterSiteRelations)
if err != nil {
return fmt.Errorf("%s.clusterSiteRelations: %s", externalSourceStr, err)
}
if len(externalSource.HostTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.HostTenantRelations)
if err != nil {
return fmt.Errorf("%s.hostTenantRelations: %s", externalSourceStr, err)
}
}
if len(externalSource.ClusterTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.ClusterTenantRelations)
if err != nil {
return fmt.Errorf("%s.clusterTenantRelations: %s", externalSourceStr, err)
}
if len(externalSource.VMTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.VMTenantRelations)
if err != nil {
return fmt.Errorf("%s.vmTenantRelations: %s", externalSourceStr, err)
}
}
if len(externalSource.HostTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.HostTenantRelations)
if err != nil {
return fmt.Errorf("%s.hostTenantRelations: %s", externalSourceStr, err)
}
if len(externalSource.VlanGroupRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.VlanGroupRelations)
if err != nil {
return fmt.Errorf("%s.vlanGroupRelations: %v", externalSourceStr, err)
}
}
if len(externalSource.VMTenantRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.VMTenantRelations)
if err != nil {
return fmt.Errorf("%s.vmTenantRelations: %s", externalSourceStr, err)
}
if len(externalSource.VlanTenantRelations) > 0 {
err := utils.ValidateRegexRelations((externalSource.VlanTenantRelations))
if err != nil {
return fmt.Errorf("%s.vlanTenantRelations: %v", externalSourceStr, err)
}
}
if len(externalSource.VlanGroupRelations) > 0 {
err := utils.ValidateRegexRelations(externalSource.VlanGroupRelations)
if err != nil {
return fmt.Errorf("%s.vlanGroupRelations: %v", externalSourceStr, err)
}
}
if len(externalSource.VlanTenantRelations) > 0 {
err := utils.ValidateRegexRelations((externalSource.VlanTenantRelations))
if err != nil {
return fmt.Errorf("%s.vlanTenantRelations: %v", externalSourceStr, err)
}
}
return nil
Expand Down
Loading
Loading