本文整理匯總了Golang中github.com/hashicorp/vault/helper/logformat.NewVaultLogger函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewVaultLogger函數的具體用法?Golang NewVaultLogger怎麽用?Golang NewVaultLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewVaultLogger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPostgreSQLBackend
func TestPostgreSQLBackend(t *testing.T) {
connURL := os.Getenv("PGURL")
if connURL == "" {
t.SkipNow()
}
table := os.Getenv("PGTABLE")
if table == "" {
table = "vault_kv_store"
}
// Run vault tests
logger := logformat.NewVaultLogger(log.LevelTrace)
b, err := NewBackend("postgresql", logger, map[string]string{
"connection_url": connURL,
"table": table,
})
if err != nil {
t.Fatalf("Failed to create new backend: %v", err)
}
defer func() {
pg := b.(*PostgreSQLBackend)
_, err := pg.client.Exec("TRUNCATE TABLE " + pg.table)
if err != nil {
t.Fatalf("Failed to drop table: %v", err)
}
}()
testBackend(t, b)
testBackend_ListPrefix(t, b)
}
示例2: mockRollback
// mockRollback returns a mock rollback manager
func mockRollback(t *testing.T) (*RollbackManager, *NoopBackend) {
backend := new(NoopBackend)
mounts := new(MountTable)
router := NewRouter()
mounts.Entries = []*MountEntry{
&MountEntry{
Path: "foo",
},
}
meUUID, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
if err := router.Mount(backend, "foo", &MountEntry{UUID: meUUID}, nil); err != nil {
t.Fatalf("err: %s", err)
}
mountsFunc := func() []*MountEntry {
return mounts.Entries
}
logger := logformat.NewVaultLogger(log.LevelTrace)
rb := NewRollbackManager(logger, mountsFunc, router)
rb.period = 10 * time.Millisecond
return rb, backend
}
示例3: TestInmem
func TestInmem(t *testing.T) {
logger := logformat.NewVaultLogger(log.LevelTrace)
inm := NewInmem(logger)
testBackend(t, inm)
testBackend_ListPrefix(t, inm)
}
示例4: TestAzureBackend
func TestAzureBackend(t *testing.T) {
if os.Getenv("AZURE_ACCOUNT_NAME") == "" ||
os.Getenv("AZURE_ACCOUNT_KEY") == "" {
t.SkipNow()
}
accountName := os.Getenv("AZURE_ACCOUNT_NAME")
accountKey := os.Getenv("AZURE_ACCOUNT_KEY")
ts := time.Now().UnixNano()
container := fmt.Sprintf("vault-test-%d", ts)
cleanupClient, _ := storage.NewBasicClient(accountName, accountKey)
logger := logformat.NewVaultLogger(log.LevelTrace)
backend, err := NewBackend("azure", logger, map[string]string{
"container": container,
"accountName": accountName,
"accountKey": accountKey,
})
defer func() {
cleanupClient.GetBlobService().DeleteContainerIfExists(container)
}()
if err != nil {
t.Fatalf("err: %s", err)
}
testBackend(t, backend)
testBackend_ListPrefix(t, backend)
}
示例5: TestCoreWithTokenStore
// TestCoreWithTokenStore returns an in-memory core that has a token store
// mounted, so that logical token functions can be used
func TestCoreWithTokenStore(t *testing.T) (*Core, *TokenStore, []byte, string) {
c, key, root := TestCoreUnsealed(t)
me := &MountEntry{
Table: credentialTableType,
Path: "token/",
Type: "token",
Description: "token based credentials",
}
meUUID, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
me.UUID = meUUID
view := NewBarrierView(c.barrier, credentialBarrierPrefix+me.UUID+"/")
tokenstore, _ := c.newCredentialBackend("token", c.mountEntrySysView(me), view, nil)
ts := tokenstore.(*TokenStore)
router := NewRouter()
router.Mount(ts, "auth/token/", &MountEntry{Table: credentialTableType, UUID: ""}, ts.view)
subview := c.systemBarrierView.SubView(expirationSubPath)
logger := logformat.NewVaultLogger(log.LevelTrace)
exp := NewExpirationManager(router, subview, ts, logger)
ts.SetExpirationManager(exp)
return c, ts, key, root
}
示例6: TestAuditBroker_LogRequest
func TestAuditBroker_LogRequest(t *testing.T) {
l := logformat.NewVaultLogger(log.LevelTrace)
b := NewAuditBroker(l)
a1 := &NoopAudit{}
a2 := &NoopAudit{}
b.Register("foo", a1, nil)
b.Register("bar", a2, nil)
auth := &logical.Auth{
ClientToken: "foo",
Policies: []string{"dev", "ops"},
Metadata: map[string]string{
"user": "armon",
"source": "github",
},
}
req := &logical.Request{
Operation: logical.ReadOperation,
Path: "sys/mounts",
}
// Create an identifier for the request to verify against
var err error
req.ID, err = uuid.GenerateUUID()
if err != nil {
t.Fatalf("failed to generate identifier for the request: path%s err: %v", req.Path, err)
}
reqErrs := errors.New("errs")
err = b.LogRequest(auth, req, reqErrs)
if err != nil {
t.Fatalf("err: %v", err)
}
for _, a := range []*NoopAudit{a1, a2} {
if !reflect.DeepEqual(a.ReqAuth[0], auth) {
t.Fatalf("Bad: %#v", a.ReqAuth[0])
}
if !reflect.DeepEqual(a.Req[0], req) {
t.Fatalf("Bad: %#v", a.Req[0])
}
if !reflect.DeepEqual(a.ReqErrs[0], reqErrs) {
t.Fatalf("Bad: %#v", a.ReqErrs[0])
}
}
// Should still work with one failing backend
a1.ReqErr = fmt.Errorf("failed")
if err := b.LogRequest(auth, req, nil); err != nil {
t.Fatalf("err: %v", err)
}
// Should FAIL work with both failing backends
a2.ReqErr = fmt.Errorf("failed")
if err := b.LogRequest(auth, req, nil); !errwrap.Contains(err, "no audit backend succeeded in logging the request") {
t.Fatalf("err: %v", err)
}
}
示例7: TestCache
func TestCache(t *testing.T) {
logger := logformat.NewVaultLogger(log.LevelTrace)
inm := NewInmem(logger)
cache := NewCache(inm, 0, logger)
testBackend(t, cache)
testBackend_ListPrefix(t, cache)
}
示例8: TestBackendConfig
func TestBackendConfig() *BackendConfig {
bc := &BackendConfig{
Logger: logformat.NewVaultLogger(log.LevelTrace),
System: TestSystemView(),
}
bc.Logger.SetLevel(log.LevelTrace)
return bc
}
示例9: TestConsulHABackend
func TestConsulHABackend(t *testing.T) {
var token string
addr := os.Getenv("CONSUL_HTTP_ADDR")
if addr == "" {
cid, connURL := prepareTestContainer(t)
if cid != "" {
defer cleanupTestContainer(t, cid)
}
addr = connURL
token = dockertest.ConsulACLMasterToken
}
conf := api.DefaultConfig()
conf.Address = addr
conf.Token = token
client, err := api.NewClient(conf)
if err != nil {
t.Fatalf("err: %v", err)
}
randPath := fmt.Sprintf("vault-%d/", time.Now().Unix())
defer func() {
client.KV().DeleteTree(randPath, nil)
}()
logger := logformat.NewVaultLogger(log.LevelTrace)
b, err := NewBackend("consul", logger, map[string]string{
"address": conf.Address,
"path": randPath,
"max_parallel": "-1",
"token": conf.Token,
})
if err != nil {
t.Fatalf("err: %s", err)
}
ha, ok := b.(HABackend)
if !ok {
t.Fatalf("consul does not implement HABackend")
}
testHABackend(t, ha, ha)
detect, ok := b.(RedirectDetect)
if !ok {
t.Fatalf("consul does not implement RedirectDetect")
}
host, err := detect.DetectHostAddr()
if err != nil {
t.Fatalf("err: %s", err)
}
if host == "" {
t.Fatalf("bad addr: %v", host)
}
}
示例10: TestEtcdBackend
func TestEtcdBackend(t *testing.T) {
addr := os.Getenv("ETCD_ADDR")
if addr == "" {
t.SkipNow()
}
cfg := client.Config{
Endpoints: []string{addr},
Transport: client.DefaultTransport,
}
c, err := client.New(cfg)
if err != nil {
t.Fatalf("err: %s", err)
}
ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
syncErr := c.Sync(ctx)
cancel()
if syncErr != nil {
t.Fatalf("err: %v", EtcdSyncClusterError)
}
kAPI := client.NewKeysAPI(c)
randPath := fmt.Sprintf("/vault-%d", time.Now().Unix())
defer func() {
delOpts := &client.DeleteOptions{
Recursive: true,
}
if _, err := kAPI.Delete(context.Background(), randPath, delOpts); err != nil {
t.Fatalf("err: %v", err)
}
}()
// Generate new etcd backend. The etcd address is read from ETCD_ADDR. No
// need to provide it explicitly.
logger := logformat.NewVaultLogger(log.LevelTrace)
b, err := NewBackend("etcd", logger, map[string]string{
"path": randPath,
})
if err != nil {
t.Fatalf("err: %s", err)
}
testBackend(t, b)
testBackend_ListPrefix(t, b)
ha, ok := b.(HABackend)
if !ok {
t.Fatalf("etcd does not implement HABackend")
}
testHABackend(t, ha, ha)
}
示例11: TestNewCore_badRedirectAddr
func TestNewCore_badRedirectAddr(t *testing.T) {
logger = logformat.NewVaultLogger(log.LevelTrace)
conf := &CoreConfig{
RedirectAddr: "127.0.0.1:8200",
Physical: physical.NewInmem(logger),
DisableMlock: true,
}
_, err := NewCore(conf)
if err == nil {
t.Fatal("should error")
}
}
示例12: TestDynamoDBHABackend
func TestDynamoDBHABackend(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
t.SkipNow()
}
creds, err := credentials.NewEnvCredentials().Get()
if err != nil {
t.Fatalf("err: %v", err)
}
// If the variable is empty or doesn't exist, the default
// AWS endpoints will be used
endpoint := os.Getenv("AWS_DYNAMODB_ENDPOINT")
region := os.Getenv("AWS_DEFAULT_REGION")
if region == "" {
region = "us-east-1"
}
conn := dynamodb.New(session.New(&aws.Config{
Credentials: credentials.NewEnvCredentials(),
Endpoint: aws.String(endpoint),
Region: aws.String(region),
}))
var randInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
table := fmt.Sprintf("vault-dynamodb-testacc-%d", randInt)
defer func() {
conn.DeleteTable(&dynamodb.DeleteTableInput{
TableName: aws.String(table),
})
}()
logger := logformat.NewVaultLogger(log.LevelTrace)
b, err := NewBackend("dynamodb", logger, map[string]string{
"access_key": creds.AccessKeyID,
"secret_key": creds.SecretAccessKey,
"session_token": creds.SessionToken,
"table": table,
})
if err != nil {
t.Fatalf("err: %s", err)
}
ha, ok := b.(HABackend)
if !ok {
t.Fatalf("dynamodb does not implement HABackend")
}
testHABackend(t, ha, ha)
}
示例13: testConsulBackendConfig
func testConsulBackendConfig(t *testing.T, conf *consulConf) *ConsulBackend {
logger := logformat.NewVaultLogger(log.LevelTrace)
be, err := newConsulBackend(*conf, logger)
if err != nil {
t.Fatalf("Expected Consul to initialize: %v", err)
}
c, ok := be.(*ConsulBackend)
if !ok {
t.Fatalf("Expected ConsulBackend")
}
return c
}
示例14: TestMySQLBackend
func TestMySQLBackend(t *testing.T) {
address := os.Getenv("MYSQL_ADDR")
if address == "" {
t.SkipNow()
}
database := os.Getenv("MYSQL_DB")
if database == "" {
database = "test"
}
table := os.Getenv("MYSQL_TABLE")
if table == "" {
table = "test"
}
username := os.Getenv("MYSQL_USERNAME")
password := os.Getenv("MYSQL_PASSWORD")
// Run vault tests
logger := logformat.NewVaultLogger(log.LevelTrace)
b, err := NewBackend("mysql", logger, map[string]string{
"address": address,
"database": database,
"table": table,
"username": username,
"password": password,
})
if err != nil {
t.Fatalf("Failed to create new backend: %v", err)
}
defer func() {
mysql := b.(*MySQLBackend)
_, err := mysql.client.Exec("DROP TABLE " + mysql.dbTable)
if err != nil {
t.Fatalf("Failed to drop table: %v", err)
}
}()
testBackend(t, b)
testBackend_ListPrefix(t, b)
}
示例15: testNewBackend
func testNewBackend(t *testing.T) {
logger := logformat.NewVaultLogger(log.LevelTrace)
_, err := NewBackend("foobar", logger, nil)
if err == nil {
t.Fatalf("expected error")
}
b, err := NewBackend("inmem", logger, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
if b == nil {
t.Fatalf("expected backend")
}
}