当前位置: 首页>>代码示例>>Golang>>正文


Golang logical.RenewRequest函数代码示例

本文整理汇总了Golang中github.com/hashicorp/vault/logical.RenewRequest函数的典型用法代码示例。如果您正苦于以下问题:Golang RenewRequest函数的具体用法?Golang RenewRequest怎么用?Golang RenewRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了RenewRequest函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestBackendHandleRequest_renewExtend

func TestBackendHandleRequest_renewExtend(t *testing.T) {
	secret := &Secret{
		Type:            "foo",
		Renew:           LeaseExtend(0, 0),
		DefaultDuration: 5 * time.Minute,
	}
	b := &Backend{
		Secrets: []*Secret{secret},
	}

	req := logical.RenewRequest("/foo", secret.Response(nil, nil).Secret, nil)
	req.Secret.LeaseIssue = time.Now().UTC()
	req.Secret.LeaseIncrement = 1 * time.Hour
	resp, err := b.HandleRequest(req)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	if resp == nil || resp.Secret == nil {
		t.Fatal("should have secret")
	}

	if resp.Secret.Lease < 60*time.Minute || resp.Secret.Lease > 70*time.Minute {
		t.Fatalf("bad: %s", resp.Secret.Lease)
	}
}
开发者ID:beornf,项目名称:vault,代码行数:25,代码来源:backend_test.go

示例2: TestBackendHandleRequest_renewExtend

func TestBackendHandleRequest_renewExtend(t *testing.T) {
	sysView := logical.StaticSystemView{
		DefaultLeaseTTLVal: 5 * time.Minute,
		MaxLeaseTTLVal:     30 * time.Hour,
	}

	secret := &Secret{
		Type:            "foo",
		Renew:           LeaseExtend(0, 0, sysView),
		DefaultDuration: 5 * time.Minute,
	}
	b := &Backend{
		Secrets: []*Secret{secret},
	}

	req := logical.RenewRequest("/foo", secret.Response(nil, nil).Secret, nil)
	req.Secret.IssueTime = time.Now().UTC()
	req.Secret.Increment = 1 * time.Hour
	resp, err := b.HandleRequest(req)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	if resp == nil || resp.Secret == nil {
		t.Fatal("should have secret")
	}

	if resp.Secret.TTL < 59*time.Minute || resp.Secret.TTL > 61*time.Minute {
		t.Fatalf("bad: %s", resp.Secret.TTL)
	}
}
开发者ID:citywander,项目名称:vault,代码行数:30,代码来源:backend_test.go

示例3: renewEntry

// renewEntry is used to attempt renew of an internal entry
func (m *ExpirationManager) renewEntry(le *leaseEntry, increment time.Duration) (*logical.Response, error) {
	secret := *le.Secret
	secret.LeaseIssue = le.IssueTime
	secret.LeaseIncrement = increment
	secret.LeaseID = ""

	req := logical.RenewRequest(le.Path, &secret, le.Data)
	resp, err := m.router.Route(req)
	if err != nil {
		return nil, fmt.Errorf("failed to renew entry: %v", err)
	}
	return resp, nil
}
开发者ID:theonewolf,项目名称:vault,代码行数:14,代码来源:expiration.go

示例4: TestBackendHandleRequest_renew

func TestBackendHandleRequest_renew(t *testing.T) {
	var called uint32
	callback := func(*logical.Request, *FieldData) (*logical.Response, error) {
		atomic.AddUint32(&called, 1)
		return nil, nil
	}

	secret := &Secret{
		Type:  "foo",
		Renew: callback,
	}
	b := &Backend{
		Secrets: []*Secret{secret},
	}

	_, err := b.HandleRequest(logical.RenewRequest(
		"/foo", secret.Response(nil, nil).Secret, nil))
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	if v := atomic.LoadUint32(&called); v != 1 {
		t.Fatalf("bad: %#v", v)
	}
}
开发者ID:beornf,项目名称:vault,代码行数:24,代码来源:backend_test.go


注:本文中的github.com/hashicorp/vault/logical.RenewRequest函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。