Skip to content

MagaluCloud/magalu

Repository files navigation

MGC

This repository contains the monorepo developed for Magalu Cloud (MGC). Each subdirectory within mgc/ corresponds to a Go module:

  • Core: Definition of data types used for the intermediate structure generated by the SDK after parsing either an OpenAPI spec or a static definition.

  • SDK: Implement the concrete data types defined by core to generate usable commands. The commands can be used by the CLI via Cobra commands, or by Terraform Plugin Provider to perform CRUD on resources.

  • CLI: Go CLI, using Cobra, with commands and actions defined by the SDK. The commands can either come from dynamic loaded OpenAPI spec or static modules, i.e: authentication.

  • Lib: A Go library, a human-readable SDK. Its code is automatically generated.

Our code is written in Golang, however there are some utility scripts written in Python as well.

Looking for Terraform code? Check out the Terraform provider repository

Dependencies

To run the project, the main dependency needed is Go. To install, visit the official link with the instructions.

There are some utility scripts written in Python. For this, Poetry is used. Check Poetry.md for instructions.

Running the CLI

See cli/RUNNING.md

OpenAPI

See sdk/openapi/README.md

Adding new APIs

OpenAPIs

To add a new API spec, see ADD_NEW_API.md.

Static APIs

Manually written APIs should be added to mgc/sdk/static, follow the structure in the exiting modules (auth, config).

Contributing

pre-commit

We use pre-commit to install git hooks and enforce lint, formatting, tests, commit messages and others. This tool depends on Python as well. On pre-commit we enforce:

  • On commit-msg for all commits:
  • On pre-commit for Go files:
    • Complete set of golangci-lint: errcheck, gosimple, govet, ineffasign, staticcheck, unused
  • On pre-commit for Python files:
    • flake8 and black enforcing pep code styles

Installation

Mac

brew install pre-commit

pip

pip install pre-commit

For other types of installation, check their official doc.

Configuration

After installing, the developer must configure the git hooks inside its clone:

pre-commit install

Linters

We install the go linters via pre-commit, so it is automatically run by the pre-commit git hook. However, if one wants to run standalone it can be done via:

pre-commit run golangci-lint

Run all

Run pre-commit without any file modified:

pre-commit run -a