Skip to content

Commit 069c8c3

Browse files
authored
Support attributes without quotes (#20)
* Support alternative assignment syntax * Add tests * Update regex
1 parent 8550034 commit 069c8c3

File tree

4 files changed

+53
-57
lines changed

4 files changed

+53
-57
lines changed

README.md

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
<!--
2-
3-
4-
5-
6-
7-
8-
1+
# tfmask [![Build Status](https://travis-ci.org/cloudposse/tfmask.svg?branch=master)](https://travis-ci.org/cloudposse/tfmask) [![Latest Release](https://img.shields.io/github/release/cloudposse/tfmask.svg)](https://github.com/cloudposse/tfmask/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
92

3+
[![README Header][readme_header_img]][readme_header_link]
104

5+
[![Cloud Posse][logo]](https://cpco.io/homepage)
116

7+
<!--
128
139
1410
1511
1612
** DO NOT EDIT THIS FILE
17-
**
18-
** This file was automatically generated by the `build-harness`.
19-
** 1) Make all changes to `README.yaml`
13+
**
14+
** This file was automatically generated by the `build-harness`.
15+
** 1) Make all changes to `README.yaml`
2016
** 2) Run `make init` (you only need to do this once)
21-
** 3) Run`make readme` to rebuild this file.
17+
** 3) Run`make readme` to rebuild this file.
2218
**
2319
** (We maintain HUNDREDS of open source projects. This is how we maintain our sanity.)
2420
**
@@ -27,30 +23,14 @@
2723
2824
2925
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
-->
41-
[![README Header][readme_header_img]][readme_header_link]
42-
43-
[![Cloud Posse][logo]](https://cpco.io/homepage)
44-
45-
# tfmask [![Build Status](https://travis-ci.org/cloudposse/tfmask.svg?branch=master)](https://travis-ci.org/cloudposse/tfmask) [![Latest Release](https://img.shields.io/github/release/cloudposse/tfmask.svg)](https://github.com/cloudposse/tfmask/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
46-
26+
-->
4727

4828
Command line utility to mask sensitive output from a `transform plan` or `terraform apply`.
4929

5030

5131
---
5232

53-
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
33+
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
5434
[<img align="right" title="Share via Email" src="https://docs.cloudposse.com/images/ionicons/ios-email-outline-2.0.1-16x16-999999.svg"/>][share_email]
5535
[<img align="right" title="Share on Google+" src="https://docs.cloudposse.com/images/ionicons/social-googleplus-outline-2.0.1-16x16-999999.svg" />][share_googleplus]
5636
[<img align="right" title="Share on Facebook" src="https://docs.cloudposse.com/images/ionicons/social-facebook-outline-2.0.1-16x16-999999.svg" />][share_facebook]
@@ -126,7 +106,7 @@ Example `.envrc`:
126106
```sh
127107
# Export terraform environment
128108
export TFMASK_CHAR="#"
129-
export TFMASK_VALUES_REGEX="(?i)^.*(oauth|secret|token|password|key|result).*$"
109+
export TFMASK_VALUES_REGEX="(?i)^.*[^a-zA-Z](oauth|secret|token|password|key|result|id).*$"
130110
```
131111

132112
<details>
@@ -243,9 +223,9 @@ terraform apply -no-color | tfmask
243223

244224

245225

246-
## Share the Love
226+
## Share the Love
247227

248-
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/tfmask)! (it helps us **a lot**)
228+
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/tfmask)! (it helps us **a lot**)
249229

250230
Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
251231

@@ -264,7 +244,7 @@ Check out these related projects.
264244

265245
## Help
266246

267-
**Got a question?** We got answers.
247+
**Got a question?** We got answers.
268248

