Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for Cloudcraft Go SDK #1

Merged
merged 9 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: "Bug report"
about: "Create a report to help us improve."
title: ""
labels: "bug, needs triage"
assignees: ""
---

**Describe the bug**
A clear and concise description of the bug.

**Environment and versions**
A clear and precise description of your setup.

- Version of the client in use.
- Services, libraries, languages and tools list and versions.

**To reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '...'
3. Scroll down to '...'
4. See the error.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Cloudcraft support
url: https://app.cloudcraft.co/app/support
about: Our friendly, knowledgeable support engineers are here to help.
- name: Cloudcraft security
url: https://www.cloudcraft.co/security
about: We care about security. If you have any questions, or encounter any issues, please contact us.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: "Feature request"
about: "Suggest an idea for this project."
title: ""
labels: "enhancement, needs triage"
assignees: ""
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
35 changes: 35 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
**Requirements for Contributing to this repository**

Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

For more details, please see [CONTRIBUTING.md](/CONTRIBUTING.md).
-->

### What does this PR do?

<!--

What inspired you to submit this pull request? Link to the issue describing the bug that you're fixing.

If there is not yet an issue for your bug, please open a new issue and then link to that issue in your pull request.

If the pull request does not address an existing issue with the "bug" label, the maintainers have the final say on whether the current behavior is a bug.

We must be able to understand the design of your change from this description. If we can't get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion.

Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts.

-->

### Additional Notes

<!-- Anything else we should know when reviewing? -->

### Review checklist

Please check relevant items below:

- [ ] The title & description contain a short meaningful summary of work completed.
- [ ] Tests have been updated/created and are passing locally.
- [ ] I've reviewed the [CONTRIBUTING.md](/CONTRIBUTING.md) file.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: 'Tests'
on:
push:
paths-ignore:
- '.editorconfig'
- '.gitignore'
- '.golangci.toml'
- 'CONTRIBUTING.md'
- 'LICENSE-3rdparty.csv'
- 'LICENSE.md'
- 'NOTICE'
- 'README.md'
- 'SUPPORT.md'
pull_request:
paths-ignore:
- '.editorconfig'
- '.gitignore'
- '.golangci.toml'
- 'CONTRIBUTING.md'
- 'LICENSE-3rdparty.csv'
- 'LICENSE.md'
- 'NOTICE'
- 'README.md'
- 'SUPPORT.md'

jobs:
test:
runs-on: 'ubuntu-latest'
name: 'Tests'
steps:
- uses: 'actions/checkout@v4'

- name: 'Setup Go environment'
uses: 'actions/setup-go@v4'
with:
go-version: '>=1.21.5'

- name: 'Run mock tests'
run: 'make test'
49 changes: 49 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: 'Lint'
on:
push:
paths-ignore:
- '.editorconfig'
- '.gitignore'
- '.golangci.toml'
- 'CONTRIBUTING.md'
- 'LICENSE-3rdparty.csv'
- 'LICENSE.md'
- 'NOTICE'
- 'README.md'
- 'SUPPORT.md'
pull_request:
paths-ignore:
- '.editorconfig'
- '.gitignore'
- '.golangci.toml'
- 'CONTRIBUTING.md'
- 'LICENSE-3rdparty.csv'
- 'LICENSE.md'
- 'NOTICE'
- 'README.md'
- 'SUPPORT.md'

permissions:
contents: 'read'

jobs:
go:
name: 'Lint Go files'
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v4'

- name: 'Setup Go environment'
uses: 'actions/setup-go@v4'
with:
go-version: '>=1.21.5'

- name: 'Run govulncheck'
run: 'make vulnerabilities'

- name: 'Run gofumpt'
run: 'make fmt'

- name: 'Run golangci-lint'
run: 'make lint'
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contribution guidelines

Thank you for your interest in improving our Go client! Follow these guidelines to contribute effectively and get your patches accepted.

## Commit sign-off

