File: internal.go

package info (click to toggle)
vagrant 2.3.7%2Bgit20230731.5fc64cde%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,616 kB
  • sloc: ruby: 111,820; sh: 462; makefile: 123; ansic: 34; lisp: 1
file content (71 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package plugin

import (
	"github.com/hashicorp/go-argmapper"
	"github.com/hashicorp/go-hclog"
	"github.com/hashicorp/go-plugin"
	"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cacher"
	"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cleanup"
)

// Returns value that implements Internal interface
// used by mappers. This allows us to generate clients
// for the managers in a common way.
func NewInternal(
	broker *plugin.GRPCBroker,
	cache cacher.Cache,
	cleanup cleanup.Cleanup,
	logger hclog.Logger,
	mappers []*argmapper.Func,
) *internal {
	return &internal{
		broker:  broker,
		cache:   cache,
		cleanup: cleanup,
		logger:  logger,
		mappers: mappers,
	}
}

func Internal(l hclog.Logger, m []*argmapper.Func) *internal {
	return &internal{
		broker:  nil,
		cache:   cacher.New(),
		cleanup: cleanup.New(),
		logger:  l,
		mappers: m,
	}
}

type internal struct {
	broker  *plugin.GRPCBroker
	cache   cacher.Cache
	cleanup cleanup.Cleanup
	logger  hclog.Logger
	mappers []*argmapper.Func
}

// Broker implements Internal
func (i *internal) Broker() *plugin.GRPCBroker {
	return i.broker
}

// Cache implements Internal
func (i *internal) Cache() cacher.Cache {
	return i.cache
}

// Cleanup implements Internal
func (i *internal) Cleanup() cleanup.Cleanup {
	return i.cleanup
}

// Logger implements Internal
func (i *internal) Logger() hclog.Logger {
	return i.logger
}

// Mappers implements Internal
func (i *internal) Mappers() []*argmapper.Func {
	return i.mappers
}