Skip to content

Commit

Permalink
Merge pull request #38 from cobbler/fix/linter-issues
Browse files Browse the repository at this point in the history
Fix linter issues
  • Loading branch information
SchoolGuy authored Oct 9, 2024
2 parents be4c2bb + b64e1de commit 70cb8e0
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 106 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
lint_docs:
name: Linting Docs
runs-on: ubuntu-latest
# Only verify this on PRs
if: github.event_name == 'pull_request'
Expand Down
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ linters:
enable:
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- godot
- copyloopvar
- gofmt
- gosimple
- ineffassign
Expand Down
4 changes: 2 additions & 2 deletions cobbler/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var cobblerApiClient cobbler.Client
var testAccProviderFactories = map[string]func() (*schema.Provider, error){
"cobbler": func() (*schema.Provider, error) {
"cobbler": func() (*schema.Provider, error) { //nolint:unparam // We satisfy an interface here
return New("dev")(), nil
},
}
Expand All @@ -24,7 +24,7 @@ func init() {
})
_, _ = cobblerApiClient.Login()
testAccProviderFactories = map[string]func() (*schema.Provider, error){
"cobbler": func() (*schema.Provider, error) {
"cobbler": func() (*schema.Provider, error) { //nolint:unparam // We satisfy an interface here
return New("dev")(), nil
},
}
Expand Down
77 changes: 61 additions & 16 deletions cobbler/resource_cobbler_distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,66 @@ func resourceDistroRead(ctx context.Context, d *schema.ResourceData, meta interf
}

// Set all fields
d.Set("arch", distro.Arch)
d.Set("breed", distro.Breed)
d.Set("boot_files", distro.BootFiles)
d.Set("boot_loaders", distro.BootLoaders)
d.Set("comment", distro.Comment)
d.Set("fetchable_files", distro.FetchableFiles)
d.Set("initrd", distro.Initrd)
d.Set("kernel", distro.Kernel)
d.Set("kernel_options", distro.KernelOptions)
d.Set("kernel_options_post", distro.KernelOptionsPost)
d.Set("initrd", distro.Initrd)
d.Set("mgmt_classes", distro.MGMTClasses)
d.Set("os_version", distro.OSVersion)
d.Set("owners", distro.Owners)
d.Set("template_files", distro.TemplateFiles)
err = d.Set("arch", distro.Arch)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("breed", distro.Breed)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("boot_files", distro.BootFiles)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("boot_loaders", distro.BootLoaders)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("comment", distro.Comment)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("fetchable_files", distro.FetchableFiles)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("initrd", distro.Initrd)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("kernel", distro.Kernel)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("kernel_options", distro.KernelOptions)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("kernel_options_post", distro.KernelOptionsPost)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("initrd", distro.Initrd)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("mgmt_classes", distro.MGMTClasses)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("os_version", distro.OSVersion)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("owners", distro.Owners)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("template_files", distro.TemplateFiles)
if err != nil {
return diag.FromErr(err)
}

return nil
}
Expand Down Expand Up @@ -199,7 +244,7 @@ func resourceDistroDelete(ctx context.Context, d *schema.ResourceData, meta inte
}

