Go template for atlas accessLists list

Hi,
I’m trying to do something simple. List the allowed IP addresses/CIDR with the comment as a simple table.
However, the documentation on the go template integration is … not there.
I looked at the output from

atlas accessLists list -o json

which lead me to guess that I need to list the results array.
So I tried this:

atlas accessLists list -o go-template="{{range .results}} {{.ipAddress}} {{end}}"

The error is
Error: template: output:1:8: executing "output" at <.results>: can't evaluate field results in type *admin.PaginatedNetworkAccess

So, I thought I’d try the simplest thing:
atlas accessLists list -o go-template='{{.totalCount}}'

Error: template: output:1:2: executing "output" at <.totalCount>: can't evaluate field totalCount in type *admin.PaginatedNetworkAccess

I wonder, what’s the root object?

$ atlas accessLists list -o go-template='{{.}}'
{0xc000b082b8 0xc000b082d0 0xc000456e20}

So how do I iterate the results list?

Well, by Googling I found the source code for the formatting modules.

@MongoDB:
Guys, if you are going to advertise Golang formatting in the API, you really need to document somewhere where the models can be found and an example or two. I should not need to output in JSON and guess, or have to go grovelling around a git repo of source.

It turns out that:

  • The field names are capitalised in the Golang type. Who knew? They aren’t in the JSON output.
  • The output is an instance of PaginatedNetworkAccess
  • The Results array in that is an array of NetworkPermissionEntry.

For future Googlers, the links to these are here: https://pkg.go.dev/go.mongodb.org/atlas-sdk/v20231115007/admin#PaginatedNetworkAccess and here: https://pkg.go.dev/go.mongodb.org/atlas-sdk/v20231115007/admin#NetworkPermissionEntry

And here is the missing example:

`atlas accessLists list -o go-template="{{range .Results}}{{.Comment}},{{.IpAddress}},{{.CidrBlock}}
{{end}}"

Note the embedded newline to get the output to appear on separate lines.

It is not possible to use printf “%s” as these values are *strings not strings, so you just get pointer values (“pointers”??? what is this, C?!)

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.