Skip to content

Commit 6820323

Browse files
committed
feat: new security center resources
1 parent d659ada commit 6820323

File tree

7 files changed

+411
-20
lines changed

7 files changed

+411
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
.token
1010
config.yaml
1111
cosign.key
12-
.idea
12+
.idea
13+
test-*.yaml

go.mod

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
7-
github.com/Azure/go-autorest/autorest v0.11.27
7+
github.com/Azure/go-autorest/autorest v0.11.28
88
github.com/aws/aws-sdk-go v1.42.51
99
github.com/aws/smithy-go v1.13.5
1010
github.com/fatih/color v1.13.0
@@ -33,23 +33,25 @@ require (
3333
github.com/gofrs/uuid v4.2.0+incompatible // indirect
3434
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
3535
github.com/golang/protobuf v1.5.2 // indirect
36+
github.com/google/go-cmp v0.5.9 // indirect
3637
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
37-
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
38-
github.com/hashicorp/go-uuid v1.0.2 // indirect
39-
github.com/hashicorp/go-version v1.3.0 // indirect
38+
github.com/hashicorp/go-hclog v1.2.1 // indirect
39+
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
40+
github.com/hashicorp/go-uuid v1.0.3 // indirect
41+
github.com/hashicorp/go-version v1.6.0 // indirect
4042
github.com/jmespath/go-jmespath v0.4.0 // indirect
41-
github.com/mattn/go-colorable v0.1.9 // indirect
43+
github.com/mattn/go-colorable v0.1.12 // indirect
4244
github.com/mattn/go-isatty v0.0.14 // indirect
4345
github.com/pkg/errors v0.9.1 // indirect
4446
github.com/pmezard/go-difflib v1.0.0 // indirect
4547
github.com/russross/blackfriday/v2 v2.0.1 // indirect
4648
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
4749
golang.org/x/crypto v0.6.0 // indirect
48-
golang.org/x/net v0.6.0 // indirect
49-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
50+
golang.org/x/net v0.7.0 // indirect
51+
golang.org/x/oauth2 v0.4.0 // indirect
5052
golang.org/x/sys v0.6.0 // indirect
5153
google.golang.org/appengine v1.6.7 // indirect
52-
google.golang.org/protobuf v1.26.0 // indirect
54+
google.golang.org/protobuf v1.28.1 // indirect
5355
gopkg.in/yaml.v3 v3.0.1 // indirect
5456
)
5557

go.sum

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9mo
3636
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
3737
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
3838
github.com/Azure/go-autorest/autorest v0.11.24/go.mod h1:G6kyRlFnTuSbEYkQGawPfsCswgme4iYf6rfSKUDzbCc=
39-
github.com/Azure/go-autorest/autorest v0.11.27 h1:F3R3q42aWytozkV8ihzcgMO4OA4cuqr3bNlsEuF6//A=
40-
github.com/Azure/go-autorest/autorest v0.11.27/go.mod h1:7l8ybrIdUmGqZMTD0sRtAr8NvbHjfofbf8RSP2q7w7U=
39+
github.com/Azure/go-autorest/autorest v0.11.28 h1:ndAExarwr5Y+GaHE6VCaY1kyS/HwwGGyuimVhWsHOEM=
40+
github.com/Azure/go-autorest/autorest v0.11.28/go.mod h1:MrkzG3Y3AH668QyF9KRk5neJnGgmhQ6krbhR8Q5eMvA=
4141
github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ=
4242
github.com/Azure/go-autorest/autorest/adal v0.9.23 h1:Yepx8CvFxwNKpH6ja7RZ+sKX+DWYNldbLiALMC3BTz8=
4343
github.com/Azure/go-autorest/autorest/adal v0.9.23/go.mod h1:5pcMqFkdPhviJdlEy3kC/v1ZLnQl0MH6XA5YCcMhy4c=
@@ -126,8 +126,9 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
126126
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
127127
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
128128
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
129-
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
130129
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
130+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
131+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
131132
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
132133
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
133134
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -143,14 +144,18 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
143144
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
144145
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
145146
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
146-
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
147147
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
148-
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
148+
github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw=
149+
github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
149150
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
150-
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
151+
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
152+
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
151153
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
152-
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
154+
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
155+
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
153156
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
157+
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
158+
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
154159
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
155160
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
156161
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -168,8 +173,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
168173
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
169174
github.com/manicminer/hamilton-autorest v0.2.0 h1:dDL+t2DrQza0EfNYINYCvXISeNwVqzgVAQh+CH/19ZU=
170175
github.com/manicminer/hamilton-autorest v0.2.0/go.mod h1:NselDpNTImEmOc/fa41kPg6YhDt/6S95ejWbTGZ6tlg=
171-
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
172176
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
177+
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
178+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
173179
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
174180
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
175181
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
@@ -198,6 +204,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
198204
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
199205
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
200206
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
207+
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
201208
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
202209
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
203210
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@@ -219,6 +226,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
219226
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
220227
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
221228
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
229+
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
222230
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
223231
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
224232
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -282,15 +290,17 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
282290
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
283291
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
284292
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
285-
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
286293
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
294+
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
295+
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
287296
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
288297
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
289298
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
290299
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
291300
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
292-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI=
293301
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
302+
golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
303+
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
294304
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
295305
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
296306
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -332,6 +342,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
332342
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
333343
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
334344
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
345+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
346+
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
335347
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
336348
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
337349
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -472,8 +484,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
472484
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
473485
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
474486
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
475-
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
476487
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
488+
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
489+
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
477490
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
478491
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
479492
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

