mirror of https://github.com/hashicorp/consul
Added DC and domain args to Configure method
parent
b962fe38cd
commit
82ae7caf3e
|
@ -66,13 +66,13 @@ func (_m *MockProvider) Cleanup() error {
|
||||||
return r0
|
return r0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure provides a mock function with given fields: clusterId, isRoot, rawConfig
|
// Configure provides a mock function with given fields: clusterID, datacenterName, dnsDomain, isRoot, rawConfig
|
||||||
func (_m *MockProvider) Configure(clusterId string, isRoot bool, rawConfig map[string]interface{}) error {
|
func (_m *MockProvider) Configure(clusterId string, datacenterName string, dnsDomain string, isRoot bool, rawConfig map[string]interface{}) error {
|
||||||
ret := _m.Called(clusterId, isRoot, rawConfig)
|
ret := _m.Called(clusterId, datacenterName, dnsDomain, isRoot, rawConfig)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
if rf, ok := ret.Get(0).(func(string, bool, map[string]interface{}) error); ok {
|
if rf, ok := ret.Get(0).(func(string, string, string, bool, map[string]interface{}) error); ok {
|
||||||
r0 = rf(clusterId, isRoot, rawConfig)
|
r0 = rf(clusterId, datacenterName, dnsDomain, isRoot, rawConfig)
|
||||||
} else {
|
} else {
|
||||||
r0 = ret.Error(0)
|
r0 = ret.Error(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@ func TestProvider_Configure(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Basic configure
|
// Basic configure
|
||||||
m.On("Configure", "foo", false, map[string]interface{}{
|
m.On("Configure", "foo", "foo", "consul", false, map[string]interface{}{
|
||||||
"string": "bar",
|
"string": "bar",
|
||||||
"number": float64(42), // because json
|
"number": float64(42), // because json
|
||||||
}).Once().Return(nil)
|
}).Once().Return(nil)
|
||||||
require.NoError(p.Configure("foo", false, map[string]interface{}{
|
require.NoError(p.Configure("foo", "foo", "consul", false, map[string]interface{}{
|
||||||
"string": "bar",
|
"string": "bar",
|
||||||
"number": float64(42),
|
"number": float64(42),
|
||||||
}))
|
}))
|
||||||
|
@ -30,8 +30,8 @@ func TestProvider_Configure(t *testing.T) {
|
||||||
|
|
||||||
// Try with an error
|
// Try with an error
|
||||||
m.Mock = mock.Mock{}
|
m.Mock = mock.Mock{}
|
||||||
m.On("Configure", "foo", false, map[string]interface{}{}).Once().Return(errors.New("hello world"))
|
m.On("Configure", "foo", "foo", "consul", false, map[string]interface{}{}).Once().Return(errors.New("hello world"))
|
||||||
err := p.Configure("foo", false, map[string]interface{}{})
|
err := p.Configure("foo", "foo", "consul", false, map[string]interface{}{})
|
||||||
require.Error(err)
|
require.Error(err)
|
||||||
require.Contains(err.Error(), "hello")
|
require.Contains(err.Error(), "hello")
|
||||||
m.AssertExpectations(t)
|
m.AssertExpectations(t)
|
||||||
|
@ -42,7 +42,7 @@ func TestProvider_GenerateRoot(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("GenerateRoot").Once().Return(nil)
|
m.On("GenerateRoot").Once().Return(nil)
|
||||||
require.NoError(p.GenerateRoot())
|
require.NoError(p.GenerateRoot())
|
||||||
m.AssertExpectations(t)
|
m.AssertExpectations(t)
|
||||||
|
@ -61,7 +61,7 @@ func TestProvider_ActiveRoot(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("ActiveRoot").Once().Return("foo", nil)
|
m.On("ActiveRoot").Once().Return("foo", nil)
|
||||||
actual, err := p.ActiveRoot()
|
actual, err := p.ActiveRoot()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -82,7 +82,7 @@ func TestProvider_GenerateIntermediateCSR(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("GenerateIntermediateCSR").Once().Return("foo", nil)
|
m.On("GenerateIntermediateCSR").Once().Return("foo", nil)
|
||||||
actual, err := p.GenerateIntermediateCSR()
|
actual, err := p.GenerateIntermediateCSR()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -103,7 +103,7 @@ func TestProvider_SetIntermediate(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("SetIntermediate", "foo", "bar").Once().Return(nil)
|
m.On("SetIntermediate", "foo", "bar").Once().Return(nil)
|
||||||
err := p.SetIntermediate("foo", "bar")
|
err := p.SetIntermediate("foo", "bar")
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -123,7 +123,7 @@ func TestProvider_ActiveIntermediate(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("ActiveIntermediate").Once().Return("foo", nil)
|
m.On("ActiveIntermediate").Once().Return("foo", nil)
|
||||||
actual, err := p.ActiveIntermediate()
|
actual, err := p.ActiveIntermediate()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -144,7 +144,7 @@ func TestProvider_GenerateIntermediate(t *testing.T) {
|
||||||
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
testPlugin(t, func(t *testing.T, m *ca.MockProvider, p ca.Provider) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Try cleanup with no error
|
// Try with no error
|
||||||
m.On("GenerateIntermediate").Once().Return("foo", nil)
|
m.On("GenerateIntermediate").Once().Return("foo", nil)
|
||||||
actual, err := p.GenerateIntermediate()
|
actual, err := p.GenerateIntermediate()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -166,7 +166,7 @@ func TestProvider_Sign(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Create a CSR
|
// Create a CSR
|
||||||
csrPEM, _ := connect.TestCSR(t, connect.TestSpiffeIDService(t, "web"))
|
csrPEM, _ := connect.TestCSR(t, connect.TestSpiffeIDService(t, "web"), "node1.web.service.dc1.consul.")
|
||||||
block, _ := pem.Decode([]byte(csrPEM))
|
block, _ := pem.Decode([]byte(csrPEM))
|
||||||
csr, err := x509.ParseCertificateRequest(block.Bytes)
|
csr, err := x509.ParseCertificateRequest(block.Bytes)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -197,7 +197,7 @@ func TestProvider_SignIntermediate(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
// Create a CSR
|
// Create a CSR
|
||||||
csrPEM, _ := connect.TestCSR(t, connect.TestSpiffeIDService(t, "web"))
|
csrPEM, _ := connect.TestCSR(t, connect.TestSpiffeIDService(t, "web"), "node1.web.service.dc1.consul.")
|
||||||
block, _ := pem.Decode([]byte(csrPEM))
|
block, _ := pem.Decode([]byte(csrPEM))
|
||||||
csr, err := x509.ParseCertificateRequest(block.Bytes)
|
csr, err := x509.ParseCertificateRequest(block.Bytes)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,8 +30,10 @@ service CA {
|
||||||
|
|
||||||
message ConfigureRequest {
|
message ConfigureRequest {
|
||||||
string cluster_id = 1;
|
string cluster_id = 1;
|
||||||
bool is_root = 2;
|
string datacenter_name = 2;
|
||||||
bytes config = 3; // JSON-encoded structure
|
string dns_domain = 3;
|
||||||
|
bool is_root = 4;
|
||||||
|
bytes config = 5; // JSON-encoded structure
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetIntermediateRequest {
|
message SetIntermediateRequest {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (p *providerPluginGRPCServer) Configure(_ context.Context, req *ConfigureRe
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Empty{}, p.impl.Configure(req.ClusterId, req.IsRoot, rawConfig)
|
return &Empty{}, p.impl.Configure(req.ClusterId, req.DatacenterName, req.DnsDomain, req.IsRoot, rawConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *providerPluginGRPCServer) GenerateRoot(context.Context, *Empty) (*Empty, error) {
|
func (p *providerPluginGRPCServer) GenerateRoot(context.Context, *Empty) (*Empty, error) {
|
||||||
|
@ -95,6 +95,8 @@ type providerPluginGRPCClient struct {
|
||||||
|
|
||||||
func (p *providerPluginGRPCClient) Configure(
|
func (p *providerPluginGRPCClient) Configure(
|
||||||
clusterId string,
|
clusterId string,
|
||||||
|
datacenterName string,
|
||||||
|
dnsDomain string,
|
||||||
isRoot bool,
|
isRoot bool,
|
||||||
rawConfig map[string]interface{}) error {
|
rawConfig map[string]interface{}) error {
|
||||||
config, err := json.Marshal(rawConfig)
|
config, err := json.Marshal(rawConfig)
|
||||||
|
@ -103,9 +105,11 @@ func (p *providerPluginGRPCClient) Configure(
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = p.client.Configure(p.doneCtx, &ConfigureRequest{
|
_, err = p.client.Configure(p.doneCtx, &ConfigureRequest{
|
||||||
ClusterId: clusterId,
|
ClusterId: clusterId,
|
||||||
IsRoot: isRoot,
|
DatacenterName: datacenterName,
|
||||||
Config: config,
|
DnsDomain: dnsDomain,
|
||||||
|
IsRoot: isRoot,
|
||||||
|
Config: config,
|
||||||
})
|
})
|
||||||
return p.err(err)
|
return p.err(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ type providerPluginRPCServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *providerPluginRPCServer) Configure(args *ConfigureRPCRequest, _ *struct{}) error {
|
func (p *providerPluginRPCServer) Configure(args *ConfigureRPCRequest, _ *struct{}) error {
|
||||||
return p.impl.Configure(args.ClusterId, args.IsRoot, args.RawConfig)
|
return p.impl.Configure(args.ClusterId, args.DatacenterName, args.DNSDomain, args.IsRoot, args.RawConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *providerPluginRPCServer) GenerateRoot(struct{}, *struct{}) error {
|
func (p *providerPluginRPCServer) GenerateRoot(struct{}, *struct{}) error {
|
||||||
|
@ -95,12 +95,16 @@ type providerPluginRPCClient struct {
|
||||||
|
|
||||||
func (p *providerPluginRPCClient) Configure(
|
func (p *providerPluginRPCClient) Configure(
|
||||||
clusterId string,
|
clusterId string,
|
||||||
|
datacenterName string,
|
||||||
|
dnsDomain string,
|
||||||
isRoot bool,
|
isRoot bool,
|
||||||
rawConfig map[string]interface{}) error {
|
rawConfig map[string]interface{}) error {
|
||||||
return p.client.Call("Plugin.Configure", &ConfigureRPCRequest{
|
return p.client.Call("Plugin.Configure", &ConfigureRPCRequest{
|
||||||
ClusterId: clusterId,
|
ClusterId: clusterId,
|
||||||
IsRoot: isRoot,
|
DatacenterName: datacenterName,
|
||||||
RawConfig: rawConfig,
|
DNSDomain: dnsDomain,
|
||||||
|
IsRoot: isRoot,
|
||||||
|
RawConfig: rawConfig,
|
||||||
}, &struct{}{})
|
}, &struct{}{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,9 +178,11 @@ var _ ca.Provider = &providerPluginRPCClient{}
|
||||||
// Structs for net/rpc request and response
|
// Structs for net/rpc request and response
|
||||||
|
|
||||||
type ConfigureRPCRequest struct {
|
type ConfigureRPCRequest struct {
|
||||||
ClusterId string
|
ClusterId string
|
||||||
IsRoot bool
|
DatacenterName string
|
||||||
RawConfig map[string]interface{}
|
DNSDomain string
|
||||||
|
IsRoot bool
|
||||||
|
RawConfig map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetIntermediateRPCRequest struct {
|
type SetIntermediateRPCRequest struct {
|
||||||
|
|
|
@ -12,7 +12,8 @@ import (
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
// Configure initializes the provider based on the given cluster ID, root status
|
// Configure initializes the provider based on the given cluster ID, root status
|
||||||
// and configuration values.
|
// and configuration values.
|
||||||
Configure(clusterId string, isRoot bool, rawConfig map[string]interface{}) error
|
Configure(clusterId string, datacenterName string, dnsDomain string,
|
||||||
|
isRoot bool, rawConfig map[string]interface{}) error
|
||||||
|
|
||||||
// GenerateRoot causes the creation of a new root certificate for this provider.
|
// GenerateRoot causes the creation of a new root certificate for this provider.
|
||||||
// This can also be a no-op if a root certificate already exists for the given
|
// This can also be a no-op if a root certificate already exists for the given
|
||||||
|
|
Loading…
Reference in New Issue