MCPcopy Create free account
hub / github.com/PostHog/duckgres / parseSecretDDLHead

Function parseSecretDDLHead

server/usersecrets/classify.go:115–170  ·  view source on GitHub ↗

parseSecretDDLHead parses the statement head (through the optional secret name) and returns the classification plus the byte offset just past the head. The fast path for non-secret statements is two short case-folded keyword comparisons — no allocation — so this is safe on hot paths.

(query string)

Source from the content-addressed store, hash-verified

113// head. The fast path for non-secret statements is two short case-folded
114// keyword comparisons — no allocation — so this is safe on hot paths.
115func parseSecretDDLHead(query string) (Statement, int, bool) {
116 rest, ok := skipCommentsAndSpace(query)
117 if !ok {
118 return Statement{}, 0, false
119 }
120 toks := newTokenizer(rest)
121 headStart := len(query) - len(rest)
122
123 var st Statement
124 switch {
125 case toks.eatKeyword("CREATE"):
126 st.Kind = KindCreate
127 if toks.eatKeyword("OR") {
128 if !toks.eatKeyword("REPLACE") {
129 return Statement{}, 0, false
130 }
131 }
132 case toks.eatKeyword("DROP"):
133 st.Kind = KindDrop
134 default:
135 return Statement{}, 0, false
136 }
137
138 if toks.eatKeyword("PERSISTENT") {
139 st.Persistent = true
140 } else if toks.eatKeyword("TEMPORARY") || toks.eatKeyword("TEMP") {
141 st.Temporary = true
142 }
143
144 if !toks.eatKeyword("SECRET") {
145 return Statement{}, 0, false
146 }
147
148 if st.Kind == KindCreate {
149 if toks.eatKeyword("IF") {
150 if !toks.eatKeyword("NOT") || !toks.eatKeyword("EXISTS") {
151 return Statement{}, 0, false
152 }
153 st.IfNotExists = true
154 }
155 } else {
156 if toks.eatKeyword("IF") {
157 if !toks.eatKeyword("EXISTS") {
158 return Statement{}, 0, false
159 }
160 }
161 }
162
163 // Optional secret name. For CREATE the next token may instead be the
164 // opening paren of the option list (unnamed secret).
165 if name, ok := toks.eatIdentifier(); ok {
166 st.Name = strings.ToLower(name)
167 }
168
169 return st, headStart + toks.i, true
170}
171
172// skipCommentsAndSpace removes leading whitespace, line comments (--) and

Callers 4

ClassifyFunction · 0.85
RedactForLogFunction · 0.85
queryHasCreateSecretFunction · 0.85

Calls 4

skipCommentsAndSpaceFunction · 0.85
newTokenizerFunction · 0.85
eatKeywordMethod · 0.80
eatIdentifierMethod · 0.80

Tested by

no test coverage detected