Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix(docs): Update instructions for adding new resources and add insta…
Browse files Browse the repository at this point in the history
…ll-tools command (#1128)
  • Loading branch information
hermanschaaf authored Jun 30, 2022
1 parent b467c68 commit 29ac7d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ test-unit:
.PHONY: test-integration
test-integration:
@if [[ "$(tableName)" == "" ]]; then go test -run=TestIntegration -timeout 3m -tags=integration ./...; else go test -run="TestIntegration/$(tableName)" -timeout 3m -tags=integration ./...; fi

# Install tools
.PHONY: install-tools
install-tools:
@echo Installing tools from tools/tool.go
@cat tools/tool.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
22 changes: 11 additions & 11 deletions docs/contributing/adding_a_new_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ If the service to which the resource belongs has not been used before in cq-prov
* Don't forget to add the new service interface name to the go:generate comment.
1. Add the service to the `Services` struct in the [client/client.go](../../client/client.go)
1. Init the service in the `initServices` function in [client/client.go](../../client/client.go)
1. Run `go generate client/services.go` to create a mock for your new service. This will update [client/mocks/<service>.go](../../client/mocks) automatically
1. Run `go generate client/services.go` to create a mock for your new service. This will update [client/mocks/mock_<service>.go](../../client/mocks) automatically

> On MacOS, if you get an error about not being able to find `mockgen`, `export PATH=${PATH}:`go env GOPATH`/bin` in you shell to set up your `PATH` environment properly
> If you get an error about not being able to find `mockgen`, run `make install-tools` to install it. If it still fails, run `export PATH=${PATH}:`go env GOPATH`/bin` in you shell to set up your `PATH` environment properly
> You might need to update an existing AWS client by running `go get github.com/aws/aws-sdk-go-v2/service/<service-name>@latest` and then `go mod tidy`
## Setting up the resource

### Skeleton

1. In [client/services.go](./client/services.go), update the service interface and add the method(s) that you will be using to fetch the data from the aws sdk.
1. Run `go generate client/services.go` to create a mock for your new methods. This will update [client/mocks/services.go](./client/mocks/services.go) automatically
1. Create a file under `resources/` that follows the pattern of `<service>_<resource>`.
1. In that file, create a function that returns a `*schema.Table`
1. In [resources/provider.go](./resources/provider.go), add a mapping between the function you just created and the name of the resource that will be used in the config yml file.
1. Add a test file at `resources/<service>_<resource>_test.go`. Follow other examples to create a test for the resource.
1. Run `go run docs/docs.go` to generate the documentation for the new resource
1. In [client/services.go](../../client/services.go), update the service interface and add the method(s) that you will be using to fetch the data from the aws sdk.
1. Run `go generate client/services.go` to create a mock for your new methods. This will update [client/mocks/mock_<service>.go](../../client/mocks) automatically.
1. Create a file under [resources/services/<service>](../../resources/services) that follows the pattern of `<resource>.go`.
1. In that file, create a function that returns a `*schema.Table`.
1. In [resources/provider.go](../../resources/provider/provider.go), add a mapping between the function you just created and the name of the resource that will be used in the config yml file.
1. Add a test file at [resources/services/<service>/<resource>_mock_test.go](../../resources/services). Follow other examples to create a test for the resource.
1. Run `go run docs/docs.go` to generate the documentation for the new resource.

### Implementation

Expand All @@ -44,9 +44,9 @@ Now that the skeleton has been set up, you can start to actually implement the r

It is recommended that you look at a few existing resources as examples and also read through the comments on the source code for the [Table](https://github.com/cloudquery/cq-provider-sdk/blob/main/provider/schema/table.go) and [Column](https://github.com/cloudquery/cq-provider-sdk/blob/main/provider/schema/column.go) implementations for details.

For noncomplex fields, the SDK can directly resolve them into `Column`s for you, so all you need to do is specify the `Name` and the `Type`.
For simple fields, the SDK can directly resolve them into `Column`s for you, so all you need to do is specify the `Name` and the `Type`.

For complex fields or fields that require further API calls, you can defined your own `Resolver` for the `Column`.
For complex fields or fields that require further API calls, you can define your own `Resolver` for the `Column`.

#### Implementing Resolver Functions

Expand Down
1 change: 1 addition & 0 deletions tools/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package main

import (
_ "github.com/cloudquery/cq-gen"
_ "github.com/golang/mock/mockgen"
)

0 comments on commit 29ac7d3

Please sign in to comment.