diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..87fdf72 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# See GitHub's documentation for more information on this file: +# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..45f7517 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +# Terraform Provider release workflow. +name: Release + +# This GitHub action creates a release when a tag that matches the pattern +# "v*" (e.g. v0.1.0) is created. +on: + push: + tags: + - 'v*' + +# Releases need permissions to read and write the repository contents. +# GitHub considers creating releases and uploading assets as writing contents. +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # Allow goreleaser to access older tag information. + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + cache: true + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 + id: import_gpg + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + args: release --rm-dist + env: + # GitHub sets the GITHUB_TOKEN secret automatically. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c486ebd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,65 @@ +# gomaasclient testing workflow. +name: Tests + +# This GitHub action runs your tests for each pull request and push. +# Optionally, you can turn it on using a schedule for regular testing. +on: + pull_request: + paths-ignore: + - 'README.md' + push: + branches: + - "master" + paths-ignore: + - 'README.md' + +# Testing only needs permissions to read the repository contents. +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55 + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + skip-cache: true + install-mode: binary + + # Ensure project builds before running testing matrix + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + cache: true + - run: go mod download + - run: go build -v . + + # Run unit tests + test: + name: gomaasclient Unit Tests + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + cache: true + - run: make test diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..8d4ad72 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,239 @@ +# This file contains all available configuration options +# https://golangci-lint.run/usage/linters/ + +run: + timeout: 5m + issues-exit-code: 1 + tests: true + # Enables skipping of directories: + # - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + + # Which files to skip: they will be analyzed, but issues from them won't be reported. + # Default value is empty list, + # but there is no need to include all autogenerated files, + # we confidently recognize autogenerated files. + # If it's not please let us know. + # "/" will be replaced by current OS file path separator to properly work on Windows. + skip-files: + - ".*\\.my\\.go$" + - lib/bad.go + + # If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # + # Allowed values: readonly|vendor|mod + # By default, it isn't set. + modules-download-mode: readonly + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: false + +# output configuration options +output: + # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity + # + # Multiple can be specified by separating them by comma, output can be provided + # for each of them by separating format name and path by colon symbol. + # Output path can be either `stdout`, `stderr` or path to the file to write to. + # Example: "checkstyle:report.xml,json:stdout,colored-line-number" + # + # Default: colored-line-number + format: colored-line-number + + # Print lines of code with issue. + # Default: true + print-issued-lines: true + + # Print linter name in the end of issue text. + # Default: true + print-linter-name: true + + # Make issues output unique by line. + # Default: true + uniq-by-line: true + + # Add a prefix to the output file references. + # Default is no prefix. + path-prefix: "" + + # Sort results by: filepath, line and column. + sort-results: false + +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - gocritic + - gofmt + - goimports + - gosec + - gosimple + - govet + - nilerr + - nilnil + - noctx + - nolintlint + - nonamedreturns + - revive + - staticcheck + - stylecheck + - tagliatelle + - unused + - whitespace + - wsl + - zerologlint + +linters-settings: + errcheck: + check-type-assertions: true + check-blank: true + gosimple: + checks: ["all"] + govet: + enable-all: true + nolintlint: + require-explanation: true + require-specific: true + revive: + ignore-generated-header: true + rules: + - name: time-equal + severity: warning + disabled: false + - name: errorf + severity: warning + disabled: false + - name: context-as-argument + severity: warning + disabled: false + - name: error-return + severity: warning + disabled: false + - name: datarace + severity: warning + disabled: false + staticcheck: + checks: ["all"] + stylecheck: + checks: ["all"] + tagliatelle: + case: + rules: + json: snake + yaml: snake + +issues: + # List of regexps of issue texts to exclude. + # + # But independently of this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. + # To list all excluded by default patterns execute `golangci-lint run --help` + # + # Default: https://golangci-lint.run/usage/false-positives/#default-exclusions + exclude: [] + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via `nolint` comments. + # `/` will be replaced by current OS file path separator to properly work on Windows. + + # Exclude `lll` issues for long lines with `go:generate`. + - linters: + - lll + source: "^//go:generate " + + - path: internal/ + text: "ST1000:" + linters: + - stylecheck + + - path: internal/ + text: "package-comments:" + linters: + - revive + + - path: internal/ + text: "exported:" + linters: + - revive + + - path: main\.go + text: "package-comments:" + linters: + - revive + + - path: _test\.go + text: "fieldalignment:" + linters: + - govet + # Independently of option `exclude` we use default exclude patterns, + # it can be disabled by this option. + # To list all excluded by default patterns execute `golangci-lint run --help`. + # Default: true. + exclude-use-default: false + + # If set to true exclude and exclude-rules regular expressions become case-sensitive. + # Default: false + exclude-case-sensitive: false + + max-same-issues: 0 + + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing large codebase. + # It's not practical to fix all existing issues at the moment of integration: + # much better don't allow issues in new code. + # + # Default: false. + new: false + + # Fix found issues (if it's supported by the linter). + fix: false + +severity: + # Set the default severity for issues. + # + # If severity rules are defined and the issues do not match or no severity is provided to the rule + # this will be the default severity applied. + # Severities should match the supported severity names of the selected out format. + # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity + # - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#SeverityLevel + # - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message + # - TeamCity: https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance + # + # Default value is an empty string. + default-severity: error + + # If set to true `severity-rules` regular expressions become case-sensitive. + # Default: false + case-sensitive: true + + # When a list of severity rules are provided, severity information will be added to lint issues. + # Severity rules have the same filtering capability as exclude rules + # except you are allowed to specify one matcher per severity rule. + # Only affects out formats that support setting severity information. + # + # Default: [] + rules: + - linters: + - dupl + severity: info diff --git a/Makefile b/Makefile index a8c342b..db3117c 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,14 @@ TEST?=$$(go list ./... | grep -v 'vendor') .PHONY: test test: go test $(TEST) -v $(TESTARGS) -timeout=5m -parallel=4 + +.PHONY: lint +lint: lint-go + +.PHONY: lint-go +lint-go: + golangci-lint run $(if $(LINT_AUTOFIX),--fix,) ./... + +.PHONY: lint-go-fix +lint-go-fix: LINT_AUTOFIX=true +lint-go-fix: lint-go diff --git a/api/api.go b/api/api.go index 6e3fb98..03ecde1 100644 --- a/api/api.go +++ b/api/api.go @@ -1,13 +1,15 @@ -/*Package api defines an interface to each MaaS API endpoint. +/* +Package api defines an interface to each MAAS API endpoint. Each interface correlates to one endpoint, such as Subnets for the Subnets endpoint (ie /subnets) and Subnet for the Subnet endpoint (eg subnets/). API clients are expected to implement these interfaces to provide a normalized way -of accessing the MaaS API with normalized results (eg the types defined in the +of accessing the MAAS API with normalized results (eg the types defined in the endpoint package). Some endpoint operations require multiple parameters, such as the Rack Controllers GET operation, which takes a number of QSP that can be used to filter results. These parameters are encapsulated in the params subpackage, providing a quick reference -for performing API operations.*/ +for performing API operations. +*/ package api diff --git a/api/maas_server.go b/api/maas_server.go index 20a7c82..514bcad 100644 --- a/api/maas_server.go +++ b/api/maas_server.go @@ -1,6 +1,6 @@ package api -// MAASServer represents the MaaS Server endpoint for changing global configuration settings +// MAASServer represents the MAAS Server endpoint for changing global configuration settings type MAASServer interface { Get(name string) (value string, err error) Post(name, value string) error diff --git a/api/network_interface.go b/api/network_interface.go index f9812fe..cc7da42 100644 --- a/api/network_interface.go +++ b/api/network_interface.go @@ -4,7 +4,7 @@ import ( "github.com/maas/gomaasclient/entity" ) -// NetworkInterface represents the MaaS Server Interface endpoint +// NetworkInterface represents the MAAS Server Interface endpoint type NetworkInterface interface { Get(systemID string, id int) (*entity.NetworkInterface, error) Update(systemID string, id int, params *entity.NetworkInterfaceUpdateParams) (*entity.NetworkInterface, error) diff --git a/api/network_interfaces.go b/api/network_interfaces.go index 2c7615c..7751045 100644 --- a/api/network_interfaces.go +++ b/api/network_interfaces.go @@ -4,7 +4,7 @@ import ( "github.com/maas/gomaasclient/entity" ) -// NetworkInterfaces represents the MaaS Server Interfaces endpoint +// NetworkInterfaces represents the MAAS Server Interfaces endpoint type NetworkInterfaces interface { Get(systemID string) ([]entity.NetworkInterface, error) CreateBond(systemID string, params *entity.NetworkInterfaceBondParams) (*entity.NetworkInterface, error) diff --git a/api/rack_controllers.go b/api/rack_controllers.go index 86622ca..babac8b 100644 --- a/api/rack_controllers.go +++ b/api/rack_controllers.go @@ -4,7 +4,7 @@ import ( "github.com/maas/gomaasclient/entity" ) -// RackControllers represents the MaaS Rack Controllers endpoint +// RackControllers represents the MAAS Rack Controllers endpoint type RackControllers interface { Get(*entity.RackControllerSearch) ([]entity.RackController, error) } diff --git a/api/subnet.go b/api/subnet.go index 0d304af..181aa56 100644 --- a/api/subnet.go +++ b/api/subnet.go @@ -5,7 +5,7 @@ import ( "github.com/maas/gomaasclient/entity/subnet" ) -// Subnet represents the MaaS Subnet endpoint +// Subnet represents the MAAS Subnet endpoint type Subnet interface { Delete(id int) error Get(id int) (*entity.Subnet, error) diff --git a/api/subnets.go b/api/subnets.go index 002cee0..ce15319 100644 --- a/api/subnets.go +++ b/api/subnets.go @@ -4,7 +4,7 @@ import ( "github.com/maas/gomaasclient/entity" ) -// Subnets represents the MaaS Subnets endpoint +// Subnets represents the MAAS Subnets endpoint type Subnets interface { Get() ([]entity.Subnet, error) Create(params *entity.SubnetParams) (*entity.Subnet, error) diff --git a/api/vlans.go b/api/vlans.go index 6f983f3..cc322fd 100644 --- a/api/vlans.go +++ b/api/vlans.go @@ -4,7 +4,7 @@ import ( "github.com/maas/gomaasclient/entity" ) -// VLANs represents the MaaS Vlans endpoint +// VLANs represents the MAAS Vlans endpoint type VLANs interface { Get(fabricID int) ([]entity.VLAN, error) Create(fabricID int, params *entity.VLANParams) (*entity.VLAN, error) diff --git a/client/block_device.go b/client/block_device.go index 5a316df..f0289a7 100644 --- a/client/block_device.go +++ b/client/block_device.go @@ -11,33 +11,36 @@ import ( // BlockDevice implements the api.BlockDevice interface type BlockDevice struct { - ApiClient ApiClient + APIClient APIClient } -func (b *BlockDevice) client(systemID string, id int) ApiClient { - return b.ApiClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("blockdevices").GetSubObject(fmt.Sprintf("%v", id)) +func (b *BlockDevice) client(systemID string, id int) APIClient { + return b.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("blockdevices").GetSubObject(fmt.Sprintf("%v", id)) } // Get fetches a given BlockDevice based on the given Node's system_id and BlockDevice's id -func (b *BlockDevice) Get(systemID string, id int) (blockDevice *entity.BlockDevice, err error) { - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Get("", url.Values{}, func(data []byte) error { +func (b *BlockDevice) Get(systemID string, id int) (*entity.BlockDevice, error) { + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Update updates a given BlockDevice -func (b *BlockDevice) Update(systemID string, id int, params *entity.BlockDeviceParams) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevice) Update(systemID string, id int, params *entity.BlockDeviceParams) (*entity.BlockDevice, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - blockDevice = new(entity.BlockDevice) + + blockDevice := new(entity.BlockDevice) err = b.client(systemID, id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Delete deletes a given BlockDevice @@ -46,66 +49,76 @@ func (b *BlockDevice) Delete(systemID string, id int) error { } // AddTag adds a tag to a given BlockDevice -func (b *BlockDevice) AddTag(systemID string, id int, tag string) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevice) AddTag(systemID string, id int, tag string) (*entity.BlockDevice, error) { qsp := url.Values{} qsp.Set("tag", tag) - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("add_tag", qsp, func(data []byte) error { + + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("add_tag", qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // RemoveTag removes a tag from a given BlockDevice -func (b *BlockDevice) RemoveTag(systemID string, id int, tag string) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevice) RemoveTag(systemID string, id int, tag string) (*entity.BlockDevice, error) { qsp := url.Values{} qsp.Set("tag", tag) - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("remove_tag", qsp, func(data []byte) error { + + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("remove_tag", qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Format configures a BlockDevice to be formatted for a new file system -func (b *BlockDevice) Format(systemID string, id int, fsType string) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevice) Format(systemID string, id int, fsType string) (*entity.BlockDevice, error) { qsp := url.Values{} qsp.Set("fstype", fsType) - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("format", qsp, func(data []byte) error { + + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("format", qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Unformat removes the configured file system -func (b *BlockDevice) Unformat(systemID string, id int) (blockDevice *entity.BlockDevice, err error) { - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("unformat", url.Values{}, func(data []byte) error { +func (b *BlockDevice) Unformat(systemID string, id int) (*entity.BlockDevice, error) { + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("unformat", url.Values{}, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Mount sets the mount point and options of a given BlockDevice -func (b *BlockDevice) Mount(systemID string, id int, mountPoint string, mountOptions string) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevice) Mount(systemID string, id int, mountPoint string, mountOptions string) (*entity.BlockDevice, error) { qsp := url.Values{} qsp.Set("mount_point", mountPoint) qsp.Set("mount_options", mountOptions) - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("mount", qsp, func(data []byte) error { + + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("mount", qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // Unmount unsets the mount of a BlockDevice -func (b *BlockDevice) Unmount(systemID string, id int) (blockDevice *entity.BlockDevice, err error) { - blockDevice = new(entity.BlockDevice) - err = b.client(systemID, id).Post("unmount", url.Values{}, func(data []byte) error { +func (b *BlockDevice) Unmount(systemID string, id int) (*entity.BlockDevice, error) { + blockDevice := new(entity.BlockDevice) + err := b.client(systemID, id).Post("unmount", url.Values{}, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } // SetBootDisk configures the given BlockDevice as the boot disk diff --git a/client/block_device_partition.go b/client/block_device_partition.go index aa8a990..020cf7f 100644 --- a/client/block_device_partition.go +++ b/client/block_device_partition.go @@ -12,36 +12,41 @@ import ( // BlockDevicePartition implements the api.BlockDevicePartition // interface type BlockDevicePartition struct { - ApiClient ApiClient + APIClient APIClient } -func (p *BlockDevicePartition) client(systemID string, blockDeviceID int, id int) (*ApiClient, error) { - uri := p.ApiClient.URI() +func (p *BlockDevicePartition) client(systemID string, blockDeviceID int, id int) (*APIClient, error) { + uri := p.APIClient.URI() newURL := url.URL{Path: fmt.Sprintf("nodes/%s/blockdevices/%v/partition/%v", systemID, blockDeviceID, id)} - resUrl := uri.ResolveReference(&newURL) - input := map[string]interface{}{"resource_uri": resUrl.String()} - jsonObj, err := gomaasapi.JSONObjectFromStruct(p.ApiClient.AuthClient, input) + resURL := uri.ResolveReference(&newURL) + input := map[string]interface{}{"resource_uri": resURL.String()} + + jsonObj, err := gomaasapi.JSONObjectFromStruct(p.APIClient.AuthClient, input) if err != nil { return nil, err } + maasObj, err := jsonObj.GetMAASObject() if err != nil { return nil, err } - return &ApiClient{p.ApiClient.AuthClient, &maasObj}, nil + + return &APIClient{p.APIClient.AuthClient, &maasObj}, nil } // Get fetches a given BlockDevicePartion for a given system_id, BlockDevice id and partition id -func (p *BlockDevicePartition) Get(systemID string, blockDeviceID int, id int) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) Get(systemID string, blockDeviceID int, id int) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // Delete deletes a given BlockDevicePartition @@ -50,93 +55,110 @@ func (p *BlockDevicePartition) Delete(systemID string, blockDeviceID int, id int if err != nil { return err } + return client.Delete() } // AddTag adds a tag to a given BlockDevicePartition -func (p *BlockDevicePartition) AddTag(systemID string, blockDeviceID int, id int, tag string) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) AddTag(systemID string, blockDeviceID int, id int, tag string) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } + qsp := url.Values{} qsp.Set("tag", tag) - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("add_tag", qsp, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // RemoveTag removes a tag from a given BlockDevicePartition -func (p *BlockDevicePartition) RemoveTag(systemID string, blockDeviceID int, id int, tag string) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) RemoveTag(systemID string, blockDeviceID int, id int, tag string) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } + qsp := url.Values{} qsp.Set("tag", tag) - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("remove_tag", qsp, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // Format sets the BlockDevicePartition to be formatted with a given file system -func (p *BlockDevicePartition) Format(systemID string, blockDeviceID int, id int, fsType string, label string) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) Format(systemID string, blockDeviceID int, id int, fsType string, label string) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } + qsp := url.Values{} qsp.Set("fstype", fsType) qsp.Set("label", label) - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("format", qsp, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // Unformat unsets a file system for a given BlockDevicePartition -func (p *BlockDevicePartition) Unformat(systemID string, blockDeviceID int, id int) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) Unformat(systemID string, blockDeviceID int, id int) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("unformat", url.Values{}, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // Mount sets a mount point and options for a given BlockDevicePartition -func (p *BlockDevicePartition) Mount(systemID string, blockDeviceID int, id int, mountPoint string, mountOptions string) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) Mount(systemID string, blockDeviceID int, id int, mountPoint string, mountOptions string) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } + qsp := url.Values{} qsp.Set("mount_point", mountPoint) qsp.Set("mount_options", mountOptions) - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("mount", qsp, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } // Unmount unsets a mount point for a given BlockDevicePartition -func (p *BlockDevicePartition) Unmount(systemID string, blockDeviceID int, id int) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartition) Unmount(systemID string, blockDeviceID int, id int) (*entity.BlockDevicePartition, error) { client, err := p.client(systemID, blockDeviceID, id) if err != nil { - return + return nil, err } - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = client.Post("unmount", url.Values{}, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } diff --git a/client/block_device_partitions.go b/client/block_device_partitions.go index e3aa006..7d0ebfe 100644 --- a/client/block_device_partitions.go +++ b/client/block_device_partitions.go @@ -11,30 +11,34 @@ import ( // BlockDevicePartitions implements api.BlockDevicePartitions type BlockDevicePartitions struct { - ApiClient ApiClient + APIClient APIClient } -func (p *BlockDevicePartitions) client(systemID string, blockDeviceID int) ApiClient { - return p.ApiClient.GetSubObject(fmt.Sprintf("nodes/%s/blockdevices/%v/partitions", systemID, blockDeviceID)) +func (p *BlockDevicePartitions) client(systemID string, blockDeviceID int) APIClient { + return p.APIClient.GetSubObject(fmt.Sprintf("nodes/%s/blockdevices/%v/partitions", systemID, blockDeviceID)) } // Get lists the BlockDevicePartition objects for a given system_id and BlockDevice id -func (p *BlockDevicePartitions) Get(systemID string, blockDeviceID int) (partitions []entity.BlockDevicePartition, err error) { - err = p.client(systemID, blockDeviceID).Get("", url.Values{}, func(data []byte) error { +func (p *BlockDevicePartitions) Get(systemID string, blockDeviceID int) ([]entity.BlockDevicePartition, error) { + partitions := make([]entity.BlockDevicePartition, 0) + err := p.client(systemID, blockDeviceID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &partitions) }) - return + + return partitions, err } // Create creats a new BlockDevicePartition for a given system_id and BlockDevice id -func (p *BlockDevicePartitions) Create(systemID string, blockDeviceID int, params *entity.BlockDevicePartitionParams) (partition *entity.BlockDevicePartition, err error) { +func (p *BlockDevicePartitions) Create(systemID string, blockDeviceID int, params *entity.BlockDevicePartitionParams) (*entity.BlockDevicePartition, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - partition = new(entity.BlockDevicePartition) + + partition := new(entity.BlockDevicePartition) err = p.client(systemID, blockDeviceID).Post("", qsp, func(data []byte) error { return json.Unmarshal(data, partition) }) - return + + return partition, err } diff --git a/client/block_devices.go b/client/block_devices.go index a935f17..fcdde72 100644 --- a/client/block_devices.go +++ b/client/block_devices.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // BlockDevices implements api.BlockDevices type BlockDevices struct { - ApiClient ApiClient + APIClient APIClient } -func (b *BlockDevices) client(systemID string) ApiClient { - return b.ApiClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("blockdevices") +func (b *BlockDevices) client(systemID string) APIClient { + return b.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("blockdevices") } // Get fetches a list of BlockDevices for a given system_id -func (b *BlockDevices) Get(systemID string) (blockDevices []entity.BlockDevice, err error) { - err = b.client(systemID).Get("", url.Values{}, func(data []byte) error { +func (b *BlockDevices) Get(systemID string) ([]entity.BlockDevice, error) { + blockDevices := make([]entity.BlockDevice, 0) + err := b.client(systemID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &blockDevices) }) - return + + return blockDevices, err } // Create creates a new BlockDevice for a given system_id -func (b *BlockDevices) Create(systemID string, params *entity.BlockDeviceParams) (blockDevice *entity.BlockDevice, err error) { +func (b *BlockDevices) Create(systemID string, params *entity.BlockDeviceParams) (*entity.BlockDevice, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - blockDevice = new(entity.BlockDevice) + + blockDevice := new(entity.BlockDevice) err = b.client(systemID).Post("", qsp, func(data []byte) error { return json.Unmarshal(data, blockDevice) }) - return + + return blockDevice, err } diff --git a/client/client.go b/client/client.go index b067c34..7b1bed8 100644 --- a/client/client.go +++ b/client/client.go @@ -1,3 +1,4 @@ +// Package client contains the implementation of CRUD operations on MAAS resources. package client import ( @@ -11,7 +12,7 @@ import ( // GetTLSClient creates a Client configured with TLS func GetTLSClient(apiURL string, apiKey string, apiVersion string, tlsConfig *tls.Config) (*Client, error) { - apiClient, err := getApiClient(apiURL, apiKey, apiVersion, tlsConfig) + apiClient, err := getAPIClient(apiURL, apiKey, apiVersion, tlsConfig) if err != nil { return nil, err } @@ -21,7 +22,7 @@ func GetTLSClient(apiURL string, apiKey string, apiVersion string, tlsConfig *tl // GetClient creates a client func GetClient(apiURL string, apiKey string, apiVersion string) (*Client, error) { - apiClient, err := getApiClient(apiURL, apiKey, apiVersion, nil) + apiClient, err := getAPIClient(apiURL, apiKey, apiVersion, nil) if err != nil { return nil, err } @@ -29,43 +30,43 @@ func GetClient(apiURL string, apiKey string, apiVersion string) (*Client, error) return constructClient(apiClient), nil } -func constructClient(apiClient *ApiClient) *Client { +func constructClient(apiClient *APIClient) *Client { client := Client{ - Device: &Device{ApiClient: *apiClient}, - Devices: &Devices{ApiClient: *apiClient}, - Domain: &Domain{ApiClient: *apiClient}, - Domains: &Domains{ApiClient: *apiClient}, - DNSResource: &DNSResource{ApiClient: *apiClient}, - DNSResources: &DNSResources{ApiClient: *apiClient}, - DNSResourceRecord: &DNSResourceRecord{ApiClient: *apiClient}, - DNSResourceRecords: &DNSResourceRecords{ApiClient: *apiClient}, - Fabric: &Fabric{ApiClient: *apiClient}, - Fabrics: &Fabrics{ApiClient: *apiClient}, - VLAN: &VLAN{ApiClient: *apiClient}, - VLANs: &VLANs{ApiClient: *apiClient}, - Space: &Space{ApiClient: *apiClient}, - Spaces: &Spaces{ApiClient: *apiClient}, - Machine: &Machine{ApiClient: *apiClient}, - Machines: &Machines{ApiClient: *apiClient}, - VMHost: &VMHost{ApiClient: *apiClient}, - VMHosts: &VMHosts{ApiClient: *apiClient}, - NetworkInterface: &NetworkInterface{ApiClient: *apiClient}, - NetworkInterfaces: &NetworkInterfaces{ApiClient: *apiClient}, - RAID: &RAID{ApiClient: *apiClient}, - RAIDs: &RAIDs{ApiClient: *apiClient}, - Subnet: &Subnet{ApiClient: *apiClient}, - Subnets: &Subnets{ApiClient: *apiClient}, - IPRange: &IPRange{ApiClient: *apiClient}, - IPRanges: &IPRanges{ApiClient: *apiClient}, - IPAddresses: &IPAddresses{ApiClient: *apiClient}, - Tag: &Tag{ApiClient: *apiClient}, - Tags: &Tags{ApiClient: *apiClient}, - BlockDevice: &BlockDevice{ApiClient: *apiClient}, - BlockDevices: &BlockDevices{ApiClient: *apiClient}, - BlockDevicePartition: &BlockDevicePartition{ApiClient: *apiClient}, - BlockDevicePartitions: &BlockDevicePartitions{ApiClient: *apiClient}, - User: &User{ApiClient: *apiClient}, - Users: &Users{ApiClient: *apiClient}, + Device: &Device{APIClient: *apiClient}, + Devices: &Devices{APIClient: *apiClient}, + Domain: &Domain{APIClient: *apiClient}, + Domains: &Domains{APIClient: *apiClient}, + DNSResource: &DNSResource{APIClient: *apiClient}, + DNSResources: &DNSResources{APIClient: *apiClient}, + DNSResourceRecord: &DNSResourceRecord{APIClient: *apiClient}, + DNSResourceRecords: &DNSResourceRecords{APIClient: *apiClient}, + Fabric: &Fabric{APIClient: *apiClient}, + Fabrics: &Fabrics{APIClient: *apiClient}, + VLAN: &VLAN{APIClient: *apiClient}, + VLANs: &VLANs{APIClient: *apiClient}, + Space: &Space{APIClient: *apiClient}, + Spaces: &Spaces{APIClient: *apiClient}, + Machine: &Machine{APIClient: *apiClient}, + Machines: &Machines{APIClient: *apiClient}, + VMHost: &VMHost{APIClient: *apiClient}, + VMHosts: &VMHosts{APIClient: *apiClient}, + NetworkInterface: &NetworkInterface{APIClient: *apiClient}, + NetworkInterfaces: &NetworkInterfaces{APIClient: *apiClient}, + RAID: &RAID{APIClient: *apiClient}, + RAIDs: &RAIDs{APIClient: *apiClient}, + Subnet: &Subnet{APIClient: *apiClient}, + Subnets: &Subnets{APIClient: *apiClient}, + IPRange: &IPRange{APIClient: *apiClient}, + IPRanges: &IPRanges{APIClient: *apiClient}, + IPAddresses: &IPAddresses{APIClient: *apiClient}, + Tag: &Tag{APIClient: *apiClient}, + Tags: &Tags{APIClient: *apiClient}, + BlockDevice: &BlockDevice{APIClient: *apiClient}, + BlockDevices: &BlockDevices{APIClient: *apiClient}, + BlockDevicePartition: &BlockDevicePartition{APIClient: *apiClient}, + BlockDevicePartitions: &BlockDevicePartitions{APIClient: *apiClient}, + User: &User{APIClient: *apiClient}, + Users: &Users{APIClient: *apiClient}, } return &client @@ -113,68 +114,79 @@ type Client struct { ResourcePools api.ResourcePools } +// GetAPIClient returns a MAAS API client. +// // Deprecated: The gomaasapi client will be no longer exposed. // Instead, please use GetClient which instantiate all MAAS resources endpoints with gomaasapi client. -func GetApiClient(apiURL string, apiKey string, apiVersion string) (*ApiClient, error) { - return getApiClient(apiURL, apiKey, apiVersion, nil) +func GetAPIClient(apiURL string, apiKey string, apiVersion string) (*APIClient, error) { + return getAPIClient(apiURL, apiKey, apiVersion, nil) } -func getApiClient(apiURL string, apiKey string, apiVersion string, tlsConfig *tls.Config) (*ApiClient, error) { +func getAPIClient(apiURL string, apiKey string, apiVersion string, tlsConfig *tls.Config) (*APIClient, error) { versionedURL := gomaasapi.AddAPIVersionToURL(apiURL, apiVersion) + authClient, err := gomaasapi.NewAuthenticatedClient(versionedURL, apiKey) if err != nil { return nil, err } + if tlsConfig != nil { tr := &http.Transport{TLSClientConfig: tlsConfig} httpClient := &http.Client{Transport: tr} authClient.HTTPClient = httpClient } - return &ApiClient{*authClient, gomaasapi.NewMAAS(*authClient)}, nil + + return &APIClient{*authClient, gomaasapi.NewMAAS(*authClient)}, nil } -type ApiClient struct { +type APIClient struct { AuthClient gomaasapi.Client *gomaasapi.MAASObject } -func (c ApiClient) Get(op string, params url.Values, f func([]byte) error) error { +func (c APIClient) Get(op string, params url.Values, f func([]byte) error) error { res, err := c.CallGet(op, params) if err != nil { return err } + data, err := res.GetBytes() if err != nil { return err } + return f(data) } -func (c ApiClient) GetSubObject(name string) ApiClient { +func (c APIClient) GetSubObject(name string) APIClient { mc := c.MAASObject.GetSubObject(name) - return ApiClient{c.AuthClient, &mc} + return APIClient{c.AuthClient, &mc} } -func (c ApiClient) Post(op string, params url.Values, f func([]byte) error) error { +func (c APIClient) Post(op string, params url.Values, f func([]byte) error) error { res, err := c.CallPost(op, params) if err != nil { return err } + data, err := res.GetBytes() if err != nil { return err } + return f(data) } -func (c ApiClient) Put(params url.Values, f func([]byte) error) error { +func (c APIClient) Put(params url.Values, f func([]byte) error) error { res, err := c.Update(params) if err != nil { return err } + data, err := res.MarshalJSON() if err != nil { return err } + return f(data) } diff --git a/client/device.go b/client/device.go index 8e90d9b..cb5437e 100644 --- a/client/device.go +++ b/client/device.go @@ -11,33 +11,36 @@ import ( // Device implements api.Device type Device struct { - ApiClient ApiClient + APIClient APIClient } -func (d *Device) client(systemID string) ApiClient { - return d.ApiClient.GetSubObject("devices").GetSubObject(fmt.Sprintf("%v", systemID)) +func (d *Device) client(systemID string) APIClient { + return d.APIClient.GetSubObject("devices").GetSubObject(fmt.Sprintf("%v", systemID)) } // Get fetches a device with a given system_id -func (d *Device) Get(systemID string) (device *entity.Device, err error) { - device = new(entity.Device) - err = d.client(systemID).Get("", url.Values{}, func(data []byte) error { +func (d *Device) Get(systemID string) (*entity.Device, error) { + device := new(entity.Device) + err := d.client(systemID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, device) }) - return + + return device, err } // Update updates a given Device -func (d *Device) Update(systemID string, deviceParams *entity.DeviceUpdateParams) (device *entity.Device, err error) { +func (d *Device) Update(systemID string, deviceParams *entity.DeviceUpdateParams) (*entity.Device, error) { qsp, err := query.Values(deviceParams) if err != nil { - return + return nil, err } - device = new(entity.Device) + + device := new(entity.Device) err = d.client(systemID).Put(qsp, func(data []byte) error { return json.Unmarshal(data, device) }) - return + + return device, err } // Delete deletes a given Device diff --git a/client/devices.go b/client/devices.go index a9a60ff..5f6b57b 100644 --- a/client/devices.go +++ b/client/devices.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // Devices implements api.Devices type Devices struct { - ApiClient ApiClient + APIClient APIClient } -func (d *Devices) client() ApiClient { - return d.ApiClient.GetSubObject("devices") +func (d *Devices) client() APIClient { + return d.APIClient.GetSubObject("devices") } // Get fetches a list of Devices -func (d *Devices) Get() (devices []entity.Device, err error) { - err = d.client().Get("", url.Values{}, func(data []byte) error { +func (d *Devices) Get() ([]entity.Device, error) { + devices := make([]entity.Device, 0) + err := d.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &devices) }) - return + + return devices, err } // Create creates a new Device -func (d *Devices) Create(deviceParams *entity.DeviceCreateParams) (device *entity.Device, err error) { +func (d *Devices) Create(deviceParams *entity.DeviceCreateParams) (*entity.Device, error) { qsp, err := query.Values(deviceParams) if err != nil { - return + return nil, err } - device = new(entity.Device) + + device := new(entity.Device) err = d.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, device) }) - return + + return device, err } diff --git a/client/dns_resource.go b/client/dns_resource.go index e15c6a5..eaf0ec1 100644 --- a/client/dns_resource.go +++ b/client/dns_resource.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -11,33 +12,36 @@ import ( // DNSResource implements api.DNSResource type DNSResource struct { - ApiClient ApiClient + APIClient APIClient } -func (d *DNSResource) client(id int) ApiClient { - return d.ApiClient.GetSubObject(fmt.Sprintf("dnsresources/%v", id)) +func (d *DNSResource) client(id int) APIClient { + return d.APIClient.GetSubObject(fmt.Sprintf("dnsresources/%v", id)) } // Get fetches a given DNSResource -func (d *DNSResource) Get(id int) (dnsResource *entity.DNSResource, err error) { - dnsResource = new(entity.DNSResource) - err = d.client(id).Get("", url.Values{}, func(data []byte) error { +func (d *DNSResource) Get(id int) (*entity.DNSResource, error) { + dnsResource := new(entity.DNSResource) + err := d.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, dnsResource) }) - return + + return dnsResource, err } // Update updates a given DNSResource -func (d *DNSResource) Update(id int, params *entity.DNSResourceParams) (dnsResource *entity.DNSResource, err error) { +func (d *DNSResource) Update(id int, params *entity.DNSResourceParams) (*entity.DNSResource, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - dnsResource = new(entity.DNSResource) + + dnsResource := new(entity.DNSResource) err = d.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, dnsResource) }) - return + + return dnsResource, err } // Delete deletes a given DNSResource diff --git a/client/dns_resource_record.go b/client/dns_resource_record.go index 2c7f8ef..1eceb96 100644 --- a/client/dns_resource_record.go +++ b/client/dns_resource_record.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -11,33 +12,36 @@ import ( // DNSResourceRecord implements api.DNSResourceRecord type DNSResourceRecord struct { - ApiClient ApiClient + APIClient APIClient } -func (d *DNSResourceRecord) client(id int) ApiClient { - return d.ApiClient.GetSubObject(fmt.Sprintf("dnsresourcerecords/%v", id)) +func (d *DNSResourceRecord) client(id int) APIClient { + return d.APIClient.GetSubObject(fmt.Sprintf("dnsresourcerecords/%v", id)) } // Get fetches a given DNSResourceRecord -func (d *DNSResourceRecord) Get(id int) (dnsResourceRecord *entity.DNSResourceRecord, err error) { - dnsResourceRecord = new(entity.DNSResourceRecord) - err = d.client(id).Get("", url.Values{}, func(data []byte) error { +func (d *DNSResourceRecord) Get(id int) (*entity.DNSResourceRecord, error) { + dnsResourceRecord := new(entity.DNSResourceRecord) + err := d.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, dnsResourceRecord) }) - return + + return dnsResourceRecord, err } // Update updates a given DNSResourceRecord -func (d *DNSResourceRecord) Update(id int, params *entity.DNSResourceRecordParams) (dnsResourceRecord *entity.DNSResourceRecord, err error) { +func (d *DNSResourceRecord) Update(id int, params *entity.DNSResourceRecordParams) (*entity.DNSResourceRecord, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - dnsResourceRecord = new(entity.DNSResourceRecord) + + dnsResourceRecord := new(entity.DNSResourceRecord) err = d.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, dnsResourceRecord) }) - return + + return dnsResourceRecord, err } // Delete deletes a given DNSResourceRecord diff --git a/client/dns_resource_records.go b/client/dns_resource_records.go index 4a6b434..6489c8e 100644 --- a/client/dns_resource_records.go +++ b/client/dns_resource_records.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // DNSResourceRecords implements api.DNSResourceRecords type DNSResourceRecords struct { - ApiClient ApiClient + APIClient APIClient } -func (d *DNSResourceRecords) client() ApiClient { - return d.ApiClient.GetSubObject("dnsresourcerecords") +func (d *DNSResourceRecords) client() APIClient { + return d.APIClient.GetSubObject("dnsresourcerecords") } // Get fetches a list of DNSResourceRecord objectts -func (d *DNSResourceRecords) Get() (dnsResourceRecords []entity.DNSResourceRecord, err error) { - err = d.client().Get("", url.Values{}, func(data []byte) error { +func (d *DNSResourceRecords) Get() ([]entity.DNSResourceRecord, error) { + dnsResourceRecords := make([]entity.DNSResourceRecord, 0) + err := d.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &dnsResourceRecords) }) - return + + return dnsResourceRecords, err } // Create creates a new DNSResourceRecord -func (d *DNSResourceRecords) Create(params *entity.DNSResourceRecordParams) (dnsResourceRecord *entity.DNSResourceRecord, err error) { +func (d *DNSResourceRecords) Create(params *entity.DNSResourceRecordParams) (*entity.DNSResourceRecord, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - dnsResourceRecord = new(entity.DNSResourceRecord) + + dnsResourceRecord := new(entity.DNSResourceRecord) err = d.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, dnsResourceRecord) }) - return + + return dnsResourceRecord, err } diff --git a/client/dns_resources.go b/client/dns_resources.go index 9130ba4..7017726 100644 --- a/client/dns_resources.go +++ b/client/dns_resources.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // DNSResources implements api.DNSResources type DNSResources struct { - ApiClient ApiClient + APIClient APIClient } -func (d *DNSResources) client() ApiClient { - return d.ApiClient.GetSubObject("dnsresources") +func (d *DNSResources) client() APIClient { + return d.APIClient.GetSubObject("dnsresources") } // Get fetches a list of DNSResource objects -func (d *DNSResources) Get() (dnsresources []entity.DNSResource, err error) { - err = d.client().Get("", url.Values{}, func(data []byte) error { +func (d *DNSResources) Get() ([]entity.DNSResource, error) { + dnsresources := make([]entity.DNSResource, 0) + err := d.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &dnsresources) }) - return + + return dnsresources, err } // Create creates a new DNSResource -func (d *DNSResources) Create(params *entity.DNSResourceParams) (dnsResource *entity.DNSResource, err error) { +func (d *DNSResources) Create(params *entity.DNSResourceParams) (*entity.DNSResource, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - dnsResource = new(entity.DNSResource) + + dnsResource := new(entity.DNSResource) err = d.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, dnsResource) }) - return + + return dnsResource, err } diff --git a/client/domain.go b/client/domain.go index b288747..54cb1ab 100644 --- a/client/domain.go +++ b/client/domain.go @@ -11,42 +11,46 @@ import ( // Domain implements api.Domain type Domain struct { - ApiClient ApiClient + APIClient APIClient } -func (d *Domain) client(id int) ApiClient { - return d.ApiClient.GetSubObject(fmt.Sprintf("domains/%v", id)) +func (d *Domain) client(id int) APIClient { + return d.APIClient.GetSubObject(fmt.Sprintf("domains/%v", id)) } // Get fetches a given Domain -func (d *Domain) Get(id int) (domain *entity.Domain, err error) { - domain = new(entity.Domain) - err = d.client(id).Get("", url.Values{}, func(data []byte) error { +func (d *Domain) Get(id int) (*entity.Domain, error) { + domain := new(entity.Domain) + err := d.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, domain) }) - return + + return domain, err } // SetDefault sets the given Domain as the default Domain -func (d *Domain) SetDefault(id int) (domain *entity.Domain, err error) { - domain = new(entity.Domain) - err = d.client(id).Post("set_default", url.Values{}, func(data []byte) error { +func (d *Domain) SetDefault(id int) (*entity.Domain, error) { + domain := new(entity.Domain) + err := d.client(id).Post("set_default", url.Values{}, func(data []byte) error { return json.Unmarshal(data, domain) }) - return + + return domain, err } // Update updates the given Domain -func (d *Domain) Update(id int, params *entity.DomainParams) (domain *entity.Domain, err error) { +func (d *Domain) Update(id int, params *entity.DomainParams) (*entity.Domain, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - domain = new(entity.Domain) + + domain := new(entity.Domain) err = d.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, domain) }) - return + + return domain, err } // Delete deletes a given Domain diff --git a/client/domains.go b/client/domains.go index 212bb8c..a179cb2 100644 --- a/client/domains.go +++ b/client/domains.go @@ -11,37 +11,42 @@ import ( // Domains implements api.Domains type Domains struct { - ApiClient ApiClient + APIClient APIClient } -func (d *Domains) client() ApiClient { - return d.ApiClient.GetSubObject("domains") +func (d *Domains) client() APIClient { + return d.APIClient.GetSubObject("domains") } // Get fetches a list of Domain objects -func (d *Domains) Get() (domains []entity.Domain, err error) { - err = d.client().Get("", url.Values{}, func(data []byte) error { +func (d *Domains) Get() ([]entity.Domain, error) { + domains := make([]entity.Domain, 0) + err := d.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &domains) }) - return + + return domains, err } // Create creates a new Domain -func (d *Domains) Create(params *entity.DomainParams) (domain *entity.Domain, err error) { +func (d *Domains) Create(params *entity.DomainParams) (*entity.Domain, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - domain = new(entity.Domain) + + domain := new(entity.Domain) err = d.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, domain) }) - return + + return domain, err } // SetSerial sets the SOA serial for all domains func (d *Domains) SetSerial(serial int) error { qsp := url.Values{} qsp.Set("serial", fmt.Sprintf("%v", serial)) + return d.client().Post("", qsp, func(data []byte) error { return nil }) } diff --git a/client/fabric.go b/client/fabric.go index 055f205..1a9ead0 100644 --- a/client/fabric.go +++ b/client/fabric.go @@ -11,33 +11,36 @@ import ( // Fabric implments api.Fabric type Fabric struct { - ApiClient ApiClient + APIClient APIClient } -func (f *Fabric) client(id int) ApiClient { - return f.ApiClient.GetSubObject("fabrics").GetSubObject(fmt.Sprintf("%v", id)) +func (f *Fabric) client(id int) APIClient { + return f.APIClient.GetSubObject("fabrics").GetSubObject(fmt.Sprintf("%v", id)) } // Get fetchs a Fabric object -func (f *Fabric) Get(id int) (fabric *entity.Fabric, err error) { - fabric = new(entity.Fabric) - err = f.client(id).Get("", url.Values{}, func(data []byte) error { +func (f *Fabric) Get(id int) (*entity.Fabric, error) { + fabric := new(entity.Fabric) + err := f.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, fabric) }) - return + + return fabric, err } // Update updates a given Fabric -func (f *Fabric) Update(id int, fabricParams *entity.FabricParams) (fabric *entity.Fabric, err error) { +func (f *Fabric) Update(id int, fabricParams *entity.FabricParams) (*entity.Fabric, error) { qsp, err := query.Values(fabricParams) if err != nil { - return + return nil, err } - fabric = new(entity.Fabric) + + fabric := new(entity.Fabric) err = f.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, fabric) }) - return + + return fabric, err } // Delete deletes a given Fabric diff --git a/client/fabrics.go b/client/fabrics.go index 6b5bc9d..05ed1da 100644 --- a/client/fabrics.go +++ b/client/fabrics.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // Fabrics implements api.Fabrics type Fabrics struct { - ApiClient ApiClient + APIClient APIClient } -func (f *Fabrics) client() ApiClient { - return f.ApiClient.GetSubObject("fabrics") +func (f *Fabrics) client() APIClient { + return f.APIClient.GetSubObject("fabrics") } // Get fetches a list of Fabric objects -func (f *Fabrics) Get() (fabrics []entity.Fabric, err error) { - err = f.client().Get("", url.Values{}, func(data []byte) error { +func (f *Fabrics) Get() ([]entity.Fabric, error) { + fabrics := make([]entity.Fabric, 0) + err := f.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &fabrics) }) - return + + return fabrics, err } // Create creates a new Fabric object -func (f *Fabrics) Create(fabricParams *entity.FabricParams) (fabric *entity.Fabric, err error) { +func (f *Fabrics) Create(fabricParams *entity.FabricParams) (*entity.Fabric, error) { qsp, err := query.Values(fabricParams) if err != nil { - return + return nil, err } - fabric = new(entity.Fabric) + + fabric := new(entity.Fabric) err = f.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, fabric) }) - return + + return fabric, err } diff --git a/client/ip_addresses.go b/client/ip_addresses.go index eebbeaf..0cf6684 100644 --- a/client/ip_addresses.go +++ b/client/ip_addresses.go @@ -9,23 +9,26 @@ import ( // IPAddresses implements api.IPAddresses type IPAddresses struct { - ApiClient ApiClient + APIClient APIClient } -func (i *IPAddresses) client() ApiClient { - return i.ApiClient.GetSubObject("ipaddresses") +func (i *IPAddresses) client() APIClient { + return i.APIClient.GetSubObject("ipaddresses") } // Get fetches a specified set of IPAddresses -func (i *IPAddresses) Get(params *entity.IPAddressesParams) (ipAddresses []entity.IPAddress, err error) { +func (i *IPAddresses) Get(params *entity.IPAddressesParams) ([]entity.IPAddress, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } + + ipAddresses := make([]entity.IPAddress, 0) err = i.client().Get("", qsp, func(data []byte) error { return json.Unmarshal(data, &ipAddresses) }) - return + + return ipAddresses, err } // Release releases a set of allocated IPAddresses @@ -34,18 +37,21 @@ func (i *IPAddresses) Release(params *entity.IPAddressesParams) error { if err != nil { return err } + return i.client().Post("release", qsp, func(data []byte) error { return nil }) } // Reserve reserves a set of IPAddresses -func (i *IPAddresses) Reserve(params *entity.IPAddressesParams) (ipAddress *entity.IPAddress, err error) { +func (i *IPAddresses) Reserve(params *entity.IPAddressesParams) (*entity.IPAddress, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ipAddress = new(entity.IPAddress) + + ipAddress := new(entity.IPAddress) err = i.client().Post("reserve", qsp, func(data []byte) error { return json.Unmarshal(data, ipAddress) }) - return + + return ipAddress, err } diff --git a/client/ip_range.go b/client/ip_range.go index f86e246..68f753d 100644 --- a/client/ip_range.go +++ b/client/ip_range.go @@ -11,33 +11,36 @@ import ( // IPRange implements api.IPRange type IPRange struct { - ApiClient ApiClient + APIClient APIClient } -func (i *IPRange) client(id int) ApiClient { - return i.ApiClient.GetSubObject("ipranges").GetSubObject(fmt.Sprintf("%v", id)) +func (i *IPRange) client(id int) APIClient { + return i.APIClient.GetSubObject("ipranges").GetSubObject(fmt.Sprintf("%v", id)) } // Get fetches a given IPRange -func (i *IPRange) Get(id int) (ipRange *entity.IPRange, err error) { - ipRange = new(entity.IPRange) - err = i.client(id).Get("", url.Values{}, func(data []byte) error { +func (i *IPRange) Get(id int) (*entity.IPRange, error) { + ipRange := new(entity.IPRange) + err := i.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, ipRange) }) - return + + return ipRange, err } // Update updates a given IPRange -func (i *IPRange) Update(id int, params *entity.IPRangeParams) (ipRange *entity.IPRange, err error) { +func (i *IPRange) Update(id int, params *entity.IPRangeParams) (*entity.IPRange, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ipRange = new(entity.IPRange) + + ipRange := new(entity.IPRange) err = i.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, ipRange) }) - return + + return ipRange, err } // Delete deletes a given IPRange diff --git a/client/ip_ranges.go b/client/ip_ranges.go index d9ba517..9486ea9 100644 --- a/client/ip_ranges.go +++ b/client/ip_ranges.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // IPRanges implements api.IPRanges type IPRanges struct { - ApiClient ApiClient + APIClient APIClient } -func (i *IPRanges) client() ApiClient { - return i.ApiClient.GetSubObject("ipranges") +func (i *IPRanges) client() APIClient { + return i.APIClient.GetSubObject("ipranges") } // Get fetches a list of IPRange objects -func (i *IPRanges) Get() (ipRanges []entity.IPRange, err error) { - err = i.client().Get("", url.Values{}, func(data []byte) error { +func (i *IPRanges) Get() ([]entity.IPRange, error) { + ipRanges := make([]entity.IPRange, 0) + err := i.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &ipRanges) }) - return + + return ipRanges, err } // Create creates a new IPRange object -func (i *IPRanges) Create(params *entity.IPRangeParams) (ipRange *entity.IPRange, err error) { +func (i *IPRanges) Create(params *entity.IPRangeParams) (*entity.IPRange, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ipRange = new(entity.IPRange) + + ipRange := new(entity.IPRange) err = i.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, ipRange) }) - return + + return ipRange, err } diff --git a/client/machine.go b/client/machine.go index 292309c..13fe63a 100644 --- a/client/machine.go +++ b/client/machine.go @@ -10,37 +10,41 @@ import ( // Machine contains functionality for manipulating the Machine entity. type Machine struct { - ApiClient ApiClient + APIClient APIClient } -func (m *Machine) client(systemID string) ApiClient { - return m.ApiClient.GetSubObject("machines").GetSubObject(systemID) +func (m *Machine) client(systemID string) APIClient { + return m.APIClient.GetSubObject("machines").GetSubObject(systemID) } // Get machine details. -func (m *Machine) Get(systemID string) (ma *entity.Machine, err error) { - ma = new(entity.Machine) - err = m.client(systemID).Get("", url.Values{}, func(data []byte) error { - return json.Unmarshal(data, ma) +func (m *Machine) Get(systemID string) (*entity.Machine, error) { + machine := new(entity.Machine) + err := m.client(systemID).Get("", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Update machine. -func (m *Machine) Update(systemID string, machineParams *entity.MachineParams, powerParams map[string]interface{}) (ma *entity.Machine, err error) { +func (m *Machine) Update(systemID string, machineParams *entity.MachineParams, powerParams map[string]interface{}) (*entity.Machine, error) { qsp, err := query.Values(machineParams) if err != nil { - return + return nil, err } + for k, v := range powerParamsToURLValues(powerParams) { // Since qsp.Add(k, v...) is not allowed qsp[k] = append(qsp[k], v...) } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client(systemID).Put(qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Delete machine. @@ -49,71 +53,81 @@ func (m *Machine) Delete(systemID string) error { } // Commission machine. -func (m *Machine) Commission(systemID string, params *entity.MachineCommissionParams) (ma *entity.Machine, err error) { +func (m *Machine) Commission(systemID string, params *entity.MachineCommissionParams) (*entity.Machine, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client(systemID).Post("commission", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Deploy machine. -func (m *Machine) Deploy(systemID string, params *entity.MachineDeployParams) (ma *entity.Machine, err error) { +func (m *Machine) Deploy(systemID string, params *entity.MachineDeployParams) (*entity.Machine, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client(systemID).Post("deploy", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Release machine. -func (m *Machine) Release(systemID string, params *entity.MachineReleaseParams) (ma *entity.Machine, err error) { +func (m *Machine) Release(systemID string, params *entity.MachineReleaseParams) (*entity.Machine, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client(systemID).Post("release", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Lock machine. -func (m *Machine) Lock(systemID string, comment string) (ma *entity.Machine, err error) { +func (m *Machine) Lock(systemID string, comment string) (*entity.Machine, error) { qsp := make(url.Values) if comment != "" { qsp.Set("comment", comment) } - ma = new(entity.Machine) - err = m.client(systemID).Post("lock", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + + machine := new(entity.Machine) + err := m.client(systemID).Post("lock", qsp, func(data []byte) error { + return json.Unmarshal(data, machine) }) - return + + return machine, err } -// Clear default gateways. -func (m *Machine) ClearDefaultGateways(systemID string) (ma *entity.Machine, err error) { - ma = new(entity.Machine) - err = m.client(systemID).Post("clear_default_gateways", url.Values{}, func(data []byte) error { - return json.Unmarshal(data, ma) +// ClearDefaultGateways clears default gateways. +func (m *Machine) ClearDefaultGateways(systemID string) (*entity.Machine, error) { + machine := new(entity.Machine) + err := m.client(systemID).Post("clear_default_gateways", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, machine) }) - return + + return machine, err } // GetPowerParameters fetches the power parameters of a given Machine -func (m *Machine) GetPowerParameters(systemID string) (params map[string]interface{}, err error) { - params = map[string]interface{}{} - err = m.client(systemID).Get("power_parameters", url.Values{}, func(data []byte) error { +func (m *Machine) GetPowerParameters(systemID string) (map[string]interface{}, error) { + params := map[string]interface{}{} + err := m.client(systemID).Get("power_parameters", url.Values{}, func(data []byte) error { return json.Unmarshal(data, ¶ms) }) - return + + return params, err } diff --git a/client/machines.go b/client/machines.go index e76c8ed..7e9c008 100644 --- a/client/machines.go +++ b/client/machines.go @@ -10,49 +10,56 @@ import ( // Machines contains functionality for manipulating the Machines entity. type Machines struct { - ApiClient ApiClient + APIClient APIClient } -func (m *Machines) client() ApiClient { - return m.ApiClient.GetSubObject("machines") +func (m *Machines) client() APIClient { + return m.APIClient.GetSubObject("machines") } // Get fetches a list machines. -func (m *Machines) Get() (machines []entity.Machine, err error) { - err = m.client().Get("", url.Values{}, func(data []byte) error { +func (m *Machines) Get() ([]entity.Machine, error) { + machines := make([]entity.Machine, 0) + err := m.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &machines) }) - return + + return machines, err } // Create machine. -func (m *Machines) Create(machineParams *entity.MachineParams, powerParams map[string]interface{}) (ma *entity.Machine, err error) { +func (m *Machines) Create(machineParams *entity.MachineParams, powerParams map[string]interface{}) (*entity.Machine, error) { qsp, err := query.Values(machineParams) if err != nil { - return + return nil, err } + for k, v := range powerParamsToURLValues(powerParams) { // Since qsp.Add(k, v...) is not allowed qsp[k] = append(qsp[k], v...) } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client().Post("", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Allocate machine. -func (m *Machines) Allocate(params *entity.MachineAllocateParams) (ma *entity.Machine, err error) { +func (m *Machines) Allocate(params *entity.MachineAllocateParams) (*entity.Machine, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - ma = new(entity.Machine) + + machine := new(entity.Machine) err = m.client().Post("allocate", qsp, func(data []byte) error { - return json.Unmarshal(data, ma) + return json.Unmarshal(data, machine) }) - return + + return machine, err } // Release machine. @@ -61,9 +68,11 @@ func (m *Machines) Release(systemIDs []string, comment string) error { for _, val := range systemIDs { qsp.Add("machines", val) } + if comment != "" { qsp.Add("comment", comment) } + return m.client().Post("release", qsp, func(data []byte) error { return nil }) } diff --git a/client/network_interface.go b/client/network_interface.go index 085464e..b991a17 100644 --- a/client/network_interface.go +++ b/client/network_interface.go @@ -11,44 +11,48 @@ import ( // NetworkInterface implements api.NetworkInterface type NetworkInterface struct { - ApiClient ApiClient + APIClient APIClient } -func (n *NetworkInterface) client(systemID string, id int) ApiClient { - return n.ApiClient.GetSubObject("nodes"). +func (n *NetworkInterface) client(systemID string, id int) APIClient { + return n.APIClient.GetSubObject("nodes"). GetSubObject(systemID). GetSubObject("interfaces"). GetSubObject(fmt.Sprintf("%v", id)) } -func (n *NetworkInterface) callPost(systemID string, id int, qsp url.Values, op string) (networkInterface *entity.NetworkInterface, err error) { - networkInterface = new(entity.NetworkInterface) - err = n.client(systemID, id).Post(op, qsp, func(data []byte) error { +func (n *NetworkInterface) callPost(systemID string, id int, qsp url.Values, op string) (*entity.NetworkInterface, error) { + networkInterface := new(entity.NetworkInterface) + err := n.client(systemID, id).Post(op, qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // Get fetches a NetworkInterface for the given system_id and NetworkInterface id -func (n *NetworkInterface) Get(systemID string, id int) (networkInterface *entity.NetworkInterface, err error) { - networkInterface = new(entity.NetworkInterface) - err = n.client(systemID, id).Get("", url.Values{}, func(data []byte) error { +func (n *NetworkInterface) Get(systemID string, id int) (*entity.NetworkInterface, error) { + networkInterface := new(entity.NetworkInterface) + err := n.client(systemID, id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // Update updates a give NetworkInterface -func (n *NetworkInterface) Update(systemID string, id int, params *entity.NetworkInterfaceUpdateParams) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterface) Update(systemID string, id int, params *entity.NetworkInterfaceUpdateParams) (*entity.NetworkInterface, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - networkInterface = new(entity.NetworkInterface) + + networkInterface := new(entity.NetworkInterface) err = n.client(systemID, id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // Delete deletes a given NetworkInterface @@ -57,7 +61,7 @@ func (n *NetworkInterface) Delete(systemID string, id int) error { } // Disconnect marks a given NetworkInterface as disconnected -func (n *NetworkInterface) Disconnect(systemID string, id int) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterface) Disconnect(systemID string, id int) (*entity.NetworkInterface, error) { return n.callPost(systemID, id, url.Values{}, "disconnect") } @@ -65,6 +69,7 @@ func (n *NetworkInterface) Disconnect(systemID string, id int) (networkInterface func (n *NetworkInterface) AddTag(systemID string, id int, tag string) (*entity.NetworkInterface, error) { qsp := url.Values{} qsp.Add("tag", tag) + return n.callPost(systemID, id, qsp, "add_tag") } @@ -72,6 +77,7 @@ func (n *NetworkInterface) AddTag(systemID string, id int, tag string) (*entity. func (n *NetworkInterface) RemoveTag(systemID string, id int, tag string) (*entity.NetworkInterface, error) { qsp := url.Values{} qsp.Add("tag", tag) + return n.callPost(systemID, id, qsp, "remove_tag") } @@ -81,19 +87,22 @@ func (n *NetworkInterface) LinkSubnet(systemID string, id int, params *entity.Ne if err != nil { return nil, err } + return n.callPost(systemID, id, qsp, "link_subnet") } // UnlinkSubnet removes a given link -func (n *NetworkInterface) UnlinkSubnet(systemID string, id int, linkID int) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterface) UnlinkSubnet(systemID string, id int, linkID int) (*entity.NetworkInterface, error) { qsp := url.Values{} qsp.Add("id", fmt.Sprintf("%v", linkID)) + return n.callPost(systemID, id, qsp, "unlink_subnet") } // SetDefaultGateway sets the default gateway of the given NetworkInterface -func (n *NetworkInterface) SetDefaultGateway(systemID string, id int, linkID int) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterface) SetDefaultGateway(systemID string, id int, linkID int) (*entity.NetworkInterface, error) { qsp := url.Values{} qsp.Add("link_id", fmt.Sprintf("%v", linkID)) + return n.callPost(systemID, id, qsp, "set_default_gateway") } diff --git a/client/network_interfaces.go b/client/network_interfaces.go index a12d69d..9503520 100644 --- a/client/network_interfaces.go +++ b/client/network_interfaces.go @@ -10,69 +10,79 @@ import ( // NetworkInterfaces implements api.NetworkInterfaces type NetworkInterfaces struct { - ApiClient ApiClient + APIClient APIClient } -func (n *NetworkInterfaces) client(systemID string) ApiClient { - return n.ApiClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("interfaces") +func (n *NetworkInterfaces) client(systemID string) APIClient { + return n.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("interfaces") } // Get fetches a list of NetworkInterface objects -func (n *NetworkInterfaces) Get(systemID string) (networkInterfaces []entity.NetworkInterface, err error) { - err = n.client(systemID).Get("", url.Values{}, func(data []byte) error { +func (n *NetworkInterfaces) Get(systemID string) ([]entity.NetworkInterface, error) { + networkInterfaces := make([]entity.NetworkInterface, 0) + err := n.client(systemID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &networkInterfaces) }) - return + + return networkInterfaces, err } // CreateBond creates a Bond interface from two or more given NetworkInterface objects -func (n *NetworkInterfaces) CreateBond(systemID string, params *entity.NetworkInterfaceBondParams) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterfaces) CreateBond(systemID string, params *entity.NetworkInterfaceBondParams) (*entity.NetworkInterface, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - networkInterface = new(entity.NetworkInterface) + + networkInterface := new(entity.NetworkInterface) err = n.client(systemID).Post("create_bond", qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // CreateBridge creates a Bridge type interface -func (n *NetworkInterfaces) CreateBridge(systemID string, params *entity.NetworkInterfaceBridgeParams) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterfaces) CreateBridge(systemID string, params *entity.NetworkInterfaceBridgeParams) (*entity.NetworkInterface, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - networkInterface = new(entity.NetworkInterface) + + networkInterface := new(entity.NetworkInterface) err = n.client(systemID).Post("create_bridge", qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // CreatePhysical creates a new physical interface -func (n *NetworkInterfaces) CreatePhysical(systemID string, params *entity.NetworkInterfacePhysicalParams) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterfaces) CreatePhysical(systemID string, params *entity.NetworkInterfacePhysicalParams) (*entity.NetworkInterface, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - networkInterface = new(entity.NetworkInterface) + + networkInterface := new(entity.NetworkInterface) err = n.client(systemID).Post("create_physical", qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } // CreateVLAN creates an interface tagged for a given VLAN -func (n *NetworkInterfaces) CreateVLAN(systemID string, params *entity.NetworkInterfaceVLANParams) (networkInterface *entity.NetworkInterface, err error) { +func (n *NetworkInterfaces) CreateVLAN(systemID string, params *entity.NetworkInterfaceVLANParams) (*entity.NetworkInterface, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - networkInterface = new(entity.NetworkInterface) + + networkInterface := new(entity.NetworkInterface) err = n.client(systemID).Post("create_vlan", qsp, func(data []byte) error { return json.Unmarshal(data, networkInterface) }) - return + + return networkInterface, err } diff --git a/client/raid.go b/client/raid.go index 2c83cae..6f9ace8 100644 --- a/client/raid.go +++ b/client/raid.go @@ -11,33 +11,36 @@ import ( // RAID Contains functionality for manipulating the RAID entity. type RAID struct { - ApiClient ApiClient + APIClient APIClient } -func (r *RAID) client(systemID string, id int) ApiClient { - return r.ApiClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("raid").GetSubObject(fmt.Sprintf("%v", id)) +func (r *RAID) client(systemID string, id int) APIClient { + return r.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("raid").GetSubObject(fmt.Sprintf("%v", id)) } // Get RAID details. -func (r *RAID) Get(systemID string, id int) (raid *entity.RAID, err error) { - raid = new(entity.RAID) - err = r.client(systemID, id).Get("", url.Values{}, func(data []byte) error { +func (r *RAID) Get(systemID string, id int) (*entity.RAID, error) { + raid := new(entity.RAID) + err := r.client(systemID, id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, raid) }) - return + + return raid, err } // Update RAID. -func (r *RAID) Update(systemID string, id int, params *entity.RAIDUpdateParams) (raid *entity.RAID, err error) { +func (r *RAID) Update(systemID string, id int, params *entity.RAIDUpdateParams) (*entity.RAID, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - raid = new(entity.RAID) + + raid := new(entity.RAID) err = r.client(systemID, id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, raid) }) - return + + return raid, err } // Delete RAID. diff --git a/client/raids.go b/client/raids.go index 29a374f..35768d8 100644 --- a/client/raids.go +++ b/client/raids.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -11,30 +12,34 @@ import ( // RAIDs contains functionality for manipulating the RAIDs entity. type RAIDs struct { - ApiClient ApiClient + APIClient APIClient } -func (r *RAIDs) client(systemID string) ApiClient { - return r.ApiClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("raids") +func (r *RAIDs) client(systemID string) APIClient { + return r.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("raids") } // Get RAIDs of a machine. -func (r *RAIDs) Get(systemID string) (raids []entity.RAID, err error) { - err = r.client(systemID).Get("", url.Values{}, func(data []byte) error { +func (r *RAIDs) Get(systemID string) ([]entity.RAID, error) { + raids := make([]entity.RAID, 0) + err := r.client(systemID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &raids) }) - return + + return raids, err } // Create a RAID of a machine. -func (r *RAIDs) Create(systemID string, params *entity.RAIDCreateParams) (raid *entity.RAID, err error) { +func (r *RAIDs) Create(systemID string, params *entity.RAIDCreateParams) (*entity.RAID, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - raid = new(entity.RAID) + + raid := new(entity.RAID) err = r.client(systemID).Post("", qsp, func(data []byte) error { return json.Unmarshal(data, raid) }) - return + + return raid, err } diff --git a/client/resource_pool.go b/client/resource_pool.go index d7c009f..f511f6b 100644 --- a/client/resource_pool.go +++ b/client/resource_pool.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -11,33 +12,36 @@ import ( // ResourcePool implements api.ResourcePool type ResourcePool struct { - ApiClient ApiClient + APIClient APIClient } -func (r *ResourcePool) client(id int) ApiClient { - return r.ApiClient.GetSubObject(fmt.Sprintf("resourcepool/%v", id)) +func (r *ResourcePool) client(id int) APIClient { + return r.APIClient.GetSubObject(fmt.Sprintf("resourcepool/%v", id)) } // Get fetches a given ResourcePool -func (r *ResourcePool) Get(id int) (resourcePool *entity.ResourcePool, err error) { - resourcePool = new(entity.ResourcePool) - err = r.client(id).Get("", url.Values{}, func(data []byte) error { +func (r *ResourcePool) Get(id int) (*entity.ResourcePool, error) { + resourcePool := new(entity.ResourcePool) + err := r.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, resourcePool) }) - return + + return resourcePool, err } // Update updates a given ResourcePool -func (r *ResourcePool) Update(id int, params *entity.ResourcePoolParams) (resourcePool *entity.ResourcePool, err error) { +func (r *ResourcePool) Update(id int, params *entity.ResourcePoolParams) (*entity.ResourcePool, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - resourcePool = new(entity.ResourcePool) + + resourcePool := new(entity.ResourcePool) err = r.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, resourcePool) }) - return + + return resourcePool, err } // Delete deletes a given ResourcePool diff --git a/client/resource_pools.go b/client/resource_pools.go index b2fb4f3..7ed8a0f 100644 --- a/client/resource_pools.go +++ b/client/resource_pools.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // ResourcePools implements api.ResourcePools type ResourcePools struct { - ApiClient ApiClient + APIClient APIClient } -func (r *ResourcePools) client() ApiClient { - return r.ApiClient.GetSubObject("resourcepools") +func (r *ResourcePools) client() APIClient { + return r.APIClient.GetSubObject("resourcepools") } // Get fetches a list of ResourcePool objects -func (r *ResourcePools) Get() (resourcePools []entity.ResourcePool, err error) { - err = r.client().Get("", url.Values{}, func(data []byte) error { +func (r *ResourcePools) Get() ([]entity.ResourcePool, error) { + resourcePools := make([]entity.ResourcePool, 0) + err := r.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &resourcePools) }) - return + + return resourcePools, err } // Create creates a new ResourcePool -func (r *ResourcePools) Create(params *entity.ResourcePoolParams) (resourcePool *entity.ResourcePool, err error) { +func (r *ResourcePools) Create(params *entity.ResourcePoolParams) (*entity.ResourcePool, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - resourcePool = new(entity.ResourcePool) + + resourcePool := new(entity.ResourcePool) err = r.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, resourcePool) }) - return + + return resourcePool, err } diff --git a/client/space.go b/client/space.go index 72242fe..70355c4 100644 --- a/client/space.go +++ b/client/space.go @@ -10,31 +10,33 @@ import ( // Space implements api.Space type Space struct { - ApiClient ApiClient + APIClient APIClient } -func (s *Space) client(id int) ApiClient { - return s.ApiClient.GetSubObject("spaces").GetSubObject(fmt.Sprintf("%v", id)) +func (s *Space) client(id int) APIClient { + return s.APIClient.GetSubObject("spaces").GetSubObject(fmt.Sprintf("%v", id)) } // Get fetches a given Space -func (s *Space) Get(id int) (space *entity.Space, err error) { - space = new(entity.Space) - err = s.client(id).Get("", url.Values{}, func(data []byte) error { +func (s *Space) Get(id int) (*entity.Space, error) { + space := new(entity.Space) + err := s.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, space) }) - return + + return space, err } // Update updates a given Space -func (s *Space) Update(id int, name string) (space *entity.Space, err error) { - space = new(entity.Space) +func (s *Space) Update(id int, name string) (*entity.Space, error) { + space := new(entity.Space) qsp := url.Values{} qsp.Set("name", name) - err = s.client(id).Put(qsp, func(data []byte) error { + err := s.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, space) }) - return + + return space, err } // Delete deletes a given Space diff --git a/client/spaces.go b/client/spaces.go index 03ed134..f441e10 100644 --- a/client/spaces.go +++ b/client/spaces.go @@ -9,28 +9,31 @@ import ( // Spaces implements api.Spaces type Spaces struct { - ApiClient ApiClient + APIClient APIClient } -func (s *Spaces) client() ApiClient { - return s.ApiClient.GetSubObject("spaces") +func (s *Spaces) client() APIClient { + return s.APIClient.GetSubObject("spaces") } // Get fetches a list of Space objects -func (s *Spaces) Get() (spaces []entity.Space, err error) { - err = s.client().Get("", url.Values{}, func(data []byte) error { +func (s *Spaces) Get() ([]entity.Space, error) { + spaces := make([]entity.Space, 0) + err := s.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &spaces) }) - return + + return spaces, err } // Create creates a new Space -func (s *Spaces) Create(name string) (space *entity.Space, err error) { - space = new(entity.Space) +func (s *Spaces) Create(name string) (*entity.Space, error) { + space := new(entity.Space) qsp := url.Values{} qsp.Set("name", name) - err = s.client().Post("", qsp, func(data []byte) error { + err := s.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, space) }) - return + + return space, err } diff --git a/client/subnet.go b/client/subnet.go index 043854c..be2c4bd 100644 --- a/client/subnet.go +++ b/client/subnet.go @@ -13,11 +13,11 @@ import ( // Subnet implements api.Subnet type Subnet struct { - ApiClient ApiClient + APIClient APIClient } -func (s *Subnet) client(id int) ApiClient { - return s.ApiClient.GetSubObject("subnets").GetSubObject(fmt.Sprintf("%v", id)) +func (s *Subnet) client(id int) APIClient { + return s.APIClient.GetSubObject("subnets").GetSubObject(fmt.Sprintf("%v", id)) } // Delete deletes a given Subnet @@ -26,60 +26,70 @@ func (s *Subnet) Delete(id int) error { } // Get fetches a given Subnet -func (s *Subnet) Get(id int) (subnet *entity.Subnet, err error) { - subnet = new(entity.Subnet) - err = s.client(id).Get("", url.Values{}, func(data []byte) error { +func (s *Subnet) Get(id int) (*entity.Subnet, error) { + subnet := new(entity.Subnet) + err := s.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &subnet) }) - return + + return subnet, err } // GetIPAddresses fetches the allocated IPAddresses in the given subnet -func (s *Subnet) GetIPAddresses(id int) (subnetIPAddresses []subnet.IPAddress, err error) { +func (s *Subnet) GetIPAddresses(id int) ([]subnet.IPAddress, error) { qsp := url.Values{} qsp.Set("with_username", "1") qsp.Set("with_summary", "1") - err = s.client(id).Get("ip_addresses", qsp, func(data []byte) error { + subnetIPAddresses := make([]subnet.IPAddress, 0) + err := s.client(id).Get("ip_addresses", qsp, func(data []byte) error { return json.Unmarshal(data, &subnetIPAddresses) }) - return + + return subnetIPAddresses, err } // GetReservedIPRanges fetches the reserved IPRange objects for the given Subnet -func (s *Subnet) GetReservedIPRanges(id int) (subnetReservedIPRanges []subnet.ReservedIPRange, err error) { - err = s.client(id).Get("reserved_ip_ranges", url.Values{}, func(data []byte) error { +func (s *Subnet) GetReservedIPRanges(id int) ([]subnet.ReservedIPRange, error) { + subnetReservedIPRanges := make([]subnet.ReservedIPRange, 0) + err := s.client(id).Get("reserved_ip_ranges", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &subnetReservedIPRanges) }) - return + + return subnetReservedIPRanges, err } // GetStatistics gets the stats of the given subnet -func (s *Subnet) GetStatistics(id int) (stats *subnet.Statistics, err error) { - stats = new(subnet.Statistics) - err = s.client(id).Get("statistics", url.Values{}, func(data []byte) error { +func (s *Subnet) GetStatistics(id int) (*subnet.Statistics, error) { + stats := new(subnet.Statistics) + err := s.client(id).Get("statistics", url.Values{}, func(data []byte) error { return json.Unmarshal(data, stats) }) - return + + return stats, err } // GetUnreservedIPRanges gets the IPRange objects for allocation use -func (s *Subnet) GetUnreservedIPRanges(id int) (ipRanges []subnet.IPRange, err error) { - err = s.client(id).Get("unreserved_ip_ranges", url.Values{}, func(data []byte) error { +func (s *Subnet) GetUnreservedIPRanges(id int) ([]subnet.IPRange, error) { + ipRanges := make([]subnet.IPRange, 0) + err := s.client(id).Get("unreserved_ip_ranges", url.Values{}, func(data []byte) error { log.Printf("%s\n", data) return json.Unmarshal(data, &ipRanges) }) - return + + return ipRanges, err } // Update updates the given Subnet -func (s *Subnet) Update(id int, params *entity.SubnetParams) (subnet *entity.Subnet, err error) { +func (s *Subnet) Update(id int, params *entity.SubnetParams) (*entity.Subnet, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - subnet = new(entity.Subnet) + + subnet := new(entity.Subnet) err = s.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, subnet) }) - return + + return subnet, err } diff --git a/client/subnets.go b/client/subnets.go index 03f5295..63324fb 100644 --- a/client/subnets.go +++ b/client/subnets.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // Subnets contains functionality for manipulating the Subnets entity. type Subnets struct { - ApiClient ApiClient + APIClient APIClient } -func (s *Subnets) client() ApiClient { - return s.ApiClient.GetSubObject("subnets") +func (s *Subnets) client() APIClient { + return s.APIClient.GetSubObject("subnets") } // Get fetches a list of Subnet objects -func (s *Subnets) Get() (subnets []entity.Subnet, err error) { - err = s.client().Get("", url.Values{}, func(data []byte) error { +func (s *Subnets) Get() ([]entity.Subnet, error) { + subnets := make([]entity.Subnet, 0) + err := s.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &subnets) }) - return + + return subnets, err } // Create creates a new Subnet -func (s *Subnets) Create(params *entity.SubnetParams) (subnet *entity.Subnet, err error) { +func (s *Subnets) Create(params *entity.SubnetParams) (*entity.Subnet, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - subnet = new(entity.Subnet) + + subnet := new(entity.Subnet) err = s.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, subnet) }) - return + + return subnet, err } diff --git a/client/tag.go b/client/tag.go index c4f3f93..cc69a48 100644 --- a/client/tag.go +++ b/client/tag.go @@ -10,33 +10,36 @@ import ( // Tag implements api.Tag type Tag struct { - ApiClient ApiClient + APIClient APIClient } -func (t *Tag) client(name string) ApiClient { - return t.ApiClient.GetSubObject("tags").GetSubObject(name) +func (t *Tag) client(name string) APIClient { + return t.APIClient.GetSubObject("tags").GetSubObject(name) } // Get fetches a given tag by name -func (t *Tag) Get(name string) (tag *entity.Tag, err error) { - tag = new(entity.Tag) - err = t.client(name).Get("", url.Values{}, func(data []byte) error { +func (t *Tag) Get(name string) (*entity.Tag, error) { + tag := new(entity.Tag) + err := t.client(name).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, tag) }) - return + + return tag, err } // Update updates a given tag -func (t *Tag) Update(name string, tagParams *entity.TagParams) (tag *entity.Tag, err error) { +func (t *Tag) Update(name string, tagParams *entity.TagParams) (*entity.Tag, error) { qsp, err := query.Values(tagParams) if err != nil { - return + return nil, err } - tag = new(entity.Tag) + + tag := new(entity.Tag) err = t.client(name).Put(qsp, func(data []byte) error { return json.Unmarshal(data, tag) }) - return + + return tag, err } // Delete deletes a given tag @@ -45,11 +48,13 @@ func (t *Tag) Delete(name string) error { } // GetMachines fetches a list of machines with a given tag -func (t *Tag) GetMachines(name string) (machines []entity.Machine, err error) { - err = t.client(name).Get("machines", url.Values{}, func(data []byte) error { +func (t *Tag) GetMachines(name string) ([]entity.Machine, error) { + machines := make([]entity.Machine, 0) + err := t.client(name).Get("machines", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &machines) }) - return + + return machines, err } // AddMachines adds a set of Machines to a given tag @@ -67,5 +72,6 @@ func (t *Tag) updateNodes(name string, machineIds []string, op string) error { for _, id := range machineIds { qsp.Add(op, id) } + return t.client(name).Post("update_nodes", qsp, func(data []byte) error { return nil }) } diff --git a/client/tags.go b/client/tags.go index 0e2c095..db9117e 100644 --- a/client/tags.go +++ b/client/tags.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // Tags implements api.Tags type Tags struct { - ApiClient ApiClient + APIClient APIClient } -func (t *Tags) client() ApiClient { - return t.ApiClient.GetSubObject("tags") +func (t *Tags) client() APIClient { + return t.APIClient.GetSubObject("tags") } // Get fetches a list of Tag objects -func (t *Tags) Get() (tags []entity.Tag, err error) { - err = t.client().Get("", url.Values{}, func(data []byte) error { +func (t *Tags) Get() ([]entity.Tag, error) { + tags := make([]entity.Tag, 0) + err := t.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &tags) }) - return + + return tags, err } // Create creates a new Tag -func (t *Tags) Create(tagParams *entity.TagParams) (tag *entity.Tag, err error) { +func (t *Tags) Create(tagParams *entity.TagParams) (*entity.Tag, error) { qsp, err := query.Values(tagParams) if err != nil { - return + return nil, err } - tag = new(entity.Tag) + + tag := new(entity.Tag) err = t.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, tag) }) - return + + return tag, err } diff --git a/client/user.go b/client/user.go index d34436d..f8934a7 100644 --- a/client/user.go +++ b/client/user.go @@ -10,20 +10,21 @@ import ( // User implements api.User type User struct { - ApiClient ApiClient + APIClient APIClient } -func (u *User) client(userName string) ApiClient { - return u.ApiClient.GetSubObject(fmt.Sprintf("users/%s", userName)) +func (u *User) client(userName string) APIClient { + return u.APIClient.GetSubObject(fmt.Sprintf("users/%s", userName)) } // Get fetches a User by username -func (u *User) Get(userName string) (user *entity.User, err error) { - user = new(entity.User) - err = u.client(userName).Get("", url.Values{}, func(data []byte) error { +func (u *User) Get(userName string) (*entity.User, error) { + user := new(entity.User) + err := u.client(userName).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, user) }) - return + + return user, err } // Delete deletes a given User diff --git a/client/users.go b/client/users.go index dfc3686..eb921c9 100644 --- a/client/users.go +++ b/client/users.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // Users implements api.Users type Users struct { - ApiClient ApiClient + APIClient APIClient } -func (u *Users) client() ApiClient { - return u.ApiClient.GetSubObject("users") +func (u *Users) client() APIClient { + return u.APIClient.GetSubObject("users") } // Get fetches a list of User objects -func (u *Users) Get() (users []entity.User, err error) { - err = u.client().Get("", url.Values{}, func(data []byte) error { +func (u *Users) Get() ([]entity.User, error) { + users := make([]entity.User, 0) + err := u.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &users) }) - return + + return users, err } // Create creates a new User -func (u *Users) Create(params *entity.UserParams) (user *entity.User, err error) { +func (u *Users) Create(params *entity.UserParams) (*entity.User, error) { qsp, err := query.Values(params) if err != nil { return nil, err } - user = new(entity.User) + + user := new(entity.User) err = u.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, user) }) - return + + return user, err } diff --git a/client/utils.go b/client/utils.go index 3d0a443..d87f404 100644 --- a/client/utils.go +++ b/client/utils.go @@ -33,5 +33,6 @@ func powerParamsToURLValues(params map[string]interface{}) url.Values { } } } + return qsp } diff --git a/client/utils_test.go b/client/utils_test.go index 587f8f9..b92e941 100644 --- a/client/utils_test.go +++ b/client/utils_test.go @@ -57,6 +57,7 @@ func TestPowerParamsToURLValues(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() + res := powerParamsToURLValues(tc.in).Encode() assert.Equal(t, tc.out, res) }) diff --git a/client/vlan.go b/client/vlan.go index da5caef..65b6539 100644 --- a/client/vlan.go +++ b/client/vlan.go @@ -11,11 +11,11 @@ import ( // VLAN implements api.VLAN type VLAN struct { - ApiClient ApiClient + APIClient APIClient } -func (v *VLAN) client(fabricID int, vid int) ApiClient { - return v.ApiClient. +func (v *VLAN) client(fabricID int, vid int) APIClient { + return v.APIClient. GetSubObject("fabrics"). GetSubObject(fmt.Sprintf("%v", fabricID)). GetSubObject("vlans"). @@ -23,25 +23,28 @@ func (v *VLAN) client(fabricID int, vid int) ApiClient { } // Get fetches a VLAN by fabric id and VLAN id -func (v *VLAN) Get(fabricID int, vid int) (vlan *entity.VLAN, err error) { - vlan = new(entity.VLAN) - err = v.client(fabricID, vid).Get("", url.Values{}, func(data []byte) error { +func (v *VLAN) Get(fabricID int, vid int) (*entity.VLAN, error) { + vlan := new(entity.VLAN) + err := v.client(fabricID, vid).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, vlan) }) - return + + return vlan, err } // Update updates a given VLAN -func (v *VLAN) Update(fabricID int, vid int, params *entity.VLANParams) (vlan *entity.VLAN, err error) { +func (v *VLAN) Update(fabricID int, vid int, params *entity.VLANParams) (*entity.VLAN, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - vlan = new(entity.VLAN) + + vlan := new(entity.VLAN) err = v.client(fabricID, vid).Put(qsp, func(data []byte) error { return json.Unmarshal(data, vlan) }) - return + + return vlan, err } // Delete deletes a given VLAN diff --git a/client/vlans.go b/client/vlans.go index d919dd6..e2fd2bd 100644 --- a/client/vlans.go +++ b/client/vlans.go @@ -11,30 +11,34 @@ import ( // VLANs implements api.VLANs type VLANs struct { - ApiClient ApiClient + APIClient APIClient } -func (v *VLANs) client(fabricID int) ApiClient { - return v.ApiClient.GetSubObject("fabrics").GetSubObject(fmt.Sprintf("%v", fabricID)).GetSubObject("vlans") +func (v *VLANs) client(fabricID int) APIClient { + return v.APIClient.GetSubObject("fabrics").GetSubObject(fmt.Sprintf("%v", fabricID)).GetSubObject("vlans") } // Get fetches a list of VLAN objects -func (v *VLANs) Get(fabricID int) (vlans []entity.VLAN, err error) { - err = v.client(fabricID).Get("", url.Values{}, func(data []byte) error { +func (v *VLANs) Get(fabricID int) ([]entity.VLAN, error) { + vlans := make([]entity.VLAN, 0) + err := v.client(fabricID).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &vlans) }) - return + + return vlans, err } // Create creates a new VLAN -func (v *VLANs) Create(fabricID int, params *entity.VLANParams) (vlan *entity.VLAN, err error) { +func (v *VLANs) Create(fabricID int, params *entity.VLANParams) (*entity.VLAN, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - vlan = new(entity.VLAN) + + vlan := new(entity.VLAN) err = v.client(fabricID).Post("", qsp, func(data []byte) error { return json.Unmarshal(data, vlan) }) - return + + return vlan, err } diff --git a/client/vm_host.go b/client/vm_host.go index a4c3d43..86872d6 100644 --- a/client/vm_host.go +++ b/client/vm_host.go @@ -12,69 +12,74 @@ import ( // VMHost contains functionality for manipulating the VMHost entity. type VMHost struct { - ApiClient ApiClient + APIClient APIClient mutex sync.Mutex } -func (p *VMHost) client(id int) ApiClient { - return p.ApiClient.GetSubObject("pods").GetSubObject(fmt.Sprintf("%v", id)) +func (p *VMHost) client(id int) APIClient { + return p.APIClient.GetSubObject("pods").GetSubObject(fmt.Sprintf("%v", id)) } // Get fetches a given VMHost -func (p *VMHost) Get(id int) (vmHost *entity.VMHost, err error) { - vmHost = new(entity.VMHost) - err = p.client(id).Get("", url.Values{}, func(data []byte) error { +func (p *VMHost) Get(id int) (*entity.VMHost, error) { + vmHost := new(entity.VMHost) + err := p.client(id).Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, vmHost) }) - return + + return vmHost, err } // Update updates a given VMHost -func (p *VMHost) Update(id int, params *entity.VMHostParams) (vmHost *entity.VMHost, err error) { +func (p *VMHost) Update(id int, params *entity.VMHostParams) (*entity.VMHost, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - vmHost = new(entity.VMHost) + + vmHost := new(entity.VMHost) err = p.client(id).Put(qsp, func(data []byte) error { return json.Unmarshal(data, vmHost) }) - return + + return vmHost, err } // Delete deletes a given VMHost -func (p *VMHost) Delete(id int) (err error) { - err = p.client(id).Delete() - return +func (p *VMHost) Delete(id int) error { + return p.client(id).Delete() } // Compose composes a VM on the given VMHost -func (p *VMHost) Compose(id int, params *entity.VMHostMachineParams) (machine *entity.Machine, err error) { +func (p *VMHost) Compose(id int, params *entity.VMHostMachineParams) (*entity.Machine, error) { p.mutex.Lock() defer p.mutex.Unlock() qsp, err := query.Values(params) if err != nil { - return + return nil, err } - machine = new(entity.Machine) + + machine := new(entity.Machine) err = p.client(id).Post("compose", qsp, func(data []byte) error { return json.Unmarshal(data, machine) }) - return + + return machine, err } // Refresh refreshes resource info and VM status of a given VMHost -func (p *VMHost) Refresh(id int) (vmHost *entity.VMHost, err error) { - err = p.client(id).Post("refresh", url.Values{}, func(data []byte) error { return nil }) - return +func (p *VMHost) Refresh(id int) (*entity.VMHost, error) { + err := p.client(id).Post("refresh", url.Values{}, func(data []byte) error { return nil }) + return nil, err } // GetParameters fetches the configured parameters of a given VMHost -func (p *VMHost) GetParameters(id int) (params map[string]string, err error) { - params = map[string]string{} - err = p.client(id).Get("parameters", url.Values{}, func(data []byte) error { +func (p *VMHost) GetParameters(id int) (map[string]string, error) { + params := map[string]string{} + err := p.client(id).Get("parameters", url.Values{}, func(data []byte) error { return json.Unmarshal(data, ¶ms) }) - return + + return params, err } diff --git a/client/vm_hosts.go b/client/vm_hosts.go index add4b76..dd6578d 100644 --- a/client/vm_hosts.go +++ b/client/vm_hosts.go @@ -1,3 +1,4 @@ +//nolint:dupl // disable dupl check on client for now package client import ( @@ -10,30 +11,34 @@ import ( // VMHosts contains functionality for manipulating the VMHosts entity. type VMHosts struct { - ApiClient ApiClient + APIClient APIClient } -func (p *VMHosts) client() ApiClient { - return p.ApiClient.GetSubObject("pods") +func (p *VMHosts) client() APIClient { + return p.APIClient.GetSubObject("pods") } // Get fetches a list of VMHost objects -func (p *VMHosts) Get() (vmHosts []entity.VMHost, err error) { - err = p.client().Get("", url.Values{}, func(data []byte) error { +func (p *VMHosts) Get() ([]entity.VMHost, error) { + vmHosts := make([]entity.VMHost, 0) + err := p.client().Get("", url.Values{}, func(data []byte) error { return json.Unmarshal(data, &vmHosts) }) - return + + return vmHosts, err } // Create creates a new VMHost -func (p *VMHosts) Create(params *entity.VMHostParams) (vmHost *entity.VMHost, err error) { +func (p *VMHosts) Create(params *entity.VMHostParams) (*entity.VMHost, error) { qsp, err := query.Values(params) if err != nil { - return + return nil, err } - vmHost = new(entity.VMHost) + + vmHost := new(entity.VMHost) err = p.client().Post("", qsp, func(data []byte) error { return json.Unmarshal(data, vmHost) }) - return + + return vmHost, err } diff --git a/entity/block_device.go b/entity/block_device.go index a8674ad..828ec85 100644 --- a/entity/block_device.go +++ b/entity/block_device.go @@ -1,37 +1,37 @@ package entity -// BlockDevice represents the MaaS BlockDevice endpoint. +// BlockDevice represents the MAAS BlockDevice endpoint. type BlockDevice struct { - BlockSize int `json:"block_size,omitempty"` - ID int `json:"id,omitempty"` - IDPath string `json:"id_path,omitempty"` - Model string `json:"model,omitempty"` - Name string `json:"name,omitempty"` + Filesystem PartitionFileSystem `json:"filesystem,omitempty"` Path string `json:"path,omitempty"` + Model string `json:"model,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + PartitionTableType string `json:"partition_table_type,omitempty"` + UUID string `json:"uuid,omitempty"` Serial string `json:"serial,omitempty"` - Size int64 `json:"size,omitempty"` - Tags []string `json:"tags,omitempty"` + IDPath string `json:"id_path,omitempty"` + UsedFor string `json:"used_for,omitempty"` FirmwareVersion string `json:"firmware_version,omitempty"` SystemID string `json:"system_id,omitempty"` - AvailableSize int64 `json:"available_size,omitempty"` - UsedSize int64 `json:"used_size,omitempty"` - PartitionTableType string `json:"partition_table_type,omitempty"` - Partitions []BlockDevicePartition `json:"partitions,omitempty"` - Filesystem PartitionFileSystem `json:"filesystem,omitempty"` StoragePool string `json:"storage_pool,omitempty"` - UsedFor string `json:"used_for,omitempty"` Type string `json:"type,omitempty"` - UUID string `json:"uuid,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + Name string `json:"name,omitempty"` + Partitions []BlockDevicePartition `json:"partitions,omitempty"` + Tags []string `json:"tags,omitempty"` + Size int64 `json:"size,omitempty"` + ID int `json:"id,omitempty"` + BlockSize int `json:"block_size,omitempty"` + UsedSize int64 `json:"used_size,omitempty"` + AvailableSize int64 `json:"available_size,omitempty"` NUMANode int `json:"numa_node,omitempty"` } type BlockDeviceParams struct { Name string `url:"name,omitempty"` - Size int64 `url:"size,omitempty"` - BlockSize int `url:"block_size,omitempty"` UUID string `url:"uuid,omitempty"` Model string `url:"model,omitempty"` Serial string `url:"serial,omitempty"` IDPath string `url:"id_path,omitempty"` + Size int64 `url:"size,omitempty"` + BlockSize int `url:"block_size,omitempty"` } diff --git a/entity/block_device_partition.go b/entity/block_device_partition.go index 79276ae..726e257 100644 --- a/entity/block_device_partition.go +++ b/entity/block_device_partition.go @@ -1,19 +1,19 @@ package entity -// BlockDevicePartition represents the MaaS block device partition endpoint. +// BlockDevicePartition represents the MAAS block device partition endpoint. type BlockDevicePartition struct { + FileSystem PartitionFileSystem `json:"filesystem"` UUID string `json:"uuid"` - Size int64 `json:"size"` - Bootable bool `json:"bootable"` - Tags []string `json:"tags,omitempty"` SystemID string `json:"system_id"` - ID int `json:"id"` - DeviceID int `json:"device_id"` - FileSystem PartitionFileSystem `json:"filesystem"` UsedFor string `json:"used_for,omitempty"` Type string `json:"type"` Path string `json:"path"` ResourceURI string `json:"resource_uri"` + Tags []string `json:"tags,omitempty"` + Size int64 `json:"size"` + ID int `json:"id"` + DeviceID int `json:"device_id"` + Bootable bool `json:"bootable"` } type PartitionFileSystem struct { @@ -25,7 +25,7 @@ type PartitionFileSystem struct { } type BlockDevicePartitionParams struct { - Size int64 `url:"size,omitempty"` UUID string `url:"uuid,omitempty"` + Size int64 `url:"size,omitempty"` Bootable bool `url:"bootable"` } diff --git a/entity/block_device_test.go b/entity/block_device_test.go index ffaf498..6ed5d87 100644 --- a/entity/block_device_test.go +++ b/entity/block_device_test.go @@ -14,6 +14,7 @@ func TestBlockDevicet(t *testing.T) { if err := helper.TestdataFromJSON("maas/block_device.json", device); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/block_devices.json", devices); err != nil { t.Fatal(err) } diff --git a/entity/device.go b/entity/device.go index 682e9aa..a003b5c 100644 --- a/entity/device.go +++ b/entity/device.go @@ -3,22 +3,22 @@ package entity import "net" type Device struct { - SystemID string `json:"system_id,omitempty"` - Hostname string `json:"hostname,omitempty"` - Description string `json:"description,omitempty"` - Domain Domain `json:"domain,omitempty"` + OwnerData interface{} `json:"owner_data,omitempty"` + Zone Zone `json:"zone,omitempty"` FQDN string `json:"fqdn,omitempty"` + Hostname string `json:"hostname,omitempty"` + SystemID string `json:"system_id,omitempty"` Owner string `json:"owner,omitempty"` - OwnerData interface{} `json:"owner_data,omitempty"` + Description string `json:"description,omitempty"` Parent string `json:"parent,omitempty"` - TagNames []string `json:"tag_names,omitempty"` - AddressTTL int `json:"address_ttl,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + NodeTypeName string `json:"node_type_name,omitempty"` IPAddresses []net.IP `json:"ip_addresses,omitempty"` InterfaceSet []NetworkInterface `json:"interface_set,omitempty"` - Zone Zone `json:"zone,omitempty"` + TagNames []string `json:"tag_names,omitempty"` + Domain Domain `json:"domain,omitempty"` NodeType int `json:"node_type,omitempty"` - NodeTypeName string `json:"node_type_name,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + AddressTTL int `json:"address_ttl,omitempty"` } type DeviceCreateParams struct { diff --git a/entity/dns_resource.go b/entity/dns_resource.go index 7d37ee9..d82abc4 100644 --- a/entity/dns_resource.go +++ b/entity/dns_resource.go @@ -1,18 +1,18 @@ package entity type DNSResource struct { - ID int `json:"id,omitempty"` - AddressTTL int `json:"address_ttl,omitempty"` FQDN string `json:"fqdn,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` IPAddresses []IPAddress `json:"ip_addresses,omitempty"` ResourceRecords []DNSResourceRecord `json:"resource_records,omitempty"` + ID int `json:"id,omitempty"` + AddressTTL int `json:"address_ttl,omitempty"` } type DNSResourceParams struct { - AddressTTL int `url:"address_ttl"` FQDN string `url:"fqdn,omitempty"` Name string `url:"name,omitempty"` Domain string `url:"domain,omitempty"` IPAddresses string `url:"ip_addresses,omitempty"` + AddressTTL int `url:"address_ttl"` } diff --git a/entity/dns_resource_record.go b/entity/dns_resource_record.go index 70a8738..cb2ad5a 100644 --- a/entity/dns_resource_record.go +++ b/entity/dns_resource_record.go @@ -1,12 +1,12 @@ package entity type DNSResourceRecord struct { - ID int `json:"id,omitempty"` - TTL int `json:"ttl,omitempty"` RRType string `json:"rrtype,omitempty"` RRData string `json:"rrdata,omitempty"` FQDN string `json:"fqdn,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + ID int `json:"id,omitempty"` + TTL int `json:"ttl,omitempty"` } type DNSResourceRecordParams struct { diff --git a/entity/domain.go b/entity/domain.go index 176d64a..4017172 100644 --- a/entity/domain.go +++ b/entity/domain.go @@ -1,6 +1,6 @@ package entity -// Domain represents the MaaS Domain endpoint +// Domain represents the MAAS Domain endpoint type Domain struct { Name string `json:"name,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` diff --git a/entity/entity.go b/entity/entity.go index d817866..1c81b21 100644 --- a/entity/entity.go +++ b/entity/entity.go @@ -1,4 +1,5 @@ -/*package entity defines types for the MaaS API endpoints' return types. +/* +Package entity defines types for the MAAS API endpoints' return types. Each endpoint returns JSON that describes the object it represents. For example, GETting the Subnets endpoint will return an array of Subnet, while GETting the @@ -7,5 +8,6 @@ Subnet endpoint (ie subnets/) will return one Subnet. Some endpoints expose operations that return metadata about the object, such as as Subnet's GetStatistics(), which contains statistics about the subnet, but does not actually describe the subnet: these alternative types can be found in subpackages -named after the endpoint.*/ +named after the endpoint. +*/ package entity diff --git a/entity/fabric.go b/entity/fabric.go index f90524a..db678ca 100644 --- a/entity/fabric.go +++ b/entity/fabric.go @@ -1,11 +1,11 @@ package entity type Fabric struct { - ID int `json:"id,omitempty"` - VLANs []VLAN `json:"vlans,omitempty"` Name string `json:"name,omitempty"` ClassType string `json:"class_type,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + VLANs []VLAN `json:"vlans,omitempty"` + ID int `json:"id,omitempty"` } type FabricParams struct { diff --git a/entity/ip_address.go b/entity/ip_address.go index 08ac153..e389639 100644 --- a/entity/ip_address.go +++ b/entity/ip_address.go @@ -3,21 +3,21 @@ package entity import "net" type IPAddress struct { - AllocType int `json:"alloc_type,omitempty"` AllocTypeName string `json:"alloc_type_name,omitempty"` Created string `json:"created,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + Owner User `json:"owner,omitempty"` IP net.IP `json:"ip,omitempty"` - Subnet Subnet `json:"subnet,omitempty"` InterfaceSet []NetworkInterface `json:"interface_set,omitempty"` - Owner User `json:"owner,omitempty"` + Subnet Subnet `json:"subnet,omitempty"` + AllocType int `json:"alloc_type,omitempty"` } type IPAddressesParams struct { - All bool `url:"all,omitempty"` - Discovered bool `url:"discovered,omitempty"` - Force bool `url:"force,omitempty"` Subnet string `url:"subnet,omitempty"` IP string `url:"ip,omitempty"` Owner string `url:"owner,omitempty"` + All bool `url:"all,omitempty"` + Discovered bool `url:"discovered,omitempty"` + Force bool `url:"force,omitempty"` } diff --git a/entity/ip_range.go b/entity/ip_range.go index 624f191..f0c439a 100644 --- a/entity/ip_range.go +++ b/entity/ip_range.go @@ -5,14 +5,14 @@ import ( ) type IPRange struct { - ID int `json:"id"` Type string `json:"type"` + Comment string `json:"comment,omitempty"` + ResourceURI string `json:"resource_uri"` + User User `json:"user,omitempty"` StartIP net.IP `json:"start_ip"` EndIP net.IP `json:"end_ip"` Subnet Subnet `json:"subnet"` - User User `json:"user,omitempty"` - Comment string `json:"comment,omitempty"` - ResourceURI string `json:"resource_uri"` + ID int `json:"id"` } type IPRangeParams struct { diff --git a/entity/machine.go b/entity/machine.go index ea9e333..ea0f59a 100644 --- a/entity/machine.go +++ b/entity/machine.go @@ -10,13 +10,52 @@ import ( "github.com/maas/gomaasclient/entity/node" ) -// Machine represents the MaaS Machine endpoint. +// Machine represents the MAAS Machine endpoint. type Machine struct { - BootInterface NetworkInterface `json:"boot_interface,omitempty"` - VMHost VMHost `json:"pod,omitempty"` - BootDisk BlockDevice `json:"boot_disk,omitempty"` - Domain Domain `json:"domain,omitempty"` - DefaultGateways struct { + HwNextSync MAASTime `json:"next_sync,omitempty"` + HwLastSync MAASTime `json:"last_sync,omitempty"` + OwnerData interface{} `json:"owner_data,omitempty"` + HardwareInfo map[string]string `json:"hardware_info,omitempty"` + OSystem string `json:"osystem,omitempty"` + FQDN string `json:"fqdn,omitempty"` + StatusName string `json:"status_name,omitempty"` + StatusMessage string `json:"status_message,omitempty"` + StatusAction string `json:"status_action,omitempty"` + Description string `json:"description,omitempty"` + CPUTestStatusName string `json:"cpu_test_status_name,omitempty"` + OtherTestStatusName string `json:"other_test_status_name,omitempty"` + Hostname string `json:"hostname,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + Architecture string `json:"architecture,omitempty"` + PowerType string `json:"power_type,omitempty"` + MemoryTestStatusName string `json:"memory_test_status_name,omitempty"` + PowerState string `json:"power_state,omitempty"` + DistroSeries string `json:"distro_series,omitempty"` + MinHWEKernel string `json:"min_hwe_kernel,omitempty"` + CommissioningStatusName string `json:"commissioning_status_name,omitempty"` + SystemID string `json:"system_id,omitempty"` + NodeTypeName string `json:"node_type_name,omitempty"` + StorageTestStatusName string `json:"storage_test_status_name,omitempty"` + Owner string `json:"owner,omitempty"` + HWEKernel string `json:"hwe_kernel,omitempty"` + TestingStatusName string `json:"testing_status_name,omitempty"` + Version string `json:"version,omitempty"` + Pool ResourcePool `json:"pool,omitempty"` + Zone Zone `json:"zone,omitempty"` + SpecialFilesystems []MachineSpecialFilesystem `json:"special_filesystems,omitempty"` + VirtualBlockDeviceSet []BlockDevice `json:"virtualblockdevice_set,omitempty"` + ISCSIBlockDeviceSet []BlockDevice `json:"iscsiblockdevice_set,omitempty"` + ServiceSet []MachineServiceSet `json:"service_set,omitempty"` + PhysicalBlockDeviceSet []BlockDevice `json:"physicalblockdevice_set,omitempty"` + TagNames []string `json:"tag_names,omitempty"` + RAIDs []MachineRAID `json:"raids,omitempty"` + IPAddresses []net.IP `json:"ip_addresses,omitempty"` + BCaches []MachineBCache `json:"bcaches,omitempty"` + InterfaceSet []NetworkInterface `json:"interface_set,omitempty"` + VolumeGroups []MachineVolumeGroup `json:"volume_groups,omitempty"` + CacheSets []MachineCacheSet `json:"cache_sets,omitempty"` + BlockDeviceSet []BlockDevice `json:"blockdevice_set,omitempty"` + DefaultGateways struct { IPv4 struct { GatewayIP net.IP `json:"gateway_ip,omitempty"` LinkID int `json:"link_id,omitempty"` @@ -26,71 +65,32 @@ type Machine struct { LinkID int `json:"link_id,omitempty"` } `json:"ipv6,omitempty"` } `json:"default_gateways,omitempty"` - Pool ResourcePool `json:"pool,omitempty"` - Zone Zone `json:"zone,omitempty"` - TagNames []string `json:"tag_names,omitempty"` - IPAddresses []net.IP `json:"ip_addresses,omitempty"` - BlockDeviceSet []BlockDevice `json:"blockdevice_set,omitempty"` - CacheSets []MachineCacheSet `json:"cache_sets,omitempty"` - VolumeGroups []MachineVolumeGroup `json:"volume_groups,omitempty"` - InterfaceSet []NetworkInterface `json:"interface_set,omitempty"` - BCaches []MachineBCache `json:"bcaches,omitempty"` - RAIDs []MachineRAID `json:"raids,omitempty"` - SpecialFilesystems []MachineSpecialFilesystem `json:"special_filesystems,omitempty"` - ServiceSet []MachineServiceSet `json:"service_set,omitempty"` - PhysicalBlockDeviceSet []BlockDevice `json:"physicalblockdevice_set,omitempty"` - ISCSIBlockDeviceSet []BlockDevice `json:"iscsiblockdevice_set,omitempty"` - VirtualBlockDeviceSet []BlockDevice `json:"virtualblockdevice_set,omitempty"` - FQDN string `json:"fqdn,omitempty"` - DistroSeries string `json:"distro_series,omitempty"` - MinHWEKernel string `json:"min_hwe_kernel,omitempty"` - CommissioningStatusName string `json:"commissioning_status_name,omitempty"` - SystemID string `json:"system_id,omitempty"` - NodeTypeName string `json:"node_type_name,omitempty"` - StorageTestStatusName string `json:"storage_test_status_name,omitempty"` - Owner string `json:"owner,omitempty"` - HWEKernel string `json:"hwe_kernel,omitempty"` - TestingStatusName string `json:"testing_status_name,omitempty"` - Version string `json:"version,omitempty"` - Architecture string `json:"architecture,omitempty"` - PowerState string `json:"power_state,omitempty"` - MemoryTestStatusName string `json:"memory_test_status_name,omitempty"` - PowerType string `json:"power_type,omitempty"` - OwnerData interface{} `json:"owner_data,omitempty"` - Hostname string `json:"hostname,omitempty"` - EnableHwSync bool `json:"enable_hw_sync,omitempty"` - HwLastSync MAASTime `json:"last_sync,omitempty"` - HwSyncInterval int `json:"sync_interval,omitempty"` - HwNextSync MAASTime `json:"next_sync,omitempty"` - Description string `json:"description,omitempty"` - StatusAction string `json:"status_action,omitempty"` - StatusMessage string `json:"status_message,omitempty"` - StatusName string `json:"status_name,omitempty"` - OSystem string `json:"osystem,omitempty"` - CPUTestStatusName string `json:"cpu_test_status_name,omitempty"` - OtherTestStatusName string `json:"other_test_status_name,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` - Memory int64 `json:"memory,omitempty"` - NodeType int `json:"node_type,omitempty"` - CurrentCommissioningResultID int `json:"current_commissioning_result_id,omitempty"` - CPUTestStatus int `json:"cpu_test_status,omitempty"` - AddressTTL int `json:"address_ttl,omitempty"` - Storage float64 `json:"storage,omitempty"` - HardwareInfo map[string]string `json:"hardware_info,omitempty"` - CPUCount int `json:"cpu_count,omitempty"` - Status node.Status `json:"status,omitempty"` - CurrentInstallationResultID int `json:"current_installation_result_id,omitempty"` - CurrentTestingResultID int `json:"current_testing_result_id,omitempty"` - CommissioningStatus int `json:"commissioning_status,omitempty"` - OtherTestStatus int `json:"other_test_status,omitempty"` - TestingStatus int `json:"testing_status,omitempty"` - StorageTestStatus int `json:"storage_test_status,omitempty"` - SwapSize int64 `json:"swap_size,omitempty"` - MemoryTestStatus int `json:"memory_test_status,omitempty"` - CPUSpeed int `json:"cpu_speed,omitempty"` - DisableIPv4 bool `json:"disable_ipv4,omitempty"` - Netboot bool `json:"netboot,omitempty"` - Locked bool `json:"locked,omitempty"` + Domain Domain `json:"domain,omitempty"` + BootDisk BlockDevice `json:"boot_disk,omitempty"` + BootInterface NetworkInterface `json:"boot_interface,omitempty"` + VMHost VMHost `json:"pod,omitempty"` + CurrentTestingResultID int `json:"current_testing_result_id,omitempty"` + Memory int64 `json:"memory,omitempty"` + NodeType int `json:"node_type,omitempty"` + HwSyncInterval int `json:"sync_interval,omitempty"` + CPUTestStatus int `json:"cpu_test_status,omitempty"` + AddressTTL int `json:"address_ttl,omitempty"` + Storage float64 `json:"storage,omitempty"` + CPUSpeed int `json:"cpu_speed,omitempty"` + CPUCount int `json:"cpu_count,omitempty"` + Status node.Status `json:"status,omitempty"` + CurrentInstallationResultID int `json:"current_installation_result_id,omitempty"` + CurrentCommissioningResultID int `json:"current_commissioning_result_id,omitempty"` + CommissioningStatus int `json:"commissioning_status,omitempty"` + OtherTestStatus int `json:"other_test_status,omitempty"` + TestingStatus int `json:"testing_status,omitempty"` + StorageTestStatus int `json:"storage_test_status,omitempty"` + SwapSize int64 `json:"swap_size,omitempty"` + MemoryTestStatus int `json:"memory_test_status,omitempty"` + EnableHwSync bool `json:"enable_hw_sync,omitempty"` + DisableIPv4 bool `json:"disable_ipv4,omitempty"` + Netboot bool `json:"netboot,omitempty"` + Locked bool `json:"locked,omitempty"` } func (m *Machine) UnmarshalJSON(data []byte) error { @@ -129,7 +129,9 @@ func (t *MAASTime) UnmarshalJSON(data []byte) error { if err != nil { return err } + *t = MAASTime(temp) + return nil } @@ -144,7 +146,7 @@ func (t MAASTime) String() string { type MachineCacheSet struct { SystemID string `json:"system_id,omitempty"` ID int `json:"id,omitempty"` - Incomplete bool `json:"__incomplete__,omitempty"` + Incomplete bool `json:"__incomplete__,omitempty"` //nolint:tagliatelle // MAAS returns this field intentionally } // MachineVolumeGroup represents a Machine's "volume_groups" list item. @@ -152,7 +154,7 @@ type MachineCacheSet struct { type MachineVolumeGroup struct { SystemID string `json:"system_id,omitempty"` ID int `json:"id,omitempty"` - Incomplete bool `json:"__incomplete__,omitempty"` + Incomplete bool `json:"__incomplete__,omitempty"` //nolint:tagliatelle // MAAS returns this field intentionally } // MachineBCache represents a Machine's "bcaches" list item. @@ -160,7 +162,7 @@ type MachineVolumeGroup struct { type MachineBCache struct { SystemID string `json:"system_id,omitempty"` ID int `json:"id,omitempty"` - Incomplete bool `json:"__incomplete__,omitempty"` + Incomplete bool `json:"__incomplete__,omitempty"` //nolint:tagliatelle // MAAS returns this field intentionally } // MachineRAID represents a Machine's "raids" list item. @@ -168,7 +170,7 @@ type MachineBCache struct { type MachineRAID struct { SystemID string `json:"system_id,omitempty"` ID int `json:"id,omitempty"` - Incomplete bool `json:"__incomplete__,omitempty"` + Incomplete bool `json:"__incomplete__,omitempty"` //nolint:tagliatelle // MAAS returns this field intentionally } // MachineSpecialFilesystem represents a Machine's "special_filesystems" list item. @@ -191,56 +193,56 @@ type MachineServiceSet struct { // MachineParams enumerates the parameters for the machine update operation type MachineParams struct { - CPUCount int `url:"cpu_count,omitempty"` - Memory int64 `url:"memory,omitempty"` - SwapSize int64 `url:"swap_size,omitempty"` + PowerType string `url:"power_type,omitempty"` PXEMacAddress string `url:"mac_addresses,omitempty"` Architecture string `url:"architecture,omitempty"` MinHWEKernel string `url:"min_hwe_kernel,omitempty"` - PowerType string `url:"power_type,omitempty"` Hostname string `url:"hostname,omitempty"` Description string `url:"description,omitempty"` Domain string `url:"domain,omitempty"` Pool string `url:"pool,omitempty"` Zone string `url:"zone,omitempty"` + Memory int64 `url:"memory,omitempty"` + SwapSize int64 `url:"swap_size,omitempty"` + CPUCount int `url:"cpu_count,omitempty"` Commission bool `url:"commission,omitempty"` } // MachineCommissionParams enumerates the parameters for the commission operation type MachineCommissionParams struct { + CommissioningScripts string `url:"commissioning_scripts,omitempty"` + TestingScripts string `url:"testing_scripts,omitempty"` EnableSSH int `url:"enable_ssh,omitempty"` SkipBMCConfig int `url:"skip_bmc_config,omitempty"` SkipNetworking int `url:"skip_networking,omitempty"` SkipStorage int `url:"skip_storage,omitempty"` - CommissioningScripts string `url:"commissioning_scripts,omitempty"` - TestingScripts string `url:"testing_scripts,omitempty"` } // MachineAllocateParams enumerates the options for the allocate operation. type MachineAllocateParams struct { + AgentName string `url:"agent_name,omitempty"` + SystemID string `url:"system_id,omitempty"` + Pool string `url:"pool,omitempty"` + Zone string `url:"zone,omitempty"` + Comment string `url:"comment,omitempty"` + Interfaces string `url:"interfaces,omitempty"` + NotVMHostType string `url:"not_pod_type,omitempty"` + VMHostType string `url:"pod_type,omitempty"` + NotVMHost string `url:"not_pod,omitempty"` + VMHost string `url:"pod,omitempty"` + Arch string `url:"arch,omitempty"` + Name string `url:"name,omitempty"` + NotFabrics []string `url:"not_fabrics,omitempty"` Tags []string `url:"tags,omitempty"` - NotTags []string `url:"not_tags,omitempty"` - NotInZone []string `url:"not_in_zone,omitempty"` NotInPool []string `url:"not_in_pool,omitempty"` - Subnets []string `url:"subnets,omitempty"` - NotSubnets []string `url:"not_subnets,omitempty"` - Storage []string `url:"storage,omitempty"` - Fabrics []string `url:"fabrics,omitempty"` - NotFabrics []string `url:"not_fabrics,omitempty"` + NotInZone []string `url:"not_in_zone,omitempty"` FabricClasses []string `url:"fabric_classes,omitempty"` + NotTags []string `url:"not_tags,omitempty"` + Fabrics []string `url:"fabrics,omitempty"` + Storage []string `url:"storage,omitempty"` + NotSubnets []string `url:"not_subnets,omitempty"` NotFabricClasses []string `url:"not_fabric_classes,omitempty"` - Name string `url:"name,omitempty"` - SystemID string `url:"system_id,omitempty"` - Arch string `url:"arch,omitempty"` - Zone string `url:"zone,omitempty"` - Pool string `url:"pool,omitempty"` - VMHost string `url:"pod,omitempty"` - NotVMHost string `url:"not_pod,omitempty"` - VMHostType string `url:"pod_type,omitempty"` - NotVMHostType string `url:"not_pod_type,omitempty"` - Interfaces string `url:"interfaces,omitempty"` - AgentName string `url:"agent_name,omitempty"` - Comment string `url:"comment,omitempty"` + Subnets []string `url:"subnets,omitempty"` CPUCount int `url:"cpu_count,omitempty"` Mem int64 `url:"mem,omitempty"` BridgeFD int `url:"bridge_fd,omitempty"` diff --git a/entity/machine_test.go b/entity/machine_test.go index 1388164..379cbb9 100644 --- a/entity/machine_test.go +++ b/entity/machine_test.go @@ -16,6 +16,7 @@ func TestMachinet(t *testing.T) { if err := helper.TestdataFromJSON("maas/machine.json", machine); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/machines.json", machines); err != nil { t.Fatal(err) } @@ -73,11 +74,13 @@ func TestMachineWithDeducedHwSync(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() + machine := Machine{} if err := json.Unmarshal(tc.in, &machine); err != nil { t.Fatal(err, string(tc.in)) } + if tc.out != machine.EnableHwSync { t.Fatalf("expected %v, got %v", tc.out, machine.EnableHwSync) } diff --git a/entity/network_interface.go b/entity/network_interface.go index 50a0c74..dc69fb4 100644 --- a/entity/network_interface.go +++ b/entity/network_interface.go @@ -1,30 +1,30 @@ package entity -// NetworkInterface represents the MaaS Interface endpoint. +// NetworkInterface represents the MAAS Interface endpoint. type NetworkInterface struct { - Children []string `json:"children,omitempty"` - Discovered []NetworkInterfaceDiscoveredIP `json:"discovered,omitempty"` - EffectiveMTU int `json:"effective_mtu,omitempty"` - Enabled bool `json:"enabled,omitempty"` - FirmwareVersion string `json:"firmware_version,omitempty"` - ID int `json:"id,omitempty"` - InterfaceSpeed int `json:"interface_speed,omitempty"` - LinkConnected bool `json:"link_connected,omitempty"` - Links []NetworkInterfaceLink `json:"links,omitempty"` - LinkSpeed int `json:"link_speed,omitempty"` - MACAddress string `json:"mac_address,omitempty"` - Name string `json:"name,omitempty"` - NUMANode int `json:"numa_node,omitempty"` Params interface{} `json:"params,omitempty"` - Parents []string `json:"parents,omitempty"` + Name string `json:"name,omitempty"` Product string `json:"product,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` - SRIOVMaxVF int `json:"sriov_max_vf,omitempty"` + MACAddress string `json:"mac_address,omitempty"` + FirmwareVersion string `json:"firmware_version,omitempty"` + Vendor string `json:"vendor,omitempty"` + Type string `json:"type,omitempty"` SystemID string `json:"system_id,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + Links []NetworkInterfaceLink `json:"links,omitempty"` + Parents []string `json:"parents,omitempty"` + Children []string `json:"children,omitempty"` Tags []string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Vendor string `json:"vendor,omitempty"` + Discovered []NetworkInterfaceDiscoveredIP `json:"discovered,omitempty"` VLAN VLAN `json:"vlan,omitempty"` + NUMANode int `json:"numa_node,omitempty"` + LinkSpeed int `json:"link_speed,omitempty"` + EffectiveMTU int `json:"effective_mtu,omitempty"` + SRIOVMaxVF int `json:"sriov_max_vf,omitempty"` + InterfaceSpeed int `json:"interface_speed,omitempty"` + ID int `json:"id,omitempty"` + Enabled bool `json:"enabled,omitempty"` + LinkConnected bool `json:"link_connected,omitempty"` } // NetworkInterfaceDiscoveredIP is consumed by NetworkInterface{} and should not be used directly. @@ -35,10 +35,10 @@ type NetworkInterfaceDiscoveredIP struct { // NetworkInterfaceLink is consumed by NetworkInterface{} and should not be used directly. type NetworkInterfaceLink struct { - ID int `json:"id,omitempty"` IPAddress string `json:"ip_address,omitempty"` Mode string `json:"mode,omitempty"` Subnet Subnet `json:"subnet,omitempty"` + ID int `json:"id,omitempty"` } // NetworkInterfaceLinkParams is used with NetworkInterface.LinkSubnet(). @@ -49,111 +49,111 @@ type NetworkInterfaceLink struct { // DefaultGateway is ignored unless Mode is AUTO or STATIC. // Note: You can parse an IP address into a net.IP via net.ParseIP(string). type NetworkInterfaceLinkParams struct { - DefaultGateway bool `url:"default_gateway"` - Force bool `url:"force,omitempty"` IPAddress string `url:"ip_address,omitempty"` Mode string `url:"mode,omitempty"` Subnet int `url:"subnet,omitempty"` + DefaultGateway bool `url:"default_gateway"` + Force bool `url:"force,omitempty"` } // NetworkInterfacePhysicalParams is the parameters for the NetworkInterfaces create_physical POST operation. type NetworkInterfacePhysicalParams struct { - AcceptRA bool `url:"accept_ra,omitempty"` - Enabled bool `url:"enabled,omitempty"` - InterfaceSpeed int `url:"interface_speed,omitempty"` + Name string `url:"name,omitempty"` IPAddress string `url:"ip_address,omitempty"` IPAssignment string `url:"ip_assignment,omitempty"` - LinkConnected bool `url:"link_connected,omitempty"` - LinkSpeed int `url:"link_speed,omitempty"` MACAddress string `url:"mac_address,omitempty"` + Tags string `url:"tags,omitempty"` + InterfaceSpeed int `url:"interface_speed,omitempty"` + LinkSpeed int `url:"link_speed,omitempty"` MTU int `url:"mtu,omitempty"` - Name string `url:"name,omitempty"` NUMANode int `url:"numa_node,omitempty"` VLAN int `url:"vlan,omitempty"` - Tags string `url:"tags,omitempty"` + Enabled bool `url:"enabled,omitempty"` + LinkConnected bool `url:"link_connected,omitempty"` + AcceptRA bool `url:"accept_ra,omitempty"` } // NetworkInterfaceBondParams is the parameters for the NetworkInterfaces create_bond POST operation. type NetworkInterfaceBondParams struct { - AcceptRA bool `url:"accept_ra,omitempty"` - BondDownDelay int `url:"bond_downdelay,omitempty"` + IPAddress string `url:"ip_address,omitempty"` + Tags string `url:"tags,omitempty"` BondLACPRate string `url:"bond_lacp_rate,omitempty"` - BondMiimon int `url:"bond_miimon,omitempty"` BondMode string `url:"bond_mode,omitempty"` - BondNumberGratARP int `url:"bond_num_grat_arp,omitempty"` - BondUpDelay int `url:"bond_updelay,omitempty"` + Name string `url:"name,omitempty"` + MACAddress string `url:"mac_address,omitempty"` BondXMitHashPolicy string `url:"bond_xmit_hash_policy,omitempty"` - InterfaceSpeed int `url:"interface_speed,omitempty"` - IPAddress string `url:"ip_address,omitempty"` IPAssignment string `url:"ip_assignment,omitempty"` - LinkConnected bool `url:"link_connected,omitempty"` + Parents []int `url:"parents,omitempty"` + InterfaceSpeed int `url:"interface_speed,omitempty"` LinkSpeed int `url:"link_speed,omitempty"` - MACAddress string `url:"mac_address,omitempty"` + BondUpDelay int `url:"bond_updelay,omitempty"` MTU int `url:"mtu,omitempty"` - Name string `url:"name,omitempty"` - Parents []int `url:"parents,omitempty"` - Tags string `url:"tags,omitempty"` + BondNumberGratARP int `url:"bond_num_grat_arp,omitempty"` + BondMiimon int `url:"bond_miimon,omitempty"` + BondDownDelay int `url:"bond_downdelay,omitempty"` VLAN int `url:"vlan,omitempty"` + AcceptRA bool `url:"accept_ra,omitempty"` + LinkConnected bool `url:"link_connected,omitempty"` } // NetworkInterfaceBridgeParams is the parameters for the NetworkInterfaces create_bridge POST operation. type NetworkInterfaceBridgeParams struct { - AcceptRA bool `url:"accept_ra,omitempty"` - BridgeFD int `url:"bridge_fd,omitempty"` - BridgeSTP bool `url:"bridge_stp,omitempty"` - BridgeType string `url:"bridge_type,omitempty"` - InterfaceSpeed int `url:"interface_speed,omitempty"` - IPAddress string `url:"ip_address,omitempty"` IPAssignment string `url:"ip_assignment,omitempty"` - LinkConnected bool `url:"link_connected,omitempty"` - LinkSpeed int `url:"link_speed,omitempty"` MACAddress string `url:"mac_address,omitempty"` - MTU int `url:"mtu,omitempty"` + Tags string `url:"tags,omitempty"` + BridgeType string `url:"bridge_type,omitempty"` + IPAddress string `url:"ip_address,omitempty"` Name string `url:"name,omitempty"` Parents []int `url:"parents,omitempty"` - Tags string `url:"tags,omitempty"` + LinkSpeed int `url:"link_speed,omitempty"` + MTU int `url:"mtu,omitempty"` + BridgeFD int `url:"bridge_fd,omitempty"` + InterfaceSpeed int `url:"interface_speed,omitempty"` VLAN int `url:"vlan,omitempty"` + AcceptRA bool `url:"accept_ra,omitempty"` + LinkConnected bool `url:"link_connected,omitempty"` + BridgeSTP bool `url:"bridge_stp,omitempty"` } // NetworkInterfaceVLANParams is the parameters for the NetworkInterfaces create_vlan POST operation. type NetworkInterfaceVLANParams struct { - AcceptRA bool `url:"accept_ra,omitempty"` - InterfaceSpeed int `url:"interface_speed,omitempty"` IPAddress string `url:"ip_address,omitempty"` IPAssignment string `url:"ip_assignment,omitempty"` - LinkConnected bool `url:"link_connected,omitempty"` - LinkSpeed int `url:"link_speed,omitempty"` - MTU int `url:"mtu,omitempty"` Name string `url:"name,omitempty"` - Parents []int `url:"parents,omitempty"` Tags string `url:"tags,omitempty"` + Parents []int `url:"parents,omitempty"` + InterfaceSpeed int `url:"interface_speed,omitempty"` + LinkSpeed int `url:"link_speed,omitempty"` + MTU int `url:"mtu,omitempty"` VLAN int `url:"vlan,omitempty"` + AcceptRA bool `url:"accept_ra,omitempty"` + LinkConnected bool `url:"link_connected,omitempty"` } // NetworkInterfaceUpdateParams is the parameters for the NetworkInterfaces update_bond POST operation. type NetworkInterfaceUpdateParams struct { - AcceptRA bool `url:"accept_ra,omitempty"` - BondDownDelay int `url:"bond_downdelay,omitempty"` + BridgeType string `url:"bridge_type,omitempty"` + Tags string `url:"tags,omitempty"` BondLACPRate string `url:"bond_lacp_rate,omitempty"` - BondMiimon int `url:"bond_miimon,omitempty"` BondMode string `url:"bond_mode,omitempty"` - BondNumberGratARP int `url:"bond_num_grat_arp,omitempty"` - BondUpDelay int `url:"bond_updelay,omitempty"` + Name string `url:"name,omitempty"` + MACAddress string `url:"mac_address,omitempty"` BondXMitHashPolicy string `url:"bond_xmit_hash_policy,omitempty"` - BridgeFD int `url:"bridge_fd,omitempty"` - BridgeSTP bool `url:"bridge_stp,omitempty"` - BridgeType string `url:"bridge_type,omitempty"` - Enabled bool `url:"enabled,omitempty"` - InterfaceSpeed int `url:"interface_speed,omitempty"` - IPAddress string `url:"ip_address,omitempty"` IPAssignment string `url:"ip_assignment,omitempty"` - LinkConnected bool `url:"link_connected,omitempty"` - LinkSpeed int `url:"link_speed,omitempty"` - MACAddress string `url:"mac_address,omitempty"` - MTU int `url:"mtu,omitempty"` - Name string `url:"name,omitempty"` - NUMANode int `url:"numa_node,omitempty"` + IPAddress string `url:"ip_address,omitempty"` Parents []int `url:"parents,omitempty"` - Tags string `url:"tags,omitempty"` + InterfaceSpeed int `url:"interface_speed,omitempty"` + BondUpDelay int `url:"bond_updelay,omitempty"` VLAN int `url:"vlan,omitempty"` + BondDownDelay int `url:"bond_downdelay,omitempty"` + BridgeFD int `url:"bridge_fd,omitempty"` + BondMiimon int `url:"bond_miimon,omitempty"` + LinkSpeed int `url:"link_speed,omitempty"` + NUMANode int `url:"numa_node,omitempty"` + MTU int `url:"mtu,omitempty"` + BondNumberGratARP int `url:"bond_num_grat_arp,omitempty"` + Enabled bool `url:"enabled,omitempty"` + LinkConnected bool `url:"link_connected,omitempty"` + BridgeSTP bool `url:"bridge_stp,omitempty"` + AcceptRA bool `url:"accept_ra,omitempty"` } diff --git a/entity/network_interface_test.go b/entity/network_interface_test.go index 08f7766..c65bffd 100644 --- a/entity/network_interface_test.go +++ b/entity/network_interface_test.go @@ -498,6 +498,7 @@ func TestNetworkInterface(t *testing.T) { if err := helper.TestdataFromJSON("maas/interface.json", ifc); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/interfaces.json", ifcs); err != nil { t.Fatal(err) } @@ -506,6 +507,7 @@ func TestNetworkInterface(t *testing.T) { if diff := cmp.Diff(&sampleNetworkInterface, ifc); diff != "" { t.Fatalf("json.Decode(NetworkInterface) mismatch (-want +got):\n%s", diff) } + if diff := cmp.Diff(&sampleNetworkInterfaces, ifcs); diff != "" { t.Fatalf("json.Decode([]NetworkInterface) mismatch (-want +got):\n%s", diff) } diff --git a/entity/node.go b/entity/node.go index 1dceac7..5208c3b 100644 --- a/entity/node.go +++ b/entity/node.go @@ -1,4 +1,4 @@ package entity -// Node represents the MaaS Node endpoint. +// Node represents the MAAS Node endpoint. type Node Machine diff --git a/entity/node/node.go b/entity/node/node.go new file mode 100644 index 0000000..df53452 --- /dev/null +++ b/entity/node/node.go @@ -0,0 +1,2 @@ +// Package node contains entities related to nodes. +package node diff --git a/entity/node_test.go b/entity/node_test.go index 7ff51f5..79a128e 100644 --- a/entity/node_test.go +++ b/entity/node_test.go @@ -14,6 +14,7 @@ func TestNodet(t *testing.T) { if err := helper.TestdataFromJSON("maas/node.json", node); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/nodes.json", nodes); err != nil { t.Fatal(err) } diff --git a/entity/rack_controller.go b/entity/rack_controller.go index 00ff1c7..15505a5 100644 --- a/entity/rack_controller.go +++ b/entity/rack_controller.go @@ -1,6 +1,6 @@ package entity -// RackController represents the MaaS RackController endpoint. +// RackController represents the MAAS RackController endpoint. type RackController Machine // RackControllerSearch narrows down the list in RackController.Get(). diff --git a/entity/rack_controller_test.go b/entity/rack_controller_test.go index 7bf5e96..f28b5cf 100644 --- a/entity/rack_controller_test.go +++ b/entity/rack_controller_test.go @@ -14,6 +14,7 @@ func TestRackControllert(t *testing.T) { if err := helper.TestdataFromJSON("maas/rack_controller.json", rackController); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/rack_controllers.json", rackControllers); err != nil { t.Fatal(err) } diff --git a/entity/raid.go b/entity/raid.go index 3bdc8d8..6cbfe89 100644 --- a/entity/raid.go +++ b/entity/raid.go @@ -2,48 +2,45 @@ package entity // RAID represents the MAAS RAID endpoint. type RAID struct { - ID int `json:"id,omitempty"` UUID string `json:"uuid,omitempty"` Name string `json:"name,omitempty"` Level string `json:"level,omitempty"` - Devices []RAIDDevice `json:"devices,omitempty"` - SpareDevices []RAIDDevice `json:"spare_devices,omitempty"` - Size int64 `json:"size,omitempty"` HumanSize string `json:"human_size,omitempty"` - VirtualDevice BlockDevice `json:"virtual_device,omitempty"` ResourceURI string `json:"resource_uri"` SystemID string `json:"system_id"` + Devices []RAIDDevice `json:"devices,omitempty"` + SpareDevices []RAIDDevice `json:"spare_devices,omitempty"` + VirtualDevice BlockDevice `json:"virtual_device,omitempty"` + ID int `json:"id,omitempty"` + Size int64 `json:"size,omitempty"` } // RAIDDevice is a combination of a BlockDevice and BlockDevicePartition since a RAID can contain either at devices field type RAIDDevice struct { - // BlockDevice fields - BlockSize int `json:"block_size,omitempty"` - ID int `json:"id,omitempty"` - IDPath string `json:"id_path,omitempty"` + Filesystem PartitionFileSystem `json:"filesystem,omitempty"` + Type string `json:"type,omitempty"` Model string `json:"model,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` Name string `json:"name,omitempty"` Path string `json:"path,omitempty"` Serial string `json:"serial,omitempty"` - Size int64 `json:"size,omitempty"` - Tags []string `json:"tags,omitempty"` + IDPath string `json:"id_path,omitempty"` + UsedFor string `json:"used_for,omitempty"` FirmwareVersion string `json:"firmware_version,omitempty"` - SystemID string `json:"system_id,omitempty"` - AvailableSize int64 `json:"available_size,omitempty"` - UsedSize int64 `json:"used_size,omitempty"` PartitionTableType string `json:"partition_table_type,omitempty"` - Partitions []BlockDevicePartition `json:"partitions,omitempty"` - Filesystem PartitionFileSystem `json:"filesystem,omitempty"` StoragePool string `json:"storage_pool,omitempty"` - UsedFor string `json:"used_for,omitempty"` - Type string `json:"type,omitempty"` UUID string `json:"uuid,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + SystemID string `json:"system_id,omitempty"` + Partitions []BlockDevicePartition `json:"partitions,omitempty"` + Tags []string `json:"tags,omitempty"` + Size int64 `json:"size,omitempty"` + ID int `json:"id,omitempty"` + BlockSize int `json:"block_size,omitempty"` + DeviceID int `json:"device_id,omitempty"` + AvailableSize int64 `json:"available_size,omitempty"` NUMANode int `json:"numa_node,omitempty"` - - // BlockDevicePartition unique fields - Bootable bool `json:"bootable,omitempty"` - DeviceID int `json:"device_id,omitempty"` + UsedSize int64 `json:"used_size,omitempty"` + Bootable bool `json:"bootable,omitempty"` } // RAIDUpdateParams enumerates the parameters for the RAID update operation diff --git a/entity/resource_pool.go b/entity/resource_pool.go index c03f4c2..b41edf5 100644 --- a/entity/resource_pool.go +++ b/entity/resource_pool.go @@ -1,11 +1,11 @@ package entity -// ResourcePool represents the MaaS ResourcePool endpoint +// ResourcePool represents the MAAS ResourcePool endpoint type ResourcePool struct { - ID int `json:"id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + ID int `json:"id,omitempty"` } type ResourcePoolParams struct { diff --git a/entity/resource_pool_test.go b/entity/resource_pool_test.go index 0ffd036..d1de857 100644 --- a/entity/resource_pool_test.go +++ b/entity/resource_pool_test.go @@ -14,6 +14,7 @@ func TestResourcePoolt(t *testing.T) { if err := helper.TestdataFromJSON("maas/resource_pool.json", pool); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/resource_pools.json", pools); err != nil { t.Fatal(err) } diff --git a/entity/space.go b/entity/space.go index 7fe406d..9abeb39 100644 --- a/entity/space.go +++ b/entity/space.go @@ -1,9 +1,9 @@ package entity type Space struct { - ID int `json:"id,omitempty"` Name string `json:"name,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` Subnets []Subnet `json:"subnets,omitempty"` VLANs []VLAN `json:"vlans,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + ID int `json:"id,omitempty"` } diff --git a/entity/subnet.go b/entity/subnet.go index 9de2916..5af5e67 100644 --- a/entity/subnet.go +++ b/entity/subnet.go @@ -4,21 +4,21 @@ import ( "net" ) -// Subnet represents the MaaS Subnet endpoint. +// Subnet represents the MAAS Subnet endpoint. type Subnet struct { + Space string `json:"space,omitempty"` + CIDR string `json:"cidr,omitempty"` Name string `json:"name,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + DNSServers []net.IP `json:"dns_servers,omitempty"` + GatewayIP net.IP `json:"gateway_ip,omitempty"` VLAN VLAN `json:"vlan,omitempty"` - CIDR string `json:"cidr,omitempty"` + ID int `json:"id,omitempty"` RDNSMode int `json:"rdns_mode,omitempty"` - GatewayIP net.IP `json:"gateway_ip,omitempty"` - DNSServers []net.IP `json:"dns_servers,omitempty"` AllowDNS bool `json:"allow_dns,omitempty"` - AllowProxy bool `json:"allow_proxy,omitempty"` - ActiveDiscovery bool `json:"active_discovery,omitempty"` Managed bool `json:"managed,omitempty"` - ID int `json:"id,omitempty"` - Space string `json:"space,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + ActiveDiscovery bool `json:"active_discovery,omitempty"` + AllowProxy bool `json:"allow_proxy,omitempty"` } // SubnetParams contains the parameters for the POST operation on the Subnets endpoint. @@ -28,9 +28,9 @@ type SubnetParams struct { Description string `url:"description,omitempty"` VLAN string `url:"vlan,omitempty"` Fabric string `url:"fabric,omitempty"` - VID int `url:"vid,omitempty"` GatewayIP string `url:"gateway_ip,omitempty"` DNSServers []string `url:"dns_servers,omitempty"` + VID int `url:"vid,omitempty"` RDNSMode int `url:"rdns_mode"` AllowDNS bool `url:"allow_dns"` AllowProxy bool `url:"allow_proxy"` diff --git a/entity/subnet/ip_address.go b/entity/subnet/ip_address.go index 656994b..5ac1903 100644 --- a/entity/subnet/ip_address.go +++ b/entity/subnet/ip_address.go @@ -6,21 +6,21 @@ import ( // IPAddress represents an IP address from a Subnet's GetIPAddresses() type IPAddress struct { - IP net.IP `json:"ip,omitempty"` - AllocType int `json:"alloc_type,omitempty"` Created string `json:"created,omitempty"` Updated string `json:"updated,omitempty"` - NodeSummary NodeSummary `json:"node_summary,omitempty"` User string `json:"user,omitempty"` + IP net.IP `json:"ip,omitempty"` + NodeSummary NodeSummary `json:"node_summary,omitempty"` + AllocType int `json:"alloc_type,omitempty"` } // NodeSummary represents the optional node_summary from GetIPAddresses(). // This type should not be used directly. type NodeSummary struct { SystemID string `json:"system_id,omitempty"` - NodeType int `json:"node_type,omitempty"` FQDN string `json:"fqdn,omitempty"` Hostname string `json:"hostname,omitempty"` - IsContainer bool `json:"is_container,omitempty"` Via string `json:"via,omitempty"` + NodeType int `json:"node_type,omitempty"` + IsContainer bool `json:"is_container,omitempty"` } diff --git a/entity/subnet/reserved_ip_range.go b/entity/subnet/reserved_ip_range.go index 0436960..4ea8359 100644 --- a/entity/subnet/reserved_ip_range.go +++ b/entity/subnet/reserved_ip_range.go @@ -2,6 +2,6 @@ package subnet // ReservedIPRange represents an IP range from a Subnet's GetReservedIPRanges() type ReservedIPRange struct { - IPRange Purpose []string `json:"purpose,omitempty"` + IPRange } diff --git a/entity/subnet/statistics.go b/entity/subnet/statistics.go index 28a2961..88e3b05 100644 --- a/entity/subnet/statistics.go +++ b/entity/subnet/statistics.go @@ -6,14 +6,14 @@ import ( // Statistics represents a Subnet's GetStatistics() type Statistics struct { + UsageString string `json:"usage_string,omitempty"` + AvailableString string `json:"available_string,omitempty"` + FirstAddress net.IP `json:"first_address,omitempty"` + LastAddress net.IP `json:"last_address,omitempty"` NumAvailable int `json:"num_available,omitempty"` LargestAvailable int `json:"largest_available,omitempty"` NumUnavailable int `json:"num_unavailable,omitempty"` TotalAddresses int `json:"total_addresses,omitempty"` Usage float64 `json:"usage,omitempty"` - UsageString string `json:"usage_string,omitempty"` - AvailableString string `json:"available_string,omitempty"` - FirstAddress net.IP `json:"first_address,omitempty"` - LastAddress net.IP `json:"last_address,omitempty"` IPVersion int `json:"ip_version,omitempty"` } diff --git a/entity/subnet/subnet.go b/entity/subnet/subnet.go new file mode 100644 index 0000000..c81d391 --- /dev/null +++ b/entity/subnet/subnet.go @@ -0,0 +1,2 @@ +// Package subnet contains entities related to subnets. +package subnet diff --git a/entity/subnet_test.go b/entity/subnet_test.go index 6289c13..03c5a4d 100644 --- a/entity/subnet_test.go +++ b/entity/subnet_test.go @@ -260,6 +260,7 @@ func TestSubnet(t *testing.T) { if err := helper.TestdataFromJSON("maas/subnet.json", subnet); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/subnets.json", subnets); err != nil { t.Fatal(err) } @@ -268,6 +269,7 @@ func TestSubnet(t *testing.T) { if diff := cmp.Diff(&sampleSubnet, subnet); diff != "" { t.Fatalf("json.Decode(Subnet) mismatch (-want +got):\n%s", diff) } + if diff := cmp.Diff(&sampleSubnets, subnets); diff != "" { t.Fatalf("json.Decode([]Subnet) mismatch (-want +got):\n%s", diff) } diff --git a/entity/user.go b/entity/user.go index f0a4940..a29bbd5 100644 --- a/entity/user.go +++ b/entity/user.go @@ -1,11 +1,11 @@ package entity type User struct { - IsSuperUser bool `json:"is_superuser"` - IsLocal bool `json:"is_local"` UserName string `json:"username"` Email string `json:"email"` ResourceURI string `json:"resource_uri"` + IsSuperUser bool `json:"is_superuser"` + IsLocal bool `json:"is_local"` } type UserParams struct { diff --git a/entity/vlan.go b/entity/vlan.go index 3af0973..fc8285a 100644 --- a/entity/vlan.go +++ b/entity/vlan.go @@ -1,34 +1,34 @@ package entity -// VLAN represents the MaaS VLAN endpoint. +// VLAN represents the MAAS VLAN endpoint. type VLAN struct { - VID int `json:"vid,omitempty"` - MTU int `json:"mtu,omitempty"` - DHCPOn bool `json:"dhcp_on,omitempty"` - ExternalDHCP string `json:"external_dhcp,omitempty"` RelayVLAN *VLAN `json:"relay_vlan,omitempty"` - FabricID int `json:"fabric_id,omitempty"` Name string `json:"name,omitempty"` + ExternalDHCP string `json:"external_dhcp,omitempty"` Description string `json:"description,omitempty"` PrimaryRack string `json:"primary_rack,omitempty"` SecondaryRack string `json:"secondary_rack,omitempty"` Space string `json:"space,omitempty"` - ID int `json:"id,omitempty"` Fabric string `json:"fabric,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + MTU int `json:"mtu,omitempty"` + FabricID int `json:"fabric_id,omitempty"` + VID int `json:"vid,omitempty"` + ID int `json:"id,omitempty"` + DHCPOn bool `json:"dhcp_on,omitempty"` } // VLANParams contains the options for a POST request to the vlans endpoint. // Only the VID field is required. If Space is empty or the string "undefined", // the VLAN will be created in the 'undefined' space. type VLANParams struct { - VID int `url:"vid,omitempty"` - MTU int `url:"mtu,omitempty"` - RelayVLAN int `url:"relay_vlan,omitempty"` Name string `url:"name,omitempty"` Description string `url:"description,omitempty"` Space string `url:"space,omitempty"` PrimaryRack string `url:"primary_rack,omitempty"` SecondaryRack string `url:"secondary_rack,omitempty"` + VID int `url:"vid,omitempty"` + MTU int `url:"mtu,omitempty"` + RelayVLAN int `url:"relay_vlan,omitempty"` DHCPOn bool `url:"dhcp_on"` } diff --git a/entity/vlan_test.go b/entity/vlan_test.go index 8c237bd..25b7188 100644 --- a/entity/vlan_test.go +++ b/entity/vlan_test.go @@ -75,6 +75,7 @@ func TestVLAN(t *testing.T) { if err := helper.TestdataFromJSON("maas/vlan.json", vlan); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/vlans.json", vlans); err != nil { t.Fatal(err) } @@ -83,6 +84,7 @@ func TestVLAN(t *testing.T) { if diff := cmp.Diff(&sampleVLAN, vlan); diff != "" { t.Fatalf("json.Decode(VLAN) mismatch (-want +got):\n%s", diff) } + if diff := cmp.Diff(&sampleVLANs, vlans); diff != "" { t.Fatalf("json.Decode([]VLAN) mismatch (-want +got):\n%s", diff) } diff --git a/entity/vm_host.go b/entity/vm_host.go index c36cd0e..d8079df 100644 --- a/entity/vm_host.go +++ b/entity/vm_host.go @@ -1,27 +1,27 @@ package entity -// VMHost represents the MaaS VM host endpoint. +// VMHost represents the MAAS VM host endpoint. type VMHost struct { - Zone Zone `json:"zone,omitempty"` - Pool ResourcePool `json:"pool,omitempty"` - Used VMHostResource `json:"used,omitempty"` - Available VMHostResource `json:"available,omitempty"` - Total VMHostResource `json:"total,omitempty"` - Host struct { + Zone Zone `json:"zone,omitempty"` + Pool ResourcePool `json:"pool,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + DefaultMACVLANMode string `json:"default_macvlan_mode,omitempty"` + Type string `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Tags []string `json:"tags,omitempty"` + Architectures []string `json:"architectures,omitempty"` + StoragePools []VMHostStoragePool `json:"storage_pools,omitempty"` + Capabilities []string `json:"capabilities,omitempty"` + Host struct { SystemID string `json:"system_id,omitempty"` - Incomplete bool `json:"__incomplete__,omitempty"` + Incomplete bool `json:"__incomplete__,omitempty"` //nolint:tagliatelle // MAAS returns this field intentionally } `json:"host,omitempty"` - StoragePools []VMHostStoragePool `json:"storage_pools,omitempty"` - Architectures []string `json:"architectures,omitempty"` - Tags []string `json:"tags,omitempty"` - Capabilities []string `json:"capabilities,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - DefaultMACVLANMode string `json:"default_macvlan_mode,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` - CPUOverCommitRatio float64 `json:"cpu_over_commit_ratio,omitempty"` - MemoryOverCommitRatio float64 `json:"memory_over_commit_ratio,omitempty"` - ID int `json:"id,omitempty"` + Total VMHostResource `json:"total,omitempty"` + Available VMHostResource `json:"available,omitempty"` + Used VMHostResource `json:"used,omitempty"` + CPUOverCommitRatio float64 `json:"cpu_over_commit_ratio,omitempty"` + MemoryOverCommitRatio float64 `json:"memory_over_commit_ratio,omitempty"` + ID int `json:"id,omitempty"` } // VMHostStoragePool represents the "storage_pools" object in a VMHost. @@ -56,19 +56,19 @@ type VMHostParams struct { Pool string `url:"pool,omitempty"` DefaultStoragePool string `url:"default_storage_pool,omitempty"` DefaultMacvlanMode string `url:"default_macvlan_mode,omitempty"` + Tags string `url:"tags,omitempty"` CPUOverCommitRatio float64 `url:"cpu_over_commit_ratio,omitempty"` MemoryOverCommitRatio float64 `url:"memory_over_commit_ratio,omitempty"` - Tags string `url:"tags,omitempty"` } // VMHostMachineParams enumerates the VMHost machine configuration options. type VMHostMachineParams struct { - Cores int `url:"cores,omitempty"` - PinnedCores int `url:"pinned_cores,omitempty"` - Memory int64 `url:"memory,omitempty"` - HugepagesBacked bool `url:"hugepages_backed,omitempty"` Architecture string `url:"architecture,omitempty"` Storage string `url:"storage,omitempty"` Interfaces string `url:"interfaces,omitempty"` Hostname string `url:"hostname,omitempty"` + Cores int `url:"cores,omitempty"` + PinnedCores int `url:"pinned_cores,omitempty"` + Memory int64 `url:"memory,omitempty"` + HugepagesBacked bool `url:"hugepages_backed,omitempty"` } diff --git a/entity/vm_host_test.go b/entity/vm_host_test.go index a192b86..64f23fb 100644 --- a/entity/vm_host_test.go +++ b/entity/vm_host_test.go @@ -14,6 +14,7 @@ func TestVMHostt(t *testing.T) { if err := helper.TestdataFromJSON("maas/vm_host.json", vmHost); err != nil { t.Fatal(err) } + if err := helper.TestdataFromJSON("maas/vm_hosts.json", vmHosts); err != nil { t.Fatal(err) } diff --git a/entity/volume_group.go b/entity/volume_group.go index 33dd1a8..c50d753 100644 --- a/entity/volume_group.go +++ b/entity/volume_group.go @@ -1,18 +1,18 @@ package entity -// VolumeGroup represents the MaaS VolumeGroup endpoint. +// VolumeGroup represents the MAAS VolumeGroup endpoint. type VolumeGroup struct { - HumanUsedSize string `json:"human_used_size,omitempty"` + LogicalVolumes interface{} `json:"logical_volumes,omitempty"` + Devices interface{} `json:"devices,omitempty"` + HumanSize string `json:"human_size,omitempty"` UUID string `json:"uuid,omitempty"` HumanAvailableSize string `json:"human_available_size,omitempty"` SystemID string `json:"system_id,omitempty"` - ID int `json:"id,omitempty"` - LogicalVolumes interface{} `json:"logical_volumes,omitempty"` + ResourceURI string `json:"resource_uri,omitempty"` + HumanUsedSize string `json:"human_used_size,omitempty"` + Name string `json:"name,omitempty"` Size int64 `json:"size,omitempty"` - Devices interface{} `json:"devices,omitempty"` - AvailableSize int64 `json:"available_size,omitempty"` UsedSize int64 `json:"used_size,omitempty"` - HumanSize string `json:"human_size,omitempty"` - Name string `json:"name,omitempty"` - ResourceURI string `json:"resource_uri,omitempty"` + AvailableSize int64 `json:"available_size,omitempty"` + ID int `json:"id,omitempty"` } diff --git a/entity/zone.go b/entity/zone.go index 0e65d4e..3a1a858 100644 --- a/entity/zone.go +++ b/entity/zone.go @@ -1,9 +1,9 @@ package entity -// Zone represents the MaaS Zone endpoint +// Zone represents the MAAS Zone endpoint type Zone struct { - ID int `json:"id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ResourceURI string `json:"resource_uri,omitempty"` + ID int `json:"id,omitempty"` } diff --git a/go.mod b/go.mod index ba15b19..7bc8dbf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/maas/gomaasclient -go 1.17 +go 1.20 require ( github.com/google/go-cmp v0.5.6 @@ -18,6 +18,5 @@ require ( github.com/juju/schema v1.0.1 // indirect github.com/juju/version v0.0.0-20210303051006-2015802527a8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ad9286d..5c3b61d 100644 --- a/go.sum +++ b/go.sum @@ -25,13 +25,12 @@ github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c/go.mod h1:nD0vlnrUjcjJhqN5WuCWZyzfd5AHZAC9/ajvbSx69xA= github.com/juju/clock v0.0.0-20220202072423-1b0f830854c4/go.mod h1:zDZCPSgCJQINeZtQwHx2/cFk4seaBC8Yiqe8V82xiP0= -github.com/juju/clock v0.0.0-20220203021603-d9deb868a28a h1:Az/6CM/P5guGHNy7r6TkOCctv3lDmN3W1uhku7QMupk= github.com/juju/clock v0.0.0-20220203021603-d9deb868a28a/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= github.com/juju/clock v1.0.0/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= +github.com/juju/clock v1.0.2 h1:dJFdUGjtR/76l6U5WLVVI/B3i6+u3Nb9F9s1m+xxrxo= github.com/juju/cmd v0.0.0-20171107070456-e74f39857ca0/go.mod h1:yWJQHl73rdSX4DHVKGqkAip+huBslxRwS8m9CrOLq18= github.com/juju/cmd/v3 v3.0.0-20220202061353-b1cc80b193b0/go.mod h1:EoGJiEG+vbMwO9l+Es0SDTlaQPjH6nLcnnc4NfZB3cY= github.com/juju/collections v0.0.0-20200605021417-0d0ec82b7271/go.mod h1:5XgO71dV1JClcOJE+4dzdn4HrI5LiyKd7PlVG6eZYhY= -github.com/juju/collections v0.0.0-20220203020748-febd7cad8a7a h1:d7eZO8OS/ZXxdP0uq3E8CdoA1qNFaecAv90UxrxaY2k= github.com/juju/collections v0.0.0-20220203020748-febd7cad8a7a/go.mod h1:JWeZdyttIEbkR51z2S13+J+aCuHVe0F6meRy+P0YGDo= github.com/juju/collections v1.0.0/go.mod h1:JWeZdyttIEbkR51z2S13+J+aCuHVe0F6meRy+P0YGDo= github.com/juju/collections v1.0.4 h1:GjL+aN512m2rVDqhPII7P6qB0e+iYFubz8sqBhZaZtk= @@ -39,24 +38,19 @@ github.com/juju/collections v1.0.4/go.mod h1:hVrdB0Zwq9wIU1Fl6ItD2+UETeNeOEs+nGv github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/errors v0.0.0-20200330140219-3fe23663418f/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff/go.mod h1:i1eL7XREII6aHpQ2gApI/v6FkVUDEBremNkcBCKYAcY= -github.com/juju/errors v0.0.0-20220203013757-bd733f3c86b9 h1:EJHbsNpQyupmMeWTq7inn+5L/WZ7JfzCVPJ+DP9McCQ= github.com/juju/errors v0.0.0-20220203013757-bd733f3c86b9/go.mod h1:TRm7EVGA3mQOqSVcBySRY7a9Y1/gyVhh/WTCnc5sD4U= github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM= github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= -github.com/juju/gomaasapi/v2 v2.1.0 h1:K9M4OjDVSS7UWjHGvYvdpXJWQE72uyDo4do1czDjlIA= -github.com/juju/gomaasapi/v2 v2.1.0/go.mod h1:ZsohFbU4xShV1aSQYQ21hR1lKj7naNGY0SPuyelcUmk= github.com/juju/gomaasapi/v2 v2.2.0 h1:vaYeEKr0mQXsM38/zfWqCrYDG8cYhHRkfTQMgkJGHdU= github.com/juju/gomaasapi/v2 v2.2.0/go.mod h1:ZsohFbU4xShV1aSQYQ21hR1lKj7naNGY0SPuyelcUmk= github.com/juju/httpprof v0.0.0-20141217160036-14bf14c30767/go.mod h1:+MaLYz4PumRkkyHYeXJ2G5g5cIW0sli2bOfpmbaMV/g= github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/juju/loggo v0.0.0-20200526014432-9ce3a2e09b5e/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= -github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4 h1:NO5tuyw++EGLnz56Q8KMyDZRwJwWO8jQnj285J3FOmY= github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg= github.com/juju/loggo v1.0.0 h1:Y6ZMQOGR9Aj3BGkiWx7HBbIx6zNwNkxhVNOHU2i1bl0= github.com/juju/loggo v1.0.0/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg= github.com/juju/mgo/v2 v2.0.0-20210302023703-70d5d206e208/go.mod h1:0OChplkvPTZ174D2FYZXg4IB9hbEwyHkD+zT+/eK+Fg= -github.com/juju/mgo/v2 v2.0.0-20220111072304-f200228f1090 h1:zX5GoH3Jp8k1EjUFkApu/YZAYEn0PYQfg/U6IDyNyYs= github.com/juju/mgo/v2 v2.0.0-20220111072304-f200228f1090/go.mod h1:N614SE0a4e+ih2rg96Vi2PeC3cTpUOWgCTv3Cgk974c= github.com/juju/mgo/v2 v2.0.2 h1:ufYtW2OFNjniTuxOngecP3Mk5sSclo8Zl1mnmyGWUWA= github.com/juju/mgo/v2 v2.0.2/go.mod h1:Z2QbXIrR9JuJcSyankQOw31tINNA5p3qevW73oDoHsM= @@ -65,11 +59,7 @@ github.com/juju/mutex/v2 v2.0.0-20220128011612-57176ebdcfa3/go.mod h1:TTCG9BJD9r github.com/juju/mutex/v2 v2.0.0-20220203023141-11eeddb42c6c/go.mod h1:jwCfBs/smYDaeZLqeaCi8CB8M+tOes4yf827HoOEoqk= github.com/juju/retry v0.0.0-20151029024821-62c620325291/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= github.com/juju/retry v0.0.0-20180821225755-9058e192b216/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= -github.com/juju/retry v0.0.0-20220204093819-62423bf33287 h1:U+7oMWEglXfiikIppNexButZRwKPlzLBGKYSNCXzXf8= -github.com/juju/retry v0.0.0-20220204093819-62423bf33287/go.mod h1:SssN1eYeK3A2qjnFGTiVMbdzGJ2BfluaJblJXvuvgqA= github.com/juju/retry v1.0.0/go.mod h1:SssN1eYeK3A2qjnFGTiVMbdzGJ2BfluaJblJXvuvgqA= -github.com/juju/schema v1.0.1-0.20190814234152-1f8aaeef0989 h1:qx1Zh1bnHHVIMmRxq0fehYk7npCG50GhUwEkYeUg/t4= -github.com/juju/schema v1.0.1-0.20190814234152-1f8aaeef0989/go.mod h1:Y+ThzXpUJ0E7NYYocAbuvJ7vTivXfrof/IfRPq/0abI= github.com/juju/schema v1.0.1 h1:GBEiwxZQeoQuXI6gOTG58W/ZpdongMwl9pfZq1KcNgM= github.com/juju/schema v1.0.1/go.mod h1:Y+ThzXpUJ0E7NYYocAbuvJ7vTivXfrof/IfRPq/0abI= github.com/juju/testing v0.0.0-20180402130637-44801989f0f7/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= @@ -78,32 +68,29 @@ github.com/juju/testing v0.0.0-20190723135506-ce30eb24acd2/go.mod h1:63prj8cnj0t github.com/juju/testing v0.0.0-20210302031854-2c7ee8570c07/go.mod h1:7lxZW0B50+xdGFkvhAb8bwAGt6IU87JB1H9w4t8MNVM= github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098/go.mod h1:7lxZW0B50+xdGFkvhAb8bwAGt6IU87JB1H9w4t8MNVM= github.com/juju/testing v0.0.0-20220202055744-1ad0816210a6/go.mod h1:QgWc2UdIPJ8t3rnvv95tFNOsQDfpXYEZDbP281o3b2c= -github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494 h1:XEDzpuZb8Ma7vLja3+5hzUqVTvAqm5Y+ygvnDs5iTMM= github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494/go.mod h1:rUquetT0ALL48LHZhyRGvjjBH8xZaZ8dFClulKK5wK4= github.com/juju/testing v1.0.0/go.mod h1:rUquetT0ALL48LHZhyRGvjjBH8xZaZ8dFClulKK5wK4= +github.com/juju/testing v1.0.2 h1:OR90RqCd9CJONxXamZAjLknpZdtqDyxqW8IwCbgw3i4= github.com/juju/utils v0.0.0-20180424094159-2000ea4ff043/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= github.com/juju/utils v0.0.0-20200116185830-d40c2fe10647 h1:wQpkHVbIIpz1PCcLYku9KFWsJ7aEMQXHBBmLy3tRBTk= github.com/juju/utils v0.0.0-20200116185830-d40c2fe10647/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= github.com/juju/utils/v2 v2.0.0-20200923005554-4646bfea2ef1/go.mod h1:fdlDtQlzundleLLz/ggoYinEt/LmnrpNKcNTABQATNI= github.com/juju/utils/v3 v3.0.0-20220130232349-cd7ecef0e94a/go.mod h1:LzwbbEN7buYjySp4nqnti6c6olSqRXUk6RkbSUUP1n8= github.com/juju/utils/v3 v3.0.0-20220202114721-338bb0530e89/go.mod h1:wf5w+8jyTh2IYnSX0sHnMJo4ZPwwuiBWn+xN3DkQg4k= -github.com/juju/utils/v3 v3.0.0-20220203023959-c3fbc78a33b0 h1:bn+2Adl1yWqYjm3KSFlFqsvfLg2eq+XNL7GGMYApdVw= github.com/juju/utils/v3 v3.0.0-20220203023959-c3fbc78a33b0/go.mod h1:8csUcj1VRkfjNIRzBFWzLFCMLwLqsRWvkmhfVAUwbC4= +github.com/juju/utils/v3 v3.0.0 h1:Gg3n63mGPbBuoXCo+EPJuMi44hGZfloI8nlCIebHu2Q= github.com/juju/utils/v3 v3.0.0/go.mod h1:8csUcj1VRkfjNIRzBFWzLFCMLwLqsRWvkmhfVAUwbC4= github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= -github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6 h1:nrqc9b4YKpKV4lPI3GPPFbo5FUuxkWxgZE2Z8O4lgaw= github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/juju/version v0.0.0-20210303051006-2015802527a8 h1:BTo6HzRR0zPBcXbs1Sy08aQNfvdm3ey8O+mBTiO3g00= github.com/juju/version v0.0.0-20210303051006-2015802527a8/go.mod h1:YUOK6VK9+V4hpmsBYx8ymvOzEXRzoIGjRDKpIezTi60= github.com/juju/version/v2 v2.0.0-20211007103408-2e8da085dc23/go.mod h1:Ljlbryh9sYaUSGXucslAEDf0A2XUSGvDbHJgW8ps6nc= -github.com/juju/version/v2 v2.0.0-20220204124744-fc9915e3d935 h1:6YoyzXVW1XkqN86y2s/rz365Jm7EiAy39v2G5ikzvHU= -github.com/juju/version/v2 v2.0.0-20220204124744-fc9915e3d935/go.mod h1:ZeFjNy+UFEWJDDPdzW7Cm9NeU6dsViGaFYhXzycLQrw= github.com/juju/version/v2 v2.0.0/go.mod h1:ZeFjNy+UFEWJDDPdzW7Cm9NeU6dsViGaFYhXzycLQrw= github.com/julienschmidt/httprouter v1.1.1-0.20151013225520-77a895ad01eb/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -124,16 +111,12 @@ github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= golang.org/x/crypto v0.0.0-20180214000028-650f4a345ab4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -143,8 +126,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -154,8 +137,8 @@ golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -171,7 +154,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -187,7 +169,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/errgo.v1 v1.0.0-20161222125816-442357a80af5/go.mod h1:u0ALmqvLRxLI95fkdCEWrE6mhWYZW1aMOJHp5YXLHTg= gopkg.in/httprequest.v1 v1.1.1/go.mod h1:/CkavNL+g3qLOrpFHVrEx4NKepeqR4XTZWNj4sGGjz0= gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= -gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk= diff --git a/test/helper/helper.go b/test/helper/helper.go index a178562..343b2d5 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -1,3 +1,4 @@ +// Package helper contains helper functions for unit tests. package helper import ( @@ -26,12 +27,15 @@ func init() { RepoBasePkg = func(fpath string) string { type foo struct{} + pkgPath := reflect.TypeOf(foo{}).PkgPath() fpath = filepath.Dir(fpath) + for path.Base(pkgPath) == filepath.Base(fpath) && filepath.Base(fpath) != filepath.Base(RepoBaseDir) { pkgPath = path.Dir(pkgPath) fpath = filepath.Dir(fpath) } + return pkgPath }(file) } diff --git a/test/helper/testdata.go b/test/helper/testdata.go index 3e8dfc4..d567635 100644 --- a/test/helper/testdata.go +++ b/test/helper/testdata.go @@ -2,6 +2,7 @@ package helper import ( "encoding/json" + "fmt" "io" "os" "path/filepath" @@ -11,7 +12,7 @@ import ( // The path should be relative to the /test/testdata directory. func Testdata(path string) (io.ReadCloser, error) { path = filepath.Join(RepoBaseDir, "test", "testdata", filepath.FromSlash(path)) - return os.Open(path) + return os.Open(filepath.Clean(path)) } // TestdataFromJSON fetches a testdata file and decodes it into a type. @@ -22,9 +23,15 @@ func TestdataFromJSON(path string, target interface{}) error { if err != nil { return err } - defer rc.Close() + + defer func() { + if err := rc.Close(); err != nil { + fmt.Println("Error when closing:", err) + } + }() dec := json.NewDecoder(rc) dec.DisallowUnknownFields() + return dec.Decode(target) }