Remember to sign-off on your commits by running `git commit --signoff` before pushing. To understand what this means, read [the Linux Kernel Developer's Certificate of Origin](https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin).

## Submission guidelines

Adhere to the following rules when submitting your PR:

- **Keep it small**: Avoid changing too many things at once.
- **Individual PRs**: One PR per issue, please.
- **Commit messages**: Take a moment to write meaningful commit messages.
- **Quality assurance**: [Review your spelling and grammar](https://languagetool.org/).
- **Testing**: Write tests and ensure your changes do not break any existing functionality by running `make test`.
- **Respect the coding style**: Maintain the style of the codebase in your contributions.

## License

All contributions are made under [the Apache-2.0 license](LICENSE.md).
2 changes: 2 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Component,Origin,License,Copyright
go.sum,golang.org/x/time,BSD-3-Clause,2019 The Go Authors
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.POSIX:
.SUFFIXES:

GO = go
GIT = git
RM = rm

-include .env
export

all: pre-commit

pre-commit: tidy fmt lint vulnerabilities test build clean # Runs all pre-commit checks.

commit: pre-commit # Commits the changes to the repository.
$(GIT) commit -s

push: commit # Pushes the changes to the repository.
$(GIT) push origin trunk

doc: # Serve the documentation locally.
$(GO) run golang.org/x/tools/cmd/godoc@latest -http=localhost:1967

tidy: # Updates the go.mod file to use the latest versions of all direct and indirect dependencies.
$(GO) mod tidy

fmt: # Formats Go source files in this repository.
$(GO) run mvdan.cc/gofumpt@latest -e -extra -w .

lint: # Runs golangci-lint using the config at the root of the repository.
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run ./...

vulnerabilities: # Analyzes the codebase and looks for vulnerabilities affecting it.
$(GO) run golang.org/x/vuln/cmd/govulncheck@latest ./...

test: # Runs unit tests.
$(GO) test -short -cover -race -vet all -mod readonly ./...

test/integration: # Runs integration tests.
$(GO) test -cover -race -vet all -mod readonly ./tests/integration

test/coverage: # Generates a coverage profile and open it in a browser.
$(GO) test -short -coverprofile cover.out ./...
$(GO) tool cover -html=cover.out

clean: # Cleans cache files from tests and deletes any build output.
$(RM) -f cover.out

.PHONY: all pre-commit commit push doc tidy fmt lint vulnerabilities test test/coverage clean
3 changes: 3 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright 2023-Present Datadog, Inc.

This product includes software developed at Datadog (<https://www.datadoghq.com/).>
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# cloudcraft-go

[![Go Documentation](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/DataDog/cloudcraft-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/DataDog/cloudcraft-go)](https://goreportcard.com/report/github.com/DataDog/cloudcraft-go)

![Cloudcraft diagram](https://static.cloudcraft.co/sdk/cloudcraft-sdk-example-1.svg)

Visualize your cloud architecture with Cloudcraft by Datadog, [the best way to create smart AWS and Azure diagrams](https://www.cloudcraft.co/).

Cloudcraft supports both manual and programmatic diagramming, as well as automatic reverse engineering of existing cloud environments into
beautiful system architecture diagrams.

This `cloudcraft-go` package provides an easy-to-use native Go SDK for interacting with [the Cloudcraft API](https://developers.cloudcraft.co/).

Use case examples:
- Snapshot and visually compare your live AWS or Azure environment before and after a deployment, in your app or as part of your automated CI pipeline
- Download an inventory of all your cloud resources from a linked account as JSON
- Write a converter from a third party data format to Cloudcraft diagrams
- Backup, export & import your Cloudcraft data
- Programmatically create Cloudcraft diagrams

This SDK requires a [Cloudcraft API key](https://developers.cloudcraft.co/#authentication) to use. [A free trial of Cloudcraft Pro](https://www.cloudcraft.co/pricing) with API access is available.

## Installation

To install `cloudcraft-go`, run:

```console
go get github.com/DataDog/cloudcraft-go
```

## Go SDK Documentation

Usage details and more examples, please [see the Go reference documentation](https://godocs.io/github.com/DataDog/cloudcraft-go).

## Example Usage

In the below example the Cloudcraft API key is read from the `CLOUDCRAFT_API_KEY` environment variable. Alternatively, pass in the key to the configuration directly.

```go
package main

import (
"context"
"log"
"os"

"github.com/DataDog/cloudcraft-go"
)

func main() {
key, ok := os.LookupEnv("CLOUDCRAFT_API_KEY")
if !ok {
log.Fatal("missing env var: CLOUDCRAFT_API_KEY")
}

// Create new Config to be initialize a Client.
cfg := cloudcraft.NewConfig(key)

// Create a new Client instance with the given Config.
client, err := cloudcraft.NewClient(cfg)
if err != nil {
log.Fatal(err)
}

// List all blueprints in an account.
blueprints, _, err := client.Blueprint.List(context.Background())
if err != nil {
log.Fatal(err)
}

// Print the name of each blueprint.
for _, blueprint := range blueprints {
log.Println(blueprint.Name)
}
}
```

## Contributing

Anyone can help make `cloudcraft-go` better. Check out [the contribution guidelines](CONTRIBUTING.md) for more information.

---

Released under the [Apache-2.0 License](LICENSE.md).
5 changes: 5 additions & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Support

The issue queue we have here on GitHub is primarily intended for tracking features, bugs and work items associated with Cloudcraft's Go client.

For any other support request, please [reach out to our support team](https://app.cloudcraft.co/app/support).
Loading