https://github.com/mondoohq/mondoo-go
Go library for the Mondoo API.
https://github.com/mondoohq/mondoo-go
api
Last synced: 5 months ago
JSON representation
Go library for the Mondoo API.
- Host: GitHub
- URL: https://github.com/mondoohq/mondoo-go
- Owner: mondoohq
- License: other
- Created: 2023-09-30T16:51:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T15:59:00.000Z (12 months ago)
- Last Synced: 2024-10-21T18:22:42.003Z (12 months ago)
- Topics: api
- Language: Go
- Homepage: https://mondoo.com
- Size: 175 KB
- Stars: 2
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mondoo Platform GraphQL API Client for Go
Status: It is currently in beta.
This is a Go client library for Mondoo Platform API using GraphQL. Mondoo is a security, risk and compliance
platform that provides continuous insight into your infrastructure. This library enables you to interact
programmatically with Mondoo Platform to perform various tasks such as querying assets, setup integrations, and
fetching vulnerability and policy reports.## Features
- Easy-to-use API to query data from Mondoo
- Strongly typed GraphQL queries and mutations
- Support for GraphQL subscriptions
- Token-based authentication## Requirements
Our libraries are compatible with at least the three most recent, major Go
releases. They are currently compatible with:- Go 1.21
- Go 1.20
- Go 1.19In addition, a Mondoo account with API access is required to use this library.
## Installation
To install the package, run:
```bash
go get go.mondoo.com/mondoo-go
```## Quick Start
Here is a quick example to fetch the details of an asset:
```go
package mainimport (
"context"
"fmt"
"log"
"os""go.mondoo.com/mondoo-go"
"go.mondoo.com/mondoo-go/option"
)func main() {
// Initialize the client
client, err := mondoogql.NewClient(option.UseUSRegion(), option.WithAPIToken(os.Getenv("MONDOO_API_TOKEN")))
if err != nil {
log.Fatal(err)
}// Fetch asset details
assetMrn := "//assets.api.mondoo.app/spaces/dreamy-ellis-859675/assets/2TwUNCJcoPG5vHfUJaMf2gRgIaY"
var q struct {
Report struct {
AssetReport struct {
Asset struct {
Name string
}
} `graphql:"... on AssetReport"`
} `graphql:"assetReport(input: { assetMrn: $assetMrn} )"`
}
variables := map[string]interface{}{
"assetMrn": mondoogql.ID(assetMrn),
}
err = client.Query(context.Background(), &q, variables)
if err != nil {
log.Fatalln(err)
}
fmt.Println(q.Report.AssetReport.Asset.Name)
}
```## Test
Run all tests:
```bash
make test
```For any requests, bug or comments, please [open an issue][issues] or [submit a
pull request][pulls].## Development
When developing new APIs locally, you can overwrite the API endpoint.
Specify `MONDOO_API_ENDPOINT` environment variable for the `generate` command, e.g.,:
```
MONDOO_API_ENDPOINT=http://127.0.0.1:8989 make generate
```## Kudos
This implementation is heavily inspired by the [GitHub GraphQL Go Client](https://github.com/shurcooL/githubv4).
[issues]: https://github.com/mondoohq/mondoo-go/issues/new
[pulls]: https://github.com/mondoohq/mondoo-go/pulls