269249
File a GitHub [issue](https://github.com/cloudposse/tfmask/issues), send us an [email][email] or join our [Slack Community][slack].
270250

@@ -273,7 +253,7 @@ File a GitHub [issue](https://github.com/cloudposse/tfmask/issues), send us an [
273253
## DevOps Accelerator for Startups
274254

275255

276-
We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
256+
We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
277257

278258
[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
279259

@@ -302,11 +282,11 @@ Participate in our [Discourse Forums][discourse]. Here you'll find answers to co
302282

303283
## Newsletter
304284

305-
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
285+
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
306286

307287
## Office Hours
308288

309-
[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
289+
[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
310290

311291
[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]
312292

@@ -337,9 +317,9 @@ Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright)
337317

338318

339319

340-
## License
320+
## License
341321

342-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
322+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
343323

344324
See [LICENSE](LICENSE) for full details.
345325

@@ -380,7 +360,7 @@ This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? P
380360

381361
We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source].
382362

383-
We offer [paid support][commercial_support] on all of our projects.
363+
We offer [paid support][commercial_support] on all of our projects.
384364

385365
Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.
386366

README.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ usage: |-
8383
```sh
8484
# Export terraform environment
8585
export TFMASK_CHAR="#"
86-
export TFMASK_VALUES_REGEX="(?i)^.*(oauth|secret|token|password|key|result).*$"
86+
export TFMASK_VALUES_REGEX="(?i)^.*[^a-zA-Z](oauth|secret|token|password|key|result|id).*$"
8787
```
8888
8989
<details>

main.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ type match struct {
2525
}
2626

2727
type keyValueMatch struct {
28-
leadingWhitespace string
29-
property string
30-
trailingWhitespaceBefore string
31-
trailingWhitespaceAfter string
32-
oldValue string
28+
leadingWhitespace string
29+
property string
30+
assignmentOperator string
31+
trailingWhitespaceAfter string
32+
oldValue string
3333
}
3434

3535
type expression struct {
@@ -68,7 +68,7 @@ var versionedExpressions = map[string]expression{
6868
"^([~/+-]+) (.*?) +(.*)$",
6969
),
7070
reMapKeyPair: regexp.MustCompile(
71-
"(?i)^(\\s+(?:[~+-] )?)\"(.*)\"(\\s+)=(\\s+)\"(.*)\"$",
71+
"(?i)^(\\s+(?:[~+-] )?)(.*)(\\s?[=:])(\\s+)\"(.*)\"$",
7272
),
7373
resourceIndex: 2,
7474
assign: ":",
@@ -85,7 +85,7 @@ var versionedExpressions = map[string]expression{
8585
"^([~/+-]+) (.*?) +(.*) (.*) (.*)$",
8686
),
8787
reMapKeyPair: regexp.MustCompile(
88-
"(?i)^(\\s+(?:[~+-] )?)\"(.*)\"(\\s+)=(\\s+)\"(.*)\"$",
88+
"(?i)^(\\s+(?:[~+-] )?)(.*)(\\s=)(\\s+)\"(.*)\"$",
8989
),
9090
resourceIndex: 3,
9191
assign: "=",
@@ -100,7 +100,7 @@ func main() {
100100
var tfmaskChar = getEnv("TFMASK_CHAR", "*")
101101
// Pattern representing sensitive output
102102
var tfmaskValuesRegex = getEnv("TFMASK_VALUES_REGEX",
103-
"(?i)^.*(oauth|secret|token|password|key|result|id).*$")
103+
"(?i)^.*[^a-zA-Z](oauth|secret|token|password|key|result|id).*$")
104104
// Pattern representing sensitive resource
105105
var tfmaskResourceRegex = getEnv("TFMASK_RESOURCES_REGEX",
106106
"(?i)^(random_id|random_string).*$")
@@ -192,11 +192,11 @@ func matchFromLine(reTfPlanLine *regexp.Regexp, line string) match {
192192
func matchFromAssignment(reMapKeyPair *regexp.Regexp, line string) keyValueMatch {
193193
subMatch := reMapKeyPair.FindStringSubmatch(line)
194194
return keyValueMatch{
195-
leadingWhitespace: subMatch[1],
196-
property: subMatch[2],
197-
trailingWhitespaceBefore: subMatch[3],
198-
trailingWhitespaceAfter: subMatch[4],
199-
oldValue: subMatch[5],
195+
leadingWhitespace: subMatch[1],
196+
property: subMatch[2],
197+
assignmentOperator: subMatch[3],
198+
trailingWhitespaceAfter: subMatch[4],
199+
oldValue: subMatch[5],
200200
}
201201
}
202202

@@ -222,10 +222,10 @@ func assignmentLine(reMapKeyPair, reTfValues *regexp.Regexp, tfmaskChar, line st
222222
match := matchFromAssignment(reMapKeyPair, line)
223223
if reTfValues.MatchString(match.property) {
224224
maskedValue := maskValue(match.oldValue, tfmaskChar)
225-
line = fmt.Sprintf("%v\"%v\"%v=%v\"%v\"",
225+
line = fmt.Sprintf("%v%v%v%v\"%v\"",
226226
match.leadingWhitespace,
227227
match.property,
228-
match.trailingWhitespaceBefore,
228+
match.assignmentOperator,
229229
match.trailingWhitespaceAfter,
230230
maskedValue)
231231
}

main_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,28 @@ var assignmentTests = []struct {
173173
expectedResult string
174174
minorVersion string
175175
}{
176+
// tf 0.11 ------------------------------------
177+
{
178+
" + client_secret: \"123456\"",
179+
" + client_secret: \"******\"",
180+
"0.11",
181+
},
182+
{
183+
" + client_secret = \"123456\"",
184+
" + client_secret = \"******\"",
185+
"0.11",
186+
},
176187
// tf 0.12 ------------------------------------
177188
{
178189
" + \"foo_secret\" = \"123456\"",
179190
" + \"foo_secret\" = \"******\"",
180191
"0.12",
181192
},
193+
{
194+
" + foo_secret = \"123456\"",
195+
" + foo_secret = \"******\"",
196+
"0.12",
197+
},
182198
{
183199
" - \"foo_secret\" = \"123456\"",
184200
" - \"foo_secret\" = \"******\"",
@@ -205,7 +221,7 @@ func TestAssignmentLine(t *testing.T) {
205221
// Character used to mask sensitive output
206222
var tfmaskChar = "*"
207223
// Pattern representing sensitive output
208-
var tfmaskValuesRegex = "(?i)^.*(oauth|secret|token|password|key|result|id).*$"
224+
var tfmaskValuesRegex = "(?i)^.*[^a-zA-Z](oauth|secret|token|password|key|result|id).*$"
209225
reTfValues := regexp.MustCompile(tfmaskValuesRegex)
210226

211227
for _, assignmentTest := range assignmentTests {

0 commit comments

Comments
 (0)