1 Star 0 Fork 0

杭州朝厚信息科技有限公司/smokescreen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"log"
"net/http"
"github.com/sirupsen/logrus"
"github.com/stripe/smokescreen/cmd"
"github.com/stripe/smokescreen/pkg/smokescreen"
)
// This default implementation of RoleFromRequest uses the CommonName of the
// client's certificate. If no certificate is provided, the AllowMissingRole
// configuration option will control whether the request is rejected, or the
// default ACL is applied.
func defaultRoleFromRequest(req *http.Request) (string, error) {
if req.TLS == nil {
return "", smokescreen.MissingRoleError("defaultRoleFromRequest requires TLS")
}
if len(req.TLS.PeerCertificates) == 0 {
return "", smokescreen.MissingRoleError("client did not provide certificate")
}
return req.TLS.PeerCertificates[0].Subject.CommonName, nil
}
func main() {
conf, err := cmd.NewConfiguration(nil, nil)
if err != nil {
logrus.Fatalf("Could not create configuration: %v", err)
} else if conf != nil {
conf.RoleFromRequest = defaultRoleFromRequest
conf.Log.Formatter = &logrus.JSONFormatter{}
adapter := &smokescreen.Log2LogrusWriter{
Entry: conf.Log.WithField("stdlog", "1"),
}
// Set the standard logger to use our logger's writer as output.
log.SetOutput(adapter)
log.SetFlags(0)
smokescreen.StartWithConfig(conf, nil)
}
// Otherwise, --help or --version was passed and handled by NewConfiguration, so do nothing
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chohotech/smokescreen.git
git@gitee.com:chohotech/smokescreen.git
chohotech
smokescreen
smokescreen
master

搜索帮助