From 44fcc9fa8820b84d9830ccc8d2b1c3132705a72f Mon Sep 17 00:00:00 2001 From: david micheneau <47741512+dmicheneau@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:28:48 +0100 Subject: [PATCH] chore: update workflow (#138) Co-authored-by: David MICHENEAU --- .changelog/43.txt | 2 +- .ci | 1 - .github/changelog/generate-changelog.sh | 2 +- .github/workflows/check_gen-doc.yml | 2 +- .github/workflows/codeql.yml | 79 ++++++++ .github/workflows/dapendabot_changelog.yml | 3 + .github/workflows/deploy_documentation.yml | 8 +- .github/workflows/generate_changelog.yml | 2 +- .github/workflows/generate_package.yml | 4 +- .github/workflows/{lint.yml => go-lint.yml} | 1 + .github/workflows/new-release.yaml | 7 +- .github/workflows/pr_close.yml | 6 + .github/workflows/release.yml | 8 +- .gitmodules | 6 - .golangci.yml | 182 ++++++++++++++++++ .goreleaser.yaml | 14 +- .pre-commit-config.yaml | 38 ++++ .pre-commit/go-mod | 6 + .vscode/settings.json | 2 +- README.md | 8 +- cmd/add.go | 4 +- cmd/add_edgegateway.go | 14 +- cmd/add_publicip.go | 10 +- cmd/add_s3.go | 8 +- cmd/add_vdc.go | 8 +- cmd/del.go | 1 - cmd/del_edgegateway.go | 10 +- cmd/del_publicip.go | 10 +- cmd/del_s3.go | 6 +- cmd/del_vdc.go | 10 +- cmd/get_edgegateway.go | 13 +- cmd/get_publicip.go | 13 +- cmd/get_s3.go | 13 +- cmd/get_t0.go | 13 +- cmd/get_vdc.go | 13 +- cmd/root.go | 2 +- cmd/root_client.go | 17 +- cmd/root_global.go | 5 +- cmd/root_test.go | 23 +-- docs/advanced/advanced-installation.md | 4 +- docs/getting-started/configuration.md | 4 +- docs/getting-started/installation.md | 2 +- docs/index.md | 2 +- docs/stylesheets/extra.css | 2 +- githooks | 1 - go.mod | 3 +- go.sum | 4 +- main.go | 10 +- mkdocs.yml | 6 +- .../errorscustom.go} | 12 +- pkg/output/model/model.go | 6 +- pkg/output/output.go | 2 +- pkg/output/oyaml/oyaml.go | 3 +- scripts/install.sh | 2 +- 54 files changed, 472 insertions(+), 165 deletions(-) delete mode 160000 .ci create mode 100644 .github/workflows/codeql.yml rename .github/workflows/{lint.yml => go-lint.yml} (97%) delete mode 100644 .gitmodules create mode 100644 .golangci.yml create mode 100644 .pre-commit-config.yaml create mode 100755 .pre-commit/go-mod delete mode 160000 githooks rename pkg/{customErrors/customErrors.go => errorscustom/errorscustom.go} (66%) diff --git a/.changelog/43.txt b/.changelog/43.txt index f1f4519..0cfb4fc 100644 --- a/.changelog/43.txt +++ b/.changelog/43.txt @@ -1,7 +1,7 @@ ```release-note:enhancement `command` - Add new option `--output` to improve result in `cav` command. ``` - + ```release-note:enhancement `command` - improve speed of printed result for vdc list command. ``` diff --git a/.ci b/.ci deleted file mode 160000 index 5a2159f..0000000 --- a/.ci +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5a2159fbc2e06bff90001ef655f1ad260bddec34 diff --git a/.github/changelog/generate-changelog.sh b/.github/changelog/generate-changelog.sh index 610c176..a814476 100644 --- a/.github/changelog/generate-changelog.sh +++ b/.github/changelog/generate-changelog.sh @@ -25,7 +25,7 @@ if [ -z "$PREVIOUS_CHANGELOG" ] then echo "Unable to locate previous changelog contents." exit 1 -fi +fi CHANGELOG=$($(go env GOPATH)/bin/changelog-build -this-release $TARGET_SHA \ -last-release $PREVIOUS_RELEASE_SHA \ diff --git a/.github/workflows/check_gen-doc.yml b/.github/workflows/check_gen-doc.yml index 8c69cd5..77f7d1f 100644 --- a/.github/workflows/check_gen-doc.yml +++ b/.github/workflows/check_gen-doc.yml @@ -7,7 +7,7 @@ on: pull_request: paths: - '**.go' - + jobs: generate: name: gen-doc diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..eb9f4de --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,79 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + workflow_dispatch: + schedule: + - cron: '33 22 * * 2' + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: + group: Default + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" \ No newline at end of file diff --git a/.github/workflows/dapendabot_changelog.yml b/.github/workflows/dapendabot_changelog.yml index e19971b..2e6be4d 100644 --- a/.github/workflows/dapendabot_changelog.yml +++ b/.github/workflows/dapendabot_changelog.yml @@ -14,6 +14,9 @@ jobs: id: dependabot-metadata uses: dependabot/fetch-metadata@v2.2.0 - uses: actions/checkout@v4 + - uses: sersoft-gmbh/setup-gh-cli-action@v2 + with: + version: stable - run: | gh pr checkout $PR_URL cat << EOF > .changelog/$PR_NUMBER.txt diff --git a/.github/workflows/deploy_documentation.yml b/.github/workflows/deploy_documentation.yml index 363e40f..05254c5 100644 --- a/.github/workflows/deploy_documentation.yml +++ b/.github/workflows/deploy_documentation.yml @@ -1,4 +1,4 @@ -name: ci +name: ci on: push: branches: @@ -15,19 +15,19 @@ jobs: git config user.name github-actions[bot] git config user.email 41898282+github-actions[bot]@users.noreply.github.com sudo apt install jq -y - # GITTAG=$(git describe --tags --abbrev=0) sed -i "s/__GITTAG__/$GITTAG/g" $GITHUB_WORKSPACE/docs/advanced/advanced-installation.md + # GITTAG=$(git describe --tags --abbrev=0) sed -i "s/__GITTAG__/$GITTAG/g" $GITHUB_WORKSPACE/docs/advanced/advanced-installation.md GITTAG=$(curl -s https://api.github.com/repos/orange-cloudavenue/cloudavenue-cli/releases/latest | jq -r '.tag_name') echo $GITTAG sed -i "s/__GITTAG__/$GITTAG/g" $GITHUB_WORKSPACE/docs/advanced/advanced-installation.md - uses: actions/setup-python@v5 with: python-version: 3.x - - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} path: .cache restore-keys: | mkdocs-material- - - run: pip install mkdocs-material pymdown-extensions + - run: pip install mkdocs-material pymdown-extensions - run: mkdocs gh-deploy --force \ No newline at end of file diff --git a/.github/workflows/generate_changelog.yml b/.github/workflows/generate_changelog.yml index 2d8df7c..3cdede1 100644 --- a/.github/workflows/generate_changelog.yml +++ b/.github/workflows/generate_changelog.yml @@ -8,7 +8,7 @@ jobs: if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: token: ${{ secrets.CHANGELOG_PAT }} fetch-depth: 0 diff --git a/.github/workflows/generate_package.yml b/.github/workflows/generate_package.yml index c5f35a7..916e22b 100644 --- a/.github/workflows/generate_package.yml +++ b/.github/workflows/generate_package.yml @@ -3,9 +3,9 @@ on: workflow_dispatch: jobs: goreleaser: - runs-on: ubuntu-latest + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: # Allow goreleaser to access older tag information. fetch-depth: 0 diff --git a/.github/workflows/lint.yml b/.github/workflows/go-lint.yml similarity index 97% rename from .github/workflows/lint.yml rename to .github/workflows/go-lint.yml index 1be684d..e3d064c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/go-lint.yml @@ -7,6 +7,7 @@ on: pull_request: paths: - '**.go' + - '.golangci.yml' # Testing only needs permissions to read the repository contents. permissions: diff --git a/.github/workflows/new-release.yaml b/.github/workflows/new-release.yaml index 53ccac9..e52575a 100644 --- a/.github/workflows/new-release.yaml +++ b/.github/workflows/new-release.yaml @@ -10,6 +10,7 @@ on: permissions: contents: write + packages: write jobs: # * Step 0: Pre-Check @@ -101,12 +102,12 @@ jobs: tag: ${{ needs.pre-check.outputs.TAG_NAME }} tag_exists_error: true message: "Release ${{ needs.pre-check.outputs.TAG_NAME }}" - + release-notes: runs-on: ubuntu-latest needs: [tag, pre-check] steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: fetch-depth: 0 ref: ${{ needs.pre-check.outputs.TAG_NAME }} @@ -155,7 +156,7 @@ jobs: needs: [release-app, golangci-lint, pre-check] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: token: ${{ secrets.CHANGELOG_PAT }} fetch-depth: 0 diff --git a/.github/workflows/pr_close.yml b/.github/workflows/pr_close.yml index 37035fa..e77cbc5 100644 --- a/.github/workflows/pr_close.yml +++ b/.github/workflows/pr_close.yml @@ -8,6 +8,10 @@ concurrency: group: ${{ github.ref }}-${{ github.head_ref }}-changelog cancel-in-progress: true +permissions: + contents: write + pull-requests: write + jobs: GenerateChangelog: if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch' @@ -18,6 +22,7 @@ jobs: token: ${{ secrets.CHANGELOG_PAT }} fetch-depth: 0 submodules: false + ref: main - uses: actions/setup-go@v5.1.0 with: go-version-file: 'go.mod' @@ -26,6 +31,7 @@ jobs: - run: bash .github/changelog/generate-changelog.sh - uses: stefanzweifel/git-auto-commit-action@v5 with: + branch: main commit_message: "chore: Update CHANGELOG.md" commit_options: '--no-verify --signoff' push_options: '--force' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b26e197..24c4778 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: release-notes: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: fetch-depth: 0 - name: Generate Release Notes @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest needs: [release-notes] steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: # Allow goreleaser to access older tag information. fetch-depth: 0 @@ -61,7 +61,7 @@ jobs: outputs: tag: ${{ steps.highest-version-tag.outputs.tag }} steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: # Allow tag to be fetched when ref is a commit fetch-depth: 0 @@ -79,7 +79,7 @@ jobs: if: github.ref_name == needs.highest-version-tag.outputs.tag runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 # v3.5.3 + - uses: actions/checkout@v4 # v3.5.3 with: token: ${{ secrets.CHANGELOG_PAT }} fetch-depth: 0 diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 13ed58a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "githooks"] - path = githooks - url = https://github.com/FrangipaneTeam/githooks -[submodule ".ci"] - path = .ci - url = https://github.com/FrangipaneTeam/release-ci diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..e0d0910 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,182 @@ +# Visit https://golangci-lint.run/ for usage documentation +# and information on other useful linters +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-dirs-use-default: false + +run: + timeout: 10m + +linters: + enable: + - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] + - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] + - decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] + - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] + - durationcheck # check for two durations multiplied together [fast: false, auto-fix: false] + - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] + - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false] + - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] + - copyloopvar # Checks for loop variables that are used in deferred functions [fast: true, auto-fix: false] + # - forbidigo # Forbids identifiers [fast: true, auto-fix: false] + - gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] + - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] + - gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] + - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + - goheader # Checks is file header matches to pattern [fast: true, auto-fix: false] + - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] + - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] + - goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] + - gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false] + - gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] + - govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] + - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] + - importas # Enforces consistent import aliases [fast: false, auto-fix: false] + - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] + - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] + - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] + - nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] + - noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false] + - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] + - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false] + - predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] + - promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] + - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] + - rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false] + - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false] + - stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false] + - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] + - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] + - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] + - unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false] + - unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] + - wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] + - whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] + + disable: + - tagliatelle # Checks the struct tags. [fast: true, auto-fix: false] + - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false] + - dupl # Tool for code clone detection [fast: true, auto-fix: false] + - containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false] + - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] + - cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false] + - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] + - exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false] + - funlen # Tool for detection of long functions [fast: true, auto-fix: false] + - gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false] + - gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false] + - gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false] + - godot # Check if comments end in a period [fast: true, auto-fix: true] + - godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] + - err113 # err113 is a linter that detects the use of the deprecated `errors.Is` and `errors.As` functions. [fast: false, auto-fix: false] + - gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false] + - lll # Reports long lines [fast: true, auto-fix: false] + - maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false] + - nestif # Reports deeply nested if statements [fast: true, auto-fix: false] + - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false] + - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false] + - staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] + - varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false] + - wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false] + - wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false] + +linters-settings: + goimports: + local-prefixes: github.com/orange-cloudavenue/cloudavenue-cli + + gci: + # Section configuration to compare against. + # Section names are case-insensitive and may contain parameters in (). + # The default order of sections is `standard > default > custom > blank > dot`, + # If `custom-order` is `true`, it follows the order of `sections` option. + # Default: ["standard", "default"] + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/orange-cloudavenue/cloudavenue-cli) # Custom section: groups all imports with the specified Prefix. + - blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled. + - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled. + skip-generated: true + custom-order: true + + gofumpt: + # Module path which contains the source code being formatted. + # Default: "" + module-path: github.com/orange-cloudavenue/cloudavenue-cli + # Choose whether to use the extra rules. + # Default: false + extra-rules: true + + + revive: + ignore-generated-header: true + severity: error + rules: + - name: exported + severity: warning + disabled: false + - name: indent-error-flow + severity: warning + disabled: false + - name: var-naming + severity: warning + disabled: false + arguments: + # List Bypass rules + - [] + # List force rules + - [ + # Default rules + "ACL", + "API", + "ASCII", + "CPU", + "CSS", + "DNS", + "EOF", + "GUID", + "HTML", + "HTTP", + "HTTPS", + "ID", + "IP", + "JSON", + "LHS", + "QPS", + "RAM", + "RHS", + "RPC", + "SLA", + "SMTP", + "SQL", + "SSH", + "TCP", + "TLS", + "TTL", + "UDP", + "UI", + "UID", + "UUID", + "URI", + "URL", + "UTF8", + "VM", + "XML", + "XMPP", + "XSRF", + "XSS", + # Custom rules + "VDC", + "DFW", + "VLAN", + "IAM", + "VCDA", + "NAT", + "VPN", + "BMS", + ] diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 855dcc7..4874834 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,13 +1,5 @@ -# This is an example .goreleaser.yml file with some sensible defaults. -# Make sure to check the documentation at https://goreleaser.com - -# The lines below are called `modelines`. See `:help modeline` -# Feel free to remove those if you don't want/need to use them. -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj - -version: 1 - +project_name: cloudavenue-cli +version: 2 before: hooks: # You may remove this if you don't use go modules. @@ -55,7 +47,7 @@ checksum: # cav is a CLI terminal app built to give a basic view to manage your Cloud Avenue IaaS. # license: MIT # folder: Formula -# repository: +# repository: # owner: orange-cloudavenue # name: cloudavenue-cli # branch: main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7a16e44 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-merge-conflict + - id: trailing-whitespace + args: ["--markdown-linebreak-ext=md"] + - id: forbid-submodules + +## GOLANG +- repo: https://github.com/golangci/golangci-lint + rev: v1.61.0 + hooks: + - id: golangci-lint + entry: bash -c 'exec golangci-lint run -j=6' + +- repo: local + hooks: + - id: gomod + name: gomod + entry: .pre-commit/go-mod + language: script + files: go.mod + pass_filenames: false + +## GIT +- repo: https://github.com/compilerla/conventional-pre-commit + rev: v3.2.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: [] + +## SECURITY +- repo: https://github.com/gitleaks/gitleaks + rev: v8.19.2 + hooks: + - id: gitleaks diff --git a/.pre-commit/go-mod b/.pre-commit/go-mod new file mode 100755 index 0000000..25d26ff --- /dev/null +++ b/.pre-commit/go-mod @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# +# go mod tidy will alter go.mod or go.sum if it finds any discrepancies +# + +go mod tidy diff --git a/.vscode/settings.json b/.vscode/settings.json index 12ecef8..7268336 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "yaml.schemas": { "https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml" }, - "yaml.customTags": [ + "yaml.customTags": [ "!ENV scalar", "!ENV sequence", "!relative scalar", diff --git a/README.md b/README.md index 1f70936..93b9131 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Please see Configuration chapter in Getting Start: https://github.com/orange-clo # Usage * Navigation commands : - + ```shell $> cav cav is the Command Line Interface for CloudAvenue Platform @@ -46,8 +46,8 @@ Use "cav [command] --help" for more information about a command. ```shell $> cav get egw -NAME OWNER -tn01e02ocbxxxxxxspt101 Shared -tn01e02ocbxxxxxxspt102 PRODUCTION +NAME OWNER +tn01e02ocbxxxxxxspt101 Shared +tn01e02ocbxxxxxxspt102 PRODUCTION tn01e02ocbxxxxxxspt103 STAGING ``` \ No newline at end of file diff --git a/cmd/add.go b/cmd/add.go index f59f476..ab764ae 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -10,11 +10,9 @@ const ( cmdAdd = "add" ) -var ( - exampleAdd1 = ` +var exampleAdd1 = ` #Add a VDC (Virtual Data Center) to CloudAvenue cav add vdc --name myvdc` -) // addCmd add a CAV resource var addCmd = &cobra.Command{ diff --git a/cmd/add_edgegateway.go b/cmd/add_edgegateway.go index 773261a..fbdaf78 100644 --- a/cmd/add_edgegateway.go +++ b/cmd/add_edgegateway.go @@ -19,18 +19,18 @@ var addEdgeGatewayCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } // Get the vdc name from the command line vdc, err := cmd.Flags().GetString(flagVDC) if err != nil { - return fmt.Errorf("Unable to retrieve flag %v: %w", flagVDC, err) + return fmt.Errorf("unable to retrieve flag %v: %w", flagVDC, err) } // Get the t0 name @@ -39,13 +39,13 @@ var addEdgeGatewayCmd = &cobra.Command{ if cmd.Flag(argT0).Value.String() == "" { t0s, err := c.V1.T0.GetT0s() if err != nil || (len(*t0s) > 1 || len(*t0s) == 0) { - return fmt.Errorf("Unable to retrieve your first T0: %w", err) + return fmt.Errorf("unable to retrieve your first T0: %w", err) } t0 = (*t0s)[0].Tier0Vrf } else { t0, err = cmd.Flags().GetString("t0") if err != nil { - return fmt.Errorf("Unable to retrieve T0 with VDC name %v: %w", flagVDC, err) + return fmt.Errorf("unable to retrieve T0 with VDC name %v: %w", flagVDC, err) } } // Add the edgeGateway @@ -56,11 +56,11 @@ var addEdgeGatewayCmd = &cobra.Command{ s.Restart() job, err := c.V1.EdgeGateway.New(vdc, t0) if err != nil { - return fmt.Errorf("Unable to add job: %w", err) + return fmt.Errorf("unable to add job: %w", err) } err = job.Wait(3, 300) if err != nil { - return fmt.Errorf("Error during EdgeGateway creation in VDC %v: %w", vdc, err) + return fmt.Errorf("error during EdgeGateway creation in VDC %v: %w", vdc, err) } s.FinalMSG = "EdgeGateway resource added successfully !!" s.Stop() diff --git a/cmd/add_publicip.go b/cmd/add_publicip.go index d1fca47..25498ff 100644 --- a/cmd/add_publicip.go +++ b/cmd/add_publicip.go @@ -18,18 +18,18 @@ var addPublicIPCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } // Get the name from the command line gwName, err := cmd.Flags().GetString(flagName) if err != nil { - return fmt.Errorf("Unable to retrieve flag %v: %w", flagName, err) + return fmt.Errorf("unable to retrieve flag %v: %w", flagName, err) } // Add a public ip @@ -40,11 +40,11 @@ var addPublicIPCmd = &cobra.Command{ job, err := c.V1.PublicIP.New(gwName) if err != nil { - return fmt.Errorf("Unable to add job: %w", err) + return fmt.Errorf("unable to add job: %w", err) } err = job.Wait(5, 300) if err != nil { - return fmt.Errorf("Error during public ip creation for edgegateway %v: %w", gwName, err) + return fmt.Errorf("error during public ip creation for edgegateway %v: %w", gwName, err) } s.FinalMSG = "public ip resource added successfully !!" s.Stop() diff --git a/cmd/add_s3.go b/cmd/add_s3.go index 837cf42..3f7ce76 100644 --- a/cmd/add_s3.go +++ b/cmd/add_s3.go @@ -18,17 +18,17 @@ var addS3Cmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } bucketName, err := cmd.Flags().GetString(flagName) if err != nil { - return fmt.Errorf("Unable to retrieve flag %v: %w", flagName, err) + return fmt.Errorf("unable to retrieve flag %v: %w", flagName, err) } // Add the bucket @@ -39,7 +39,7 @@ var addS3Cmd = &cobra.Command{ _, err = c.V1.S3().CreateBucket(&s3.CreateBucketInput{Bucket: &bucketName}) if err != nil { - return fmt.Errorf("Unable to add bucket S3 %v: %w", bucketName, err) + return fmt.Errorf("unable to add bucket S3 %v: %w", bucketName, err) } s.FinalMSG = "Bucket resource added successfully !!" s.Stop() diff --git a/cmd/add_vdc.go b/cmd/add_vdc.go index 344815c..c339576 100644 --- a/cmd/add_vdc.go +++ b/cmd/add_vdc.go @@ -18,18 +18,18 @@ var addVDCCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } // Get the vdc name from the command line vdcName, err := cmd.Flags().GetString(flagName) if err != nil { - return fmt.Errorf("Unable to retrieve flag %v: %w", flagName, err) + return fmt.Errorf("unable to retrieve flag %v: %w", flagName, err) } // Add the vdc @@ -58,7 +58,7 @@ var addVDCCmd = &cobra.Command{ }, }, }); err != nil { - return fmt.Errorf("Unable to add vdc %v: %w", vdcName, err) + return fmt.Errorf("unable to add vdc %v: %w", vdcName, err) } s.FinalMSG = "vdc resource added successfully !!\n" s.Stop() diff --git a/cmd/del.go b/cmd/del.go index 37bd855..fcd8343 100644 --- a/cmd/del.go +++ b/cmd/del.go @@ -49,5 +49,4 @@ func init() { // ? Delete for vdc delCmd.AddCommand(delVDCCmd) delVDCCmd.Args = cobra.MinimumNArgs(1) - } diff --git a/cmd/del_edgegateway.go b/cmd/del_edgegateway.go index 5b26ea6..9b70385 100644 --- a/cmd/del_edgegateway.go +++ b/cmd/del_edgegateway.go @@ -26,11 +26,11 @@ var delEdgeGatewayCmd = &cobra.Command{ // init Config File & Client if err = initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -44,16 +44,16 @@ var delEdgeGatewayCmd = &cobra.Command{ gw, err = c.V1.EdgeGateway.GetByName(arg) } if err != nil { - return fmt.Errorf("Unable to retrieve EdgeGateway: %w.", err) + return fmt.Errorf("unable to retrieve EdgeGateway: %w", err) } job, err := gw.Delete() if err != nil { - return fmt.Errorf("Unable to delete EdgeGateway: %w", err) + return fmt.Errorf("unable to delete EdgeGateway: %w", err) } err = job.Wait(3, 300) if err != nil { - return fmt.Errorf("Error during jobs edgeGateway deletion : %w", err) + return fmt.Errorf("error during jobs edgeGateway deletion : %w", err) } s.FinalMSG = "EdgeGateway resource deleted " + arg + " successfully !!\n" s.Stop() diff --git a/cmd/del_publicip.go b/cmd/del_publicip.go index 7469df9..aa501e3 100644 --- a/cmd/del_publicip.go +++ b/cmd/del_publicip.go @@ -17,11 +17,11 @@ var delPublicIPCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -31,15 +31,15 @@ var delPublicIPCmd = &cobra.Command{ s.Restart() ip, err := c.V1.PublicIP.GetIP(arg) if err != nil { - return fmt.Errorf("Unable to retrieve ip: %w", err) + return fmt.Errorf("unable to retrieve ip: %w", err) } job, err := ip.Delete() if err != nil { - return fmt.Errorf("Unable to delete ip: %w", err) + return fmt.Errorf("unable to delete ip: %w", err) } err = job.Wait(15, 300) if err != nil { - return fmt.Errorf("Job errors: %w", err) + return fmt.Errorf("job errors: %w", err) } s.FinalMSG = "ip resource deleted " + arg + " successfully !!\n" s.Stop() diff --git a/cmd/del_s3.go b/cmd/del_s3.go index 8837184..fc2c419 100644 --- a/cmd/del_s3.go +++ b/cmd/del_s3.go @@ -18,11 +18,11 @@ var delS3Cmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -33,7 +33,7 @@ var delS3Cmd = &cobra.Command{ // Del the bucket _, err := c.V1.S3().DeleteBucket(&s3.DeleteBucketInput{Bucket: &args[i]}) if err != nil { - return fmt.Errorf("Error from S3 Delete: %w", err) + return fmt.Errorf("error from S3 Delete: %w", err) } s.FinalMSG = "Bucket resource deleted " + arg + " successfully !!\n" s.Stop() diff --git a/cmd/del_vdc.go b/cmd/del_vdc.go index 8b439f7..5618c89 100644 --- a/cmd/del_vdc.go +++ b/cmd/del_vdc.go @@ -17,11 +17,11 @@ var delVDCCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -31,15 +31,15 @@ var delVDCCmd = &cobra.Command{ s.Restart() vdc, err := c.V1.VDC().GetVDC(arg) if err != nil { - return fmt.Errorf("Error from vdc: %w", err) + return fmt.Errorf("error from vdc: %w", err) } job, err := vdc.Delete() if err != nil { - return fmt.Errorf("Unable to delete vdc: %w", err) + return fmt.Errorf("unable to delete vdc: %w", err) } err = job.Wait(3, 300) if err != nil { - return fmt.Errorf("Error during vdc Deletion !!: %w", err) + return fmt.Errorf("error during vdc Deletion !!: %w", err) } s.FinalMSG = "vdc resource deleted " + arg + " successfully !!\n" s.Stop() diff --git a/cmd/get_edgegateway.go b/cmd/get_edgegateway.go index 5934a08..877e50d 100644 --- a/cmd/get_edgegateway.go +++ b/cmd/get_edgegateway.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1" "github.com/orange-cloudavenue/common-go/print" "github.com/spf13/cobra" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" ) // getEdgeGatewayCmd return a list of your edgegateway resource(s) @@ -25,11 +26,11 @@ var getEdgeGatewayCmd = &cobra.Command{ // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set and print time elapsed - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -65,7 +66,7 @@ var getEdgeGatewayCmd = &cobra.Command{ case flagOutputValueJSON, flagOutputValueYAML: x, err := output.New(stringToTypeFormat(flag), edgeGateways) if err != nil { - return fmt.Errorf("Impossible to format output: %w", err) + return fmt.Errorf("impossible to format output: %w", err) } x.ToOutput() case "": @@ -74,7 +75,7 @@ var getEdgeGatewayCmd = &cobra.Command{ w.AddFields(e.EdgeName, e.OwnerName) } default: - return fmt.Errorf("Output format %v: %w", flag, customErrors.ErrNotValidOutput) + return fmt.Errorf("output format %v: %w", flag, errorscustom.ErrNotValidOutput) } w.PrintTable() return nil diff --git a/cmd/get_publicip.go b/cmd/get_publicip.go index 539fd69..b153be3 100644 --- a/cmd/get_publicip.go +++ b/cmd/get_publicip.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1" "github.com/orange-cloudavenue/common-go/print" "github.com/spf13/cobra" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" ) // getPublicIPCmd return a list of your publicip @@ -25,11 +26,11 @@ var getPublicIPCmd = &cobra.Command{ // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set and print time elapsed - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -67,7 +68,7 @@ var getPublicIPCmd = &cobra.Command{ case flagOutputValueJSON, flagOutputValueYAML: x, err := output.New(stringToTypeFormat(flag), ips) if err != nil { - return fmt.Errorf("Impossible to format output: %w", err) + return fmt.Errorf("impossible to format output: %w", err) } x.ToOutput() case "": @@ -76,7 +77,7 @@ var getPublicIPCmd = &cobra.Command{ w.AddFields(i.UplinkIP, i.EdgeGatewayName) } default: - return fmt.Errorf("Output format %v: %w", flag, customErrors.ErrNotValidOutput) + return fmt.Errorf("output format %v: %w", flag, errorscustom.ErrNotValidOutput) } w.PrintTable() return nil diff --git a/cmd/get_s3.go b/cmd/get_s3.go index a7ea02f..4a75d5b 100644 --- a/cmd/get_s3.go +++ b/cmd/get_s3.go @@ -5,10 +5,11 @@ import ( "time" "github.com/aws/aws-sdk-go/service/s3" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" "github.com/orange-cloudavenue/common-go/print" "github.com/spf13/cobra" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" ) // getS3Cmd return a list of your s3 (bucket) resource(s) @@ -25,11 +26,11 @@ var getS3Cmd = &cobra.Command{ // init Config File & Client if err := initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set and print time elapsed - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -61,7 +62,7 @@ var getS3Cmd = &cobra.Command{ case flagOutputValueJSON, flagOutputValueYAML: x, err := output.New(stringToTypeFormat(flag), s3s) if err != nil { - return fmt.Errorf("Impossible to format output: %w", err) + return fmt.Errorf("impossible to format output: %w", err) } x.ToOutput() case "": @@ -70,7 +71,7 @@ var getS3Cmd = &cobra.Command{ w.AddFields(*b.Name, *s3s.Owner.DisplayName) } default: - return fmt.Errorf("Output format %v: %w", flag, customErrors.ErrNotValidOutput) + return fmt.Errorf("output format %v: %w", flag, errorscustom.ErrNotValidOutput) } w.PrintTable() return nil diff --git a/cmd/get_t0.go b/cmd/get_t0.go index 5dd41be..7c3753c 100644 --- a/cmd/get_t0.go +++ b/cmd/get_t0.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1" "github.com/orange-cloudavenue/common-go/print" "github.com/spf13/cobra" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" ) // getT0Cmd return a list of your t0 resource(s) @@ -24,11 +25,11 @@ var getT0Cmd = &cobra.Command{ // init Config File & Client if err = initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set and print time elapsed - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -64,7 +65,7 @@ var getT0Cmd = &cobra.Command{ case flagOutputValueJSON, flagOutputValueYAML: x, err := output.New(stringToTypeFormat(flag), t0s) if err != nil { - return fmt.Errorf("Impossible to format output: %w", err) + return fmt.Errorf("impossible to format output: %w", err) } x.ToOutput() case "": @@ -73,7 +74,7 @@ var getT0Cmd = &cobra.Command{ w.AddFields(t0.Tier0Vrf, t0.Tier0Provider) } default: - return fmt.Errorf("Output format %v: %w", flag, customErrors.ErrNotValidOutput) + return fmt.Errorf("output format %v: %w", flag, errorscustom.ErrNotValidOutput) } w.PrintTable() return nil diff --git a/cmd/get_vdc.go b/cmd/get_vdc.go index a5e64aa..6ad4f45 100644 --- a/cmd/get_vdc.go +++ b/cmd/get_vdc.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" "github.com/orange-cloudavenue/common-go/print" "github.com/spf13/cobra" "github.com/vmware/go-vcloud-director/v2/types/v56" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output" ) // getVDCCmd return a list of your vdc resource(s) @@ -24,11 +25,11 @@ var getVDCCmd = &cobra.Command{ // init Config File & Client if err = initConfig(); err != nil { - return fmt.Errorf("Unable to initialize: %w", err) + return fmt.Errorf("unable to initialize: %w", err) } // Check if time flag is set and print time elapsed - if cmd.Flag(flagTime).Value.String() == "true" { + if cmd.Flag(flagTime).Value.String() == trueValue { defer timeTrack(time.Now(), cmd.CommandPath()) } @@ -64,7 +65,7 @@ var getVDCCmd = &cobra.Command{ case flagOutputValueJSON, flagOutputValueYAML: x, err := output.New(stringToTypeFormat(flag), vdcs) if err != nil { - return fmt.Errorf("Impossible to format output: %w", err) + return fmt.Errorf("impossible to format output: %w", err) } x.ToOutput() case "": @@ -73,7 +74,7 @@ var getVDCCmd = &cobra.Command{ w.AddFields(v.Name, v.Status) } default: - return fmt.Errorf("Output format %v: %w", flag, customErrors.ErrNotValidOutput) + return fmt.Errorf("output format %v: %w", flag, errorscustom.ErrNotValidOutput) } w.PrintTable() return nil diff --git a/cmd/root.go b/cmd/root.go index 6f973ff..da502b9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,7 @@ func Execute() (err error) { // Execute root command if err = rootCmd.Execute(); err != nil { - return fmt.Errorf("Command return an Error: %w", err) + return fmt.Errorf("command return an Error: %w", err) } return nil } diff --git a/cmd/root_client.go b/cmd/root_client.go index c311b5e..60b84d0 100644 --- a/cmd/root_client.go +++ b/cmd/root_client.go @@ -6,10 +6,11 @@ import ( "os" "github.com/mitchellh/go-homedir" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" "github.com/orange-cloudavenue/cloudavenue-sdk-go" clientcloudavenue "github.com/orange-cloudavenue/cloudavenue-sdk-go/pkg/clients/cloudavenue" "github.com/spf13/viper" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" ) // function to initialize the configuration file @@ -17,7 +18,7 @@ func initConfig() error { // Find the home directory home, err := homedir.Dir() if err != nil { - return fmt.Errorf("Home Directory %s is: %w, %w", home, customErrors.ErrNoHomeDirectory, err) + return fmt.Errorf("home directory %s is: %w, %w", home, errorscustom.ErrNoHomeDirectory, err) } // Set default file configuration v := viper.New() @@ -25,12 +26,12 @@ func initConfig() error { v.SetConfigType("yaml") v.AddConfigPath(home + configPath) if home == "" { - return fmt.Errorf("Error Home Directory: %w", errors.New(customErrors.ErrNoHomeDirectory.Error())) + return fmt.Errorf("error home directory: %w", errors.New(errorscustom.ErrNoHomeDirectory.Error())) } // Create configuration file if not exist if _, err = os.Stat(home + fileConfigPath); os.IsNotExist(err) { - if err = os.MkdirAll(home+configPath, 0755); err != nil { - return fmt.Errorf("Error canot create directory %s: %w, %w", home+configPath, customErrors.ErrNoHomeDirectory, err) + if err = os.MkdirAll(home+configPath, 0o755); err != nil { + return fmt.Errorf("error canot create directory %s: %w, %w", home+configPath, errorscustom.ErrNoHomeDirectory, err) } // Set default configuration cloudavenueConfig := cloudavenueConfig{} @@ -39,7 +40,7 @@ func initConfig() error { // Write configuration file if err = v.SafeWriteConfig(); err != nil { - return fmt.Errorf("Error write config: %w", err) + return fmt.Errorf("error write config: %w", err) } s.FinalMSG = ` *** @@ -52,7 +53,7 @@ func initConfig() error { // Read configuration file err = v.ReadInConfig() if err != nil { - return fmt.Errorf("Unable to read config file: %w, %w", customErrors.ErrConfigFile, err) + return fmt.Errorf("unable to read config file: %w, %w", errorscustom.ErrConfigFile, err) } return initClient(v) } @@ -69,7 +70,7 @@ func initClient(v *viper.Viper) (err error) { }, }) if err != nil { - return fmt.Errorf("Unable to init cloudavenue client: %w, %w", customErrors.ErrClient, err) + return fmt.Errorf("unable to init cloudavenue client: %w, %w", errorscustom.ErrClient, err) } return nil } diff --git a/cmd/root_global.go b/cmd/root_global.go index e64ffaa..434e530 100644 --- a/cmd/root_global.go +++ b/cmd/root_global.go @@ -5,9 +5,10 @@ import ( "time" "github.com/briandowns/spinner" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output/model" "github.com/orange-cloudavenue/cloudavenue-sdk-go" "github.com/spf13/cobra" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output/model" ) const ( @@ -34,6 +35,8 @@ const ( configPath = "/.cav" fileConfig = "config.yaml" fileConfigPath = configPath + "/" + fileConfig + // ? Constants values for true + trueValue = "true" ) var ( diff --git a/cmd/root_test.go b/cmd/root_test.go index bc51f85..7d10640 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -3,13 +3,13 @@ package cmd_test import ( "bytes" "fmt" - "os" "strings" "testing" - "github.com/orange-cloudavenue/cloudavenue-cli/cmd" "github.com/spf13/cobra" "github.com/spf13/pflag" + + "github.com/orange-cloudavenue/cloudavenue-cli/cmd" ) const ( @@ -38,7 +38,7 @@ func TestRootCmd(t *testing.T) { // ? Test configuration // Bad configuration t.Run("Bad Configuration", func(t *testing.T) { - os.Setenv("CLOUDAVENUE_URL", "https://console1.cloudavenue.orange-business.blackhole") + t.Setenv("CLOUDAVENUE_URL", "https://console1.cloudavenue.orange-business.blackhole") if err := cmd.Execute(); err != nil { check := err.Error() if !strings.Contains(check, "Please check your configuration") { @@ -48,9 +48,9 @@ func TestRootCmd(t *testing.T) { }) // Good configuration - fmt.Println("=Good Configuration") + // fmt.Println("=Good Configuration") t.Run("Configuration", func(t *testing.T) { - os.Setenv("CLOUDAVENUE_URL", "https://console1.cloudavenue.orange-business.com") + t.Setenv("CLOUDAVENUE_URL", "https://console1.cloudavenue.orange-business.com") if err := cmd.Execute(); err != nil { t.Errorf("Fail %v", err) } @@ -83,20 +83,20 @@ func TestRootCmd(t *testing.T) { fail: true, // Should fail because flag no exist }, { - name: oneCmd.Use + "_" + cmdSubCmd.Use + " with ouput flag without args", + name: oneCmd.Use + "_" + cmdSubCmd.Use + " with output flag without args", args: []string{oneCmd.Use, cmdSubCmd.Use, "--output"}, fail: true, // Should fail because args for flag is empty }, { - name: oneCmd.Use + "_" + cmdSubCmd.Use + " with ouput flag wide args", + name: oneCmd.Use + "_" + cmdSubCmd.Use + " with output flag wide args", args: []string{oneCmd.Use, cmdSubCmd.Use, "--output", "wide"}, }, { - name: oneCmd.Use + "_" + cmdSubCmd.Use + " with ouput flag json args", + name: oneCmd.Use + "_" + cmdSubCmd.Use + " with output flag json args", args: []string{oneCmd.Use, cmdSubCmd.Use, "--output", "json"}, }, { - name: oneCmd.Use + "_" + cmdSubCmd.Use + " with ouput flag yaml args", + name: oneCmd.Use + "_" + cmdSubCmd.Use + " with output flag yaml args", args: []string{oneCmd.Use, cmdSubCmd.Use, "--output", "yaml"}, }, { @@ -289,7 +289,7 @@ func TestRootCmd(t *testing.T) { default: if oneCmd.Use == "" { - fmt.Printf("No test for this subcommand: %v", oneCmd.Use) + fmt.Printf("No test for this command: %v", oneCmd.Use) } } } @@ -298,7 +298,6 @@ func TestRootCmd(t *testing.T) { startTest(getTests, t) startTest(delTests, t) startTest(globalTests, t) - } func startTest(tests tts, t *testing.T) { @@ -324,9 +323,7 @@ func startTest(tests tts, t *testing.T) { resetFlags(x) x.SetOut(nil) x.SetErr(nil) - }) - } } diff --git a/docs/advanced/advanced-installation.md b/docs/advanced/advanced-installation.md index 53800b7..a2cbd7f 100644 --- a/docs/advanced/advanced-installation.md +++ b/docs/advanced/advanced-installation.md @@ -23,7 +23,7 @@ Version: __GITTAG__ && curl -LO https://github.com/orange-cloudavenue/cloudavenue-cli/releases/download/__GITTAG__/cloudavenue-cli___GITTAG___386.apk \ && sha256sum --ignore-missing -c cloudavenue-cli___GITTAG___checksums.txt \ && sudo apk add cloudavenue-cli___GITTAG___386.apk - + !!! Note For other Arch please replace word `386` by `amd64` or `arm64` @@ -31,7 +31,7 @@ Version: __GITTAG__ ``` powershell Invoke-WebRequest https://github.com/orange-cloudavenue/cloudavenue-cli/releases/download/__GITTAG__/cloudavenue-cli___GITTAG___checksums.txt -OutFile "cav-checksum.txt" Invoke-WebRequest https://github.com/orange-cloudavenue/cloudavenue-cli/releases/download/__GITTAG__/cloudavenue-cli___GITTAG___windows_amd64.zip -OutFile "cloudavenue-cli___GITTAG___windows_amd64.zip" -Expand-Archive -LiteralPath 'cloudavenue-cli___GITTAG___windows_amd64.zip' -DestinationPath 'c:\cloudavenue\' +Expand-Archive -LiteralPath 'cloudavenue-cli___GITTAG___windows_amd64.zip' -DestinationPath 'c:\cloudavenue\' Get-FileHash 'c:\cloudavenue\cav.exe' -Algorithm SHA256 | Format-List ``` !!! Note diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index 4d2dd72..0b11742 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -1,6 +1,6 @@ ## Configuration -Two ways possible to configure your CLI. +Two ways possible to configure your CLI. ### Configuration File @@ -8,7 +8,7 @@ On the first try, a config file locate in your home directory, under the followi ```{ .shell .no-copy } > cav -Configuration file created in /root/.cav/config.yaml +Configuration file created in /root/.cav/config.yaml Please fill it with your credentials and re-run the command. ``` diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index 8c65556..e4fe8cc 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -1,6 +1,6 @@ ## Installation -The binary `cav` will be installed in `/usr/local/bin/` directory. +The binary `cav` will be installed in `/usr/local/bin/` directory. ### Automatic installation ```bash diff --git a/docs/index.md b/docs/index.md index 9044df1..c3b9455 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,7 +24,7 @@ Is based on the Terraform [Provider Cloud Avenue](https://registry.terraform.io/ It can quickly create an object with a simple template defined in the application coding (in futur release with a parameter template). No needs to use terraform to see your IAAS state. It is recommended to use it when you want to perform a quick operation on your infrastructure. -See [demo below](index.md#demo) +See [demo below](index.md#demo) !!! info If you need more information about Cloud Avenue, please visit [Cloud Avenue documentation](https://wiki.cloudavenue.orange-business.com/wiki/Welcome). diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index 801c492..6b08f9b 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -1,3 +1,3 @@ .md-grid { - max-width: 1440px; + max-width: 1440px; } \ No newline at end of file diff --git a/githooks b/githooks deleted file mode 160000 index 739d891..0000000 --- a/githooks +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 739d89142682f092dbfa4be2d4da47d755e6c931 diff --git a/go.mod b/go.mod index 4c85ce1..5abfde5 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 github.com/vmware/go-vcloud-director/v2 v2.26.0 + google.golang.org/appengine v1.6.8 gopkg.in/yaml.v3 v3.0.1 ) @@ -100,7 +101,7 @@ require ( golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect - google.golang.org/appengine v1.6.8 // indirect + golang.org/x/tools v0.19.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect google.golang.org/grpc v1.62.1 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index f0b76de..831dc01 100644 --- a/go.sum +++ b/go.sum @@ -326,8 +326,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/main.go b/main.go index 7547e22..acab243 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/orange-cloudavenue/cloudavenue-cli/cmd" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/customErrors" + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/errorscustom" ) const ( @@ -17,14 +17,14 @@ const ( func main() { if err := cmd.Execute(); err != nil { switch { - case customErrors.IsNoHomeDirectory(err): + case errorscustom.IsNoHomeDirectory(err): fmt.Println(errorMessage+"Check your system to set and access write to your home directory.", err) - case customErrors.IsConfigFile(err): + case errorscustom.IsConfigFile(err): fmt.Println(errorMessage+"Please check your configuration file.", err) - case customErrors.IsClient(err): + case errorscustom.IsClient(err): fmt.Println(errorMessage+"Unable to initialize client", err) fmt.Println("Please check your configuration (https://orange-cloudavenue.github.io/cloudavenue-cli/getting-started/configuration/).") - case customErrors.IsNotValidOutput(err): + case errorscustom.IsNotValidOutput(err): fmt.Println(errorMessage+"Please read help to check format output is possible.", err) default: fmt.Println(errorMessage + err.Error()) diff --git a/mkdocs.yml b/mkdocs.yml index 3e89ad0..3530a6d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -39,21 +39,21 @@ plugins: - search nav: - - Home: + - Home: - index.md - Getting Started: - Installation: getting-started/installation.md - Configuration: getting-started/configuration.md - Command: - command/cav.md - - get: + - get: - command/cav_get.md - VDC: command/cav_get_vdc.md - S3: command/cav_get_s3.md - T0: command/cav_get_t0.md - Public IP: command/cav_get_publicip.md - EdgeGateway: command/cav_get_edgegateway.md - - create: + - create: - command/cav_create.md - VDC: command/cav_create_vdc.md - S3: command/cav_create_s3.md diff --git a/pkg/customErrors/customErrors.go b/pkg/errorscustom/errorscustom.go similarity index 66% rename from pkg/customErrors/customErrors.go rename to pkg/errorscustom/errorscustom.go index 227ce69..009e382 100644 --- a/pkg/customErrors/customErrors.go +++ b/pkg/errorscustom/errorscustom.go @@ -1,14 +1,14 @@ -package customErrors +package errorscustom import "errors" var ( // Generic Error type - ErrNotValidOutput = errors.New("not valid output.") - ErrNoHomeDirectory = errors.New("no home directory.") - ErrNotImplemented = errors.New("not implemented.") - ErrConfigFile = errors.New("error to configuration file.") - ErrClient = errors.New("error to initialize client.") + ErrNotValidOutput = errors.New("not valid output") + ErrNoHomeDirectory = errors.New("no home directory") + ErrNotImplemented = errors.New("not implemented") + ErrConfigFile = errors.New("error to configuration file") + ErrClient = errors.New("error to initialize client") ) // IsNoHomeDirectory checks if the error is of type ErrNoHomeDirectory diff --git a/pkg/output/model/model.go b/pkg/output/model/model.go index 907f06b..8928e94 100644 --- a/pkg/output/model/model.go +++ b/pkg/output/model/model.go @@ -6,7 +6,9 @@ type Formatter interface { type TypeFormat string -const TypeJSON TypeFormat = "json" -const TypeYAML TypeFormat = "yaml" +const ( + TypeJSON TypeFormat = "json" + TypeYAML TypeFormat = "yaml" +) var ListTypeFormat = []TypeFormat{TypeJSON, TypeYAML} diff --git a/pkg/output/output.go b/pkg/output/output.go index c66eff2..22b3b02 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -15,5 +15,5 @@ func New(format model.TypeFormat, data any) (model.Formatter, error) { case model.TypeYAML: return oyaml.New(data) } - return nil, fmt.Errorf("Error creating output") + return nil, fmt.Errorf("error creating output") } diff --git a/pkg/output/oyaml/oyaml.go b/pkg/output/oyaml/oyaml.go index 05a7ece..b16bb48 100644 --- a/pkg/output/oyaml/oyaml.go +++ b/pkg/output/oyaml/oyaml.go @@ -3,8 +3,9 @@ package oyaml import ( "fmt" - "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output/model" "gopkg.in/yaml.v3" + + "github.com/orange-cloudavenue/cloudavenue-cli/pkg/output/model" ) var _ model.Formatter = oyaml{} diff --git a/scripts/install.sh b/scripts/install.sh index 3fef31f..eff961d 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -47,7 +47,7 @@ execute() { http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}" hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}" srcdir="${tmpdir}/${NAME}" - rm -rf "${srcdir}" + rm -rf "${srcdir}" (cd "${tmpdir}" && untar "${TARBALL}") test ! -d "${BINDIR}" && install -d "${BINDIR}" for binexe in $BINARIES; do