captainhook / secrets
用于检测秘密的实用类
0.9.5
2023-11-30 18:10 UTC
Requires
- php: >=8.0
- ext-mbstring: *
README
此包用于检测代码中的密码。主要用于防止您将它们提交到版本控制。
您可以使用 Regex\Supplier
下的类提供的正则表达式,或者使用包含的 Detector
类。您可以轻松创建自己的 Supplier
类,或者如果您认为对其他人有用,可以发起 pull-request。
以下是一些使用示例
使用 Suppliers
$result = Detector::create() ->useSuppliers( Aws::class, Google::class, GitHub::class )->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }
使用您自定义的正则表达式
$result = Detector::create() ->useRegex('#password = "\\S"#i') ->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }
Detector
还支持白名单
$result = Detector::create() ->useRegex('#password = "\\S"#i') ->allow('#root#') ->detectIn($myString) if ($result->wasSecretDetected()) { echo "secret detected: " . implode(' ', $result->matches()); }