| 1 |
package azure |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
|
| 6 |
"github.com/DefangLabs/secret-detector/pkg/detectors/helpers" |
| 7 |
"github.com/DefangLabs/secret-detector/pkg/secrets" |
| 8 |
) |
| 9 |
|
| 10 |
const ( |
| 11 |
Name = "azure" |
| 12 |
secretType = "Azure Storage Account access key" |
| 13 |
|
| 14 |
azureStorageKeyRegex = `(AccountKey=)?[a-zA-Z0-9+\/=]{88}` |
| 15 |
expectedMatchKey = "AccountKey" |
| 16 |
) |
| 17 |
|
| 18 |
func init() { |
| 19 |
secrets.GetDetectorFactory().Register(Name, NewDetector) |
| 20 |
} |
| 21 |
|
| 22 |
type detector struct { |
| 23 |
secrets.Detector |
| 24 |
} |
| 25 |
|
| 26 |
func NewDetector(config ...string) secrets.Detector { |
| 27 |
d := &detector{} |
| 28 |
d.Detector = helpers.NewRegexDetectorBuilder(secretType, azureStorageKeyRegex).WithVerifier(d.isStorageKey).Build() |
| 29 |
return d |
| 30 |
} |
| 31 |
|
| 32 |
func (d *detector) isStorageKey(key, value string) bool { |
| 33 |
|
| 34 |
return strings.HasPrefix(value, expectedMatchKey) || strings.HasSuffix(key, expectedMatchKey) |
| 35 |
} |