Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>

Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>

Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>

Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>

Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>

Update docs/development.md

Co-authored-by: Letha <letha@mondoo.com>
  • Loading branch information
imilchev and misterpantz committed Feb 2, 2024
1 parent 55541fa commit 796d4bf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ use (

## Providers development best practices

The more time we spent building providers, the more learn about how to do that better in the future. Here we described learnings that would help you get started with providers development.
The more time we spend building providers, the more learn how to do better in the future. Here we describe learnings that will help you get started with providers development.

### Referencing MQL resources
Often we have a top-level MQL resource, which we want to reference in another top-level resource.
Expand All @@ -217,7 +217,7 @@ private gcp.project.computeService {
}
```

However, we have a reference to a GCP network in a GCP Compute Address. This allows us to quickly navigate to the network in which an address is created:
However, we have a reference to a GCP network in a GCP Compute address. This allows us to quickly navigate to the network in which an address is created:
```
private gcp.project.computeService.address {
// Static IP address
Expand All @@ -228,9 +228,9 @@ private gcp.project.computeService.address {
}
```

The simple wait to implement the reference would be to call the GCP API every time `gcp.project.computeService.address.network` is executed. However, this means we are going to be doing an excessive amount of API calls when scanning large GCP projects. If we have 10 addresses, this would mean we will do 10 separate API calls to get the network for each of them.
The simple way to implement the reference would be to call the GCP API every time `gcp.project.computeService.address.network` is executed. However, this would generate an excessive amount of API calls when scanning large GCP projects. If we have 10 addresses, this would mean 10 separate API calls to get the network, one for each of them.

MQL has powerful caching capabilities that would allow to achieve the same end result with a single (or fewer) API calls.
MQL has powerful caching capabilities that let us achieve the same end result with a single (or fewer) API calls.

First, create an init function for `gcp.project.computeService.network`, which is the resource we are cross-referencing:
```go
Expand Down Expand Up @@ -260,7 +260,7 @@ func initGcpProjectComputeServiceNetwork(runtime *plugin.Runtime, args map[strin

// Cast the resource to the appropriate type
computeSvc := obj.(*mqlGcpProjectComputeService)
// List the networks: equivalent to gcp.project.computeService.networks MQL query. This will retrieve all networks in the project and cache them in the MQL cache. Consecutive calls to this will retrieve the data from cache and will not execute any API calls.
// List the networks: equivalent to gcp.project.computeService.networks MQL query. This retrieves all networks in the project and caches them in the MQL cache. Consecutive calls to this retrieve the data from the cache and do not execute any API calls.
networks := computeSvc.GetNetworks()
if networks.Error != nil {
return nil, nil, networks.Error
Expand All @@ -287,7 +287,7 @@ func initGcpProjectComputeServiceNetwork(runtime *plugin.Runtime, args map[strin
}
```

Then, we implement the function for retrieving the network for a GCP compute address as follows:
Then, we implement the function for retrieving the network for a GCP compute address:
```go
func (g *mqlGcpProjectComputeServiceAddress) network() (*mqlGcpProjectComputeServiceNetwork, error) {
if g.NetworkUrl.Error != nil {
Expand Down

0 comments on commit 796d4bf

Please sign in to comment.