// buildDistro builds a cobbler.Distro from the Terraform attributes.
func buildDistro(d *schema.ResourceData, meta interface{}) cobbler.Distro {
func buildDistro(d *schema.ResourceData, meta interface{}) cobbler.Distro { //nolint:unparam // We satisfy our own pattern here
mgmtClasses := []string{}
for _, i := range d.Get("mgmt_classes").([]interface{}) {
mgmtClasses = append(mgmtClasses, i.(string))
Expand Down
2 changes: 1 addition & 1 deletion cobbler/resource_cobbler_distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func testAccCobblerCheckDistroDestroy(s *terraform.State) error {
return nil
}

func testAccCobblerCheckDistroExists(n string, distro *cobbler.Distro) resource.TestCheckFunc {
func testAccCobblerCheckDistroExists(n string, distro *cobbler.Distro) resource.TestCheckFunc { //nolint:unparam
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand Down
152 changes: 121 additions & 31 deletions cobbler/resource_cobbler_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,36 +253,126 @@ func resourceProfileRead(ctx context.Context, d *schema.ResourceData, meta inter
}

// Set all fields
d.Set("autoinstall", profile.Autoinstall)
d.Set("autoinstall_meta", profile.AutoinstallMeta)
d.Set("boot_files", profile.BootFiles)
d.Set("comment", profile.Comment)
d.Set("dhcp_tag", profile.DHCPTag)
d.Set("distro", profile.Distro)
d.Set("enable_gpxe", profile.EnableGPXE)
d.Set("enable_menu", profile.EnableMenu)
d.Set("fetchable_files", profile.FetchableFiles)
d.Set("kernel_options", profile.KernelOptions)
d.Set("kernel_options_post", profile.KernelOptionsPost)
d.Set("mgmt_classes", profile.MGMTClasses)
d.Set("mgmt_parameters", profile.MGMTParameters)
d.Set("name", profile.Name)
d.Set("name_servers_search", profile.NameServersSearch)
d.Set("name_servers", profile.NameServers)
d.Set("next_server_v4", profile.NextServerv4)
d.Set("next_server_v6", profile.NextServerv6)
d.Set("owners", profile.Owners)
d.Set("proxy", profile.Proxy)
d.Set("repos", profile.Repos)
d.Set("template_files", profile.TemplateFiles)
d.Set("virt_auto_boot", profile.VirtAutoBoot)
d.Set("virt_bridge", profile.VirtBridge)
d.Set("virt_cpus", profile.VirtCPUs)
d.Set("virt_disk_driver", profile.VirtDiskDriver)
d.Set("virt_file_size", profile.VirtFileSize)
d.Set("virt_path", profile.VirtPath)
d.Set("virt_ram", profile.VirtRAM)
d.Set("virt_type", profile.VirtType)
err = d.Set("autoinstall", profile.Autoinstall)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("autoinstall_meta", profile.AutoinstallMeta)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("boot_files", profile.BootFiles)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("comment", profile.Comment)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("dhcp_tag", profile.DHCPTag)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("distro", profile.Distro)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("enable_gpxe", profile.EnableGPXE)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("enable_menu", profile.EnableMenu)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("fetchable_files", profile.FetchableFiles)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("kernel_options", profile.KernelOptions)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("kernel_options_post", profile.KernelOptionsPost)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("mgmt_classes", profile.MGMTClasses)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("mgmt_parameters", profile.MGMTParameters)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("name", profile.Name)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("name_servers_search", profile.NameServersSearch)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("name_servers", profile.NameServers)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("next_server_v4", profile.NextServerv4)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("next_server_v6", profile.NextServerv6)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("owners", profile.Owners)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("proxy", profile.Proxy)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("repos", profile.Repos)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("template_files", profile.TemplateFiles)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_auto_boot", profile.VirtAutoBoot)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_bridge", profile.VirtBridge)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_cpus", profile.VirtCPUs)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_disk_driver", profile.VirtDiskDriver)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_file_size", profile.VirtFileSize)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_path", profile.VirtPath)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_ram", profile.VirtRAM)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("virt_type", profile.VirtType)
if err != nil {
return diag.FromErr(err)
}

return nil
}
Expand Down Expand Up @@ -318,7 +408,7 @@ func resourceProfileDelete(ctx context.Context, d *schema.ResourceData, meta int
}

// buildProfile builds a cobblerclient.Profile out of the Terraform attributes.
func buildProfile(d *schema.ResourceData, meta interface{}) cobbler.Profile {
func buildProfile(d *schema.ResourceData, meta interface{}) cobbler.Profile { //nolint:unparam // We satisfy our own pattern here
mgmtClasses := []string{}
for _, i := range d.Get("mgmt_classes").([]interface{}) {
mgmtClasses = append(mgmtClasses, i.(string))
Expand Down
2 changes: 1 addition & 1 deletion cobbler/resource_cobbler_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func testAccCobblerCheckProfileDestroy(s *terraform.State) error {
return nil
}

func testAccCobblerCheckProfileExists(n string, profile *cobbler.Profile) resource.TestCheckFunc {
func testAccCobblerCheckProfileExists(n string, profile *cobbler.Profile) resource.TestCheckFunc { //nolint:unparam
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand Down
47 changes: 37 additions & 10 deletions cobbler/resource_cobbler_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,42 @@ func resourceRepoRead(ctx context.Context, d *schema.ResourceData, meta interfac
}

// Set all fields
d.Set("arch", repo.Arch)
d.Set("breed", repo.Breed)
d.Set("comment", repo.Comment)
d.Set("createrepo_flags", repo.CreateRepoFlags)
d.Set("keep_updated", repo.KeepUpdated)
d.Set("mirror", repo.Mirror)
d.Set("mirror_locally", repo.MirrorLocally)
d.Set("name", repo.Name)
d.Set("proxy", repo.Proxy)
err = d.Set("arch", repo.Arch)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("breed", repo.Breed)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("comment", repo.Comment)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("createrepo_flags", repo.CreateRepoFlags)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("keep_updated", repo.KeepUpdated)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("mirror", repo.Mirror)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("mirror_locally", repo.MirrorLocally)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("name", repo.Name)
if err != nil {
return diag.FromErr(err)
}
err = d.Set("proxy", repo.Proxy)
if err != nil {
return diag.FromErr(err)
}

err = d.Set("apt_components", repo.AptComponents)
if err != nil {
Expand Down Expand Up @@ -211,7 +238,7 @@ func resourceRepoDelete(ctx context.Context, d *schema.ResourceData, meta interf
}

// buildRepo builds a cobbler.Repo from the Terraform attributes.
func buildRepo(d *schema.ResourceData, meta interface{}) cobbler.Repo {
func buildRepo(d *schema.ResourceData, meta interface{}) cobbler.Repo { //nolint:unparam // We satisfy our own pattern here
aptComponents := []string{}
for _, i := range d.Get("apt_components").([]interface{}) {
aptComponents = append(aptComponents, i.(string))
Expand Down
Loading

0 comments on commit 70cb8e0

Please sign in to comment.