-
Notifications
You must be signed in to change notification settings - Fork 2k
Generate an Access Monitoring event reference #61632
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Teleport | ||
| // Copyright (C) 2025 Gravitational, Inc. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
| "os" | ||
| "regexp" | ||
| "slices" | ||
| "strings" | ||
| "text/template" | ||
| "unicode" | ||
| "unicode/utf8" | ||
|
|
||
| "github.com/gravitational/teleport/gen/go/eventschema" | ||
| ) | ||
|
|
||
| // colNameList prints an example of columns from a given Access Monitoring event | ||
| // view to include an example command. It only prints up to the first three | ||
| // columns. | ||
| func colNameList(cols []*eventschema.ColumnSchemaDetails) string { | ||
| var sb strings.Builder | ||
| for i := range min(3, len(cols)) { | ||
| if i != 0 { | ||
| sb.WriteString(",") | ||
| } | ||
| sb.WriteString(cols[i].NameSQL()) | ||
| } | ||
| return sb.String() | ||
| } | ||
|
|
||
| var descPredicate = regexp.MustCompile(`^(is|are) `) | ||
|
|
||
| // prepareDescription returns a description of the column data provided in col. | ||
| func prepareDescription(col *eventschema.ColumnSchemaDetails) string { | ||
| // Remove the initial verb, since there is no subject in the sentence. | ||
| desc := descPredicate.ReplaceAllString(col.Description, "") | ||
|
|
||
| // Capitalize the first word in the description. | ||
| if r, size := utf8.DecodeRuneInString(desc); r != utf8.RuneError { | ||
| desc = string(unicode.ToUpper(r)) + desc[size:] | ||
| } | ||
|
|
||
| return desc | ||
| } | ||
|
|
||
| // docTempl is the template that represents an Access Monitoring event reference | ||
| // docs page. The assumption is that "@" characters are replaced with backticks | ||
| // before rendering the template. | ||
| // | ||
| //go:embed schema-reference.mdx.tmpl | ||
| var docTempl string | ||
|
|
||
| func main() { | ||
| data, err := eventschema.GetViewsDetails() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Cannot generate an Access Monitoring schema reference: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| slices.SortFunc(data, func(a, b *eventschema.TableSchemaDetails) int { | ||
| return strings.Compare(a.Name, b.Name) | ||
| }) | ||
|
|
||
| template.Must(template.New("event-reference").Funcs( | ||
| template.FuncMap{ | ||
| "ColNameList": colNameList, | ||
| "PrepareDescription": prepareDescription, | ||
| }, | ||
| ).Parse(docTempl)).Execute(os.Stdout, data) | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
build.assets/tooling/cmd/gen-athena-docs/schema-reference.mdx.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| {/*generated file. DO NOT EDIT.*/} | ||
| {/*To generate, run make access-monitoring-reference*/} | ||
| {/*vale messaging.capitalization = NO*/} | ||
| {/*vale messaging.consistent-terms = NO*/} | ||
|
|
||
| {{ range . -}} | ||
| ## {{ .Name }} | ||
|
|
||
| `{{ .Name }}` {{ .Description }}. | ||
|
|
||
| Example query: | ||
|
|
||
| ```code | ||
| $ tctl audit query exec \ | ||
| 'select {{ ColNameList .Columns }} from {{ .SQLViewName }} limit 1' | ||
| ``` | ||
|
|
||
| Columns: | ||
|
|
||
| |SQL Name|Type|Description| | ||
| |---|---|---| | ||
| {{- range .Columns }} | ||
| |{{ .NameSQL }}|{{ .Type }}|{{ PrepareDescription . }}| | ||
| {{- end }} | ||
|
|
||
| {{ end }} | ||
| {/*vale messaging.capitalization = YES*/} | ||
| {/*vale messaging.consistent-terms = YES*/} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.