resources/security-alert.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/aws/smithy-go/ptr"
7+
"github.com/ekristen/azure-nuke/pkg/resource"
8+
"github.com/ekristen/azure-nuke/pkg/types"
9+
"github.com/sirupsen/logrus"
10+
"regexp"
11+
"time"
12+
13+
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
14+
)
15+
16+
type SecurityAlert struct {
17+
client security.AlertsClient
18+
id string
19+
name string
20+
displayName string
21+
location string
22+
status string
23+
}
24+
25+
var SecurityAlertLocation = "/Microsoft.Security/locations/(?P<location>.*)/alerts/"
26+
27+
func init() {
28+
resource.RegisterV2(resource.Registration{
29+
Name: "SecurityAlert",
30+
Scope: resource.Subscription,
31+
Lister: ListSecurityAlert,
32+
})
33+
}
34+
35+
func ListSecurityAlert(opts resource.ListerOpts) ([]resource.Resource, error) {
36+
log := logrus.
37+
WithField("resource", "SecurityAlert").
38+
WithField("scope", resource.Subscription).
39+
WithField("subscription", opts.SubscriptionId)
40+
41+
log.Trace("creating client")
42+
43+
locationRe := regexp.MustCompile(SecurityAlertLocation)
44+
45+
client := security.NewAlertsClient(opts.SubscriptionId)
46+
client.Authorizer = opts.Authorizers.Management
47+
client.RetryAttempts = 1
48+
client.RetryDuration = time.Second * 2
49+
50+
resources := make([]resource.Resource, 0)
51+
52+
log.Trace("listing resources")
53+
54+
ctx := context.TODO()
55+
list, err := client.List(ctx)
56+
if err != nil {
57+
return nil, err
58+
}
59+
60+
for list.NotDone() {
61+
log.Trace("listing not done")
62+
for _, g := range list.Values() {
63+
64+
matches := locationRe.FindStringSubmatch(ptr.ToString(g.ID))
65+
resources = append(resources, &SecurityAlert{
66+
client: client,
67+
id: *g.ID,
68+
name: *g.Name,
69+
displayName: ptr.ToString(g.AlertDisplayName),
70+
location: matches[1],
71+
status: string(g.AlertProperties.Status),
72+
})
73+
}
74+
75+
if err := list.NextWithContext(ctx); err != nil {
76+
return nil, err
77+
}
78+
}
79+
80+
return resources, nil
81+
}
82+
83+
func (r *SecurityAlert) Filter() error {
84+
if r.status == "Dismissed" {
85+
return fmt.Errorf("alert already dismissed")
86+
}
87+
88+
return nil
89+
}
90+
91+
func (r *SecurityAlert) Remove() error {
92+
// Note: we cannot actually remove alerts :(
93+
// So we just have to dismiss them instead
94+
_, err := r.client.UpdateSubscriptionLevelStateToDismiss(context.TODO(), r.location, r.name)
95+
return err
96+
}
97+
98+
func (r *SecurityAlert) Properties() types.Properties {
99+
properties := types.NewProperties()
100+
101+
properties.Set("Name", r.name)
102+
properties.Set("DisplayName", r.displayName)
103+
properties.Set("Location", r.location)
104+
properties.Set("Status", r.status)
105+
106+
return properties
107+
}
108+
109+
func (r *SecurityAlert) String() string {
110+
return r.name
111+
}

resources/security-assessment.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/ekristen/azure-nuke/pkg/resource"
7+
"github.com/ekristen/azure-nuke/pkg/types"
8+
"github.com/sirupsen/logrus"
9+
"time"
10+
11+
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
12+
)
13+
14+
type SecurityAssessment struct {
15+
client security.AssessmentsClient
16+
id string
17+
name string
18+
}
19+
20+
func init() {
21+
resource.RegisterV2(resource.Registration{
22+
Name: "SecurityAssessment",
23+
Scope: resource.Subscription,
24+
Lister: ListSecurityAssessment,
25+
})
26+
}
27+
28+
func ListSecurityAssessment(opts resource.ListerOpts) ([]resource.Resource, error) {
29+
log := logrus.
30+
WithField("resource", "SecurityAssessment").
31+
WithField("scope", resource.Subscription).
32+
WithField("subscription", opts.SubscriptionId)
33+
34+
log.Trace("creating client")
35+
36+
client := security.NewAssessmentsClient(opts.SubscriptionId)
37+
client.Authorizer = opts.Authorizers.Management
38+
client.RetryAttempts = 1
39+
client.RetryDuration = time.Second * 2
40+
41+
resources := make([]resource.Resource, 0)
42+
43+
log.Trace("listing resources")
44+
45+
ctx := context.TODO()
46+
list, err := client.List(ctx, fmt.Sprintf("/subscriptions/%s", opts.SubscriptionId))
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
for list.NotDone() {
52+
log.Trace("listing not done")
53+
for _, g := range list.Values() {
54+
resources = append(resources, &SecurityAssessment{
55+
client: client,
56+
id: *g.ID,
57+
name: *g.Name,
58+
})
59+
}
60+
61+
if err := list.NextWithContext(ctx); err != nil {
62+
return nil, err
63+
}
64+
}
65+
66+
return resources, nil
67+
}
68+
69+
func (r *SecurityAssessment) Remove() error {
70+
_, err := r.client.Delete(context.TODO(), r.id, r.name)
71+
return err
72+
}
73+
74+
func (r *SecurityAssessment) Properties() types.Properties {
75+
properties := types.NewProperties()
76+
77+
properties.Set("ID", r.id)
78+
properties.Set("Name", r.name)
79+
80+
return properties
81+
}
82+
83+
func (r *SecurityAssessment) String() string {
84+
return r.name
85+
}

0 commit comments

Comments
 (0)