Documentation ¶
Index ¶
- Variables
- func SupportedVaultArch(platform, arch string) bool
- func SupportedVaultEdition(ed string) bool
- func SupportedVaultPlatform(platform string) bool
- type Client
- type Opt
- type SearchAQLOpt
- func WithLimit(limit string) SearchAQLOpt
- func WithName(name string) SearchAQLOpt
- func WithPath(path string) SearchAQLOpt
- func WithProperties(props map[string]string) SearchAQLOpt
- func WithProperty(key, value string) SearchAQLOpt
- func WithQueryTemplate(temp *template.Template) SearchAQLOpt
- func WithRepo(repo string) SearchAQLOpt
- type SearchAQLRequest
- type SearchAQLResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var AQLQueryTemplate = template.Must(template.New("aql_query").Parse(`items.find({
{{ if .Repo -}}
"repo": { "$match": "{{ .Repo }}" }{{ if or .Path .Name .Properties -}},{{ end }}
{{ end -}}
{{ if .Path -}}
"path": { "$match": "{{ .Path }}" }{{ if or .Name .Properties -}},{{ end }}
{{ end -}}
{{ if .Name -}}
"name": { "$match": "{{ .Name }}" }{{ if .Properties -}},{{ end }}
{{ end -}}
{{ if .Properties -}}
{{ $first := true -}}
{{ range $k, $v := .Properties -}}
{{ if $first -}}
{{ $first = false -}}
{{ else -}},{{ end -}}
"@{{ $k }}": { "$match": "{{ $v }}" }
{{ end -}}
{{ end -}}
}) .include("*", "property.*") .sort({"$desc": ["modified"]}) {{ if .Limit -}}.limit({{ .Limit -}}){{ end -}}
`))
AQLQueryTemplate is our default query template. The syntax for AQL, combined a go template might make this hard to read, but most of what we're doing is dealing with trailing commas. The rendered query will look something like the following:
items.find({ "repo": { "$match": "hashicorp-packagespec-buildcache-local*" }, "path": { "$match": "cache-v1/vault-enterprise/*" }, "name": { "$match": "*.zip" }, "@EDITION": { "$match": "ent" }, "@GOARCH": { "$match": "amd64" }, "@GOOS": { "$match": "linux" }, "@artifactType": { "$match": "package" }, "@productRevision": { "$match": "f45845666b4e552bfc8ca775834a3ef6fc097fe0" }, "@productVersion": { "$match": "1.7.0" } }) .include("*", "property.*") .sort({"$desc": ["modified"]}) .limit(1)
Functions ¶
func SupportedVaultArch ¶
SupportedVaultArch validates that the given platform and arch are supported.
func SupportedVaultEdition ¶
SupportedVaultEdition validates that the given edition is a valid for Vault.
func SupportedVaultPlatform ¶
SupportedVaultPlatform validates that the given platform is supported.
Types ¶
type Client ¶
type Client struct { Host string Username string Token string // contains filtered or unexported fields }
func (*Client) SearchAQL ¶
func (c *Client) SearchAQL(ctx context.Context, req *SearchAQLRequest) (*SearchAQLResponse, error)
type Opt ¶
func WithUsername ¶
type SearchAQLOpt ¶
type SearchAQLOpt func(*SearchAQLRequest) *SearchAQLRequest
func WithLimit ¶
func WithLimit(limit string) SearchAQLOpt
func WithName ¶
func WithName(name string) SearchAQLOpt
func WithPath ¶
func WithPath(path string) SearchAQLOpt
func WithProperties ¶
func WithProperties(props map[string]string) SearchAQLOpt
func WithProperty ¶
func WithProperty(key, value string) SearchAQLOpt
func WithQueryTemplate ¶
func WithQueryTemplate(temp *template.Template) SearchAQLOpt
func WithRepo ¶
func WithRepo(repo string) SearchAQLOpt
type SearchAQLRequest ¶
type SearchAQLRequest struct { Repo string Path string Name string Properties map[string]string QueryTemplate *template.Template Limit string }
func NewSearchAQLRequest ¶
func NewSearchAQLRequest(opts ...SearchAQLOpt) *SearchAQLRequest
type SearchAQLResponse ¶
type SearchAQLResponse struct { Results []struct { Repo string `json:"repo"` Path string `json:"path"` Name string `json:"name"` Type string `json:"type"` Size json.Number `json:"size"` SHA256 string `json:"sha256"` Properties []struct { Key string `json:"key"` Value string `json:"value"` } `json:"properties"` } `json:"results"` }
Click to show internal directories.
Click to hide internal directories.