Added DC and domain args to Configure method

This commit is contained in:
tradel 2019-08-27 14:09:01 -07:00
parent 1b3d066f90
commit 3dc47a9251
7 changed files with 356 additions and 156 deletions

View File

@ -66,13 +66,13 @@ func (_m *MockProvider) Cleanup() error {
return r0
}
// Configure provides a mock function with given fields: clusterId, isRoot, rawConfig
func (_m *MockProvider) Configure(clusterId string, isRoot bool, rawConfig map[string]interface{}) error {
ret := _m.Called(clusterId, isRoot, rawConfig)
// Configure provides a mock function with given fields: clusterID, datacenterName, dnsDomain, isRoot, rawConfig
func (_m *MockProvider) Configure(clusterId string, datacenterName string, dnsDomain string, isRoot bool, rawConfig map[string]interface{}) error {
ret := _m.Called(clusterId, datacenterName, dnsDomain, isRoot, rawConfig)
var r0 error
if rf, ok := ret.Get(0).(func(string, bool, map[string]interface{}) error); ok {
r0 = rf(clusterId, isRoot, rawConfig)
if rf, ok := ret.Get(0).(func(string, string, string, bool, map[string]interface{}) error); ok {
r0 = rf(clusterId, datacenterName, dnsDomain, isRoot, rawConfig)
} else {
r0 = ret.Error(0)
}

View File

@ -18,11 +18,11 @@ func TestProvider_Configure(t *testing.T) {
require := require.New(t)
// Basic configure
m.On("Configure", "foo", false, map[string]interface{}{
m.On("Configure", "foo", "foo", "consul", false, map[string]interface{}{
"string": "bar",
"number": float64(42), // because json
}).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",
"number": float64(42),
}))
@ -30,8 +30,8 @@ func TestProvider_Configure(t *testing.T) {
// Try with an error
m.Mock = mock.Mock{}
m.On("Configure", "foo", false, map[string]interface{}{}).Once().Return(errors.New("hello world"))
err := p.Configure("foo", false, map[string]interface{}{})
m.On("Configure", "foo", "foo", "consul", false, map[string]interface{}{}).Once().Return(errors.New("hello world"))
err := p.Configure("foo", "foo", "consul", false, map[string]interface{}{})
require.Error(err)
require.Contains(err.Error(), "hello")
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("GenerateRoot").Once().Return(nil)
require.NoError(p.GenerateRoot())
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("ActiveRoot").Once().Return("foo", nil)
actual, err := p.ActiveRoot()
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("GenerateIntermediateCSR").Once().Return("foo", nil)
actual, err := p.GenerateIntermediateCSR()
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("SetIntermediate", "foo", "bar").Once().Return(nil)
err := p.SetIntermediate("foo", "bar")
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("ActiveIntermediate").Once().Return("foo", nil)
actual, err := p.ActiveIntermediate()
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) {
require := require.New(t)
// Try cleanup with no error
// Try with no error
m.On("GenerateIntermediate").Once().Return("foo", nil)
actual, err := p.GenerateIntermediate()
require.NoError(err)
@ -166,7 +166,7 @@ func TestProvider_Sign(t *testing.T) {
require := require.New(t)
// 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))
csr, err := x509.ParseCertificateRequest(block.Bytes)
require.NoError(err)
@ -197,7 +197,7 @@ func TestProvider_SignIntermediate(t *testing.T) {
require := require.New(t)
// 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))
csr, err := x509.ParseCertificateRequest(block.Bytes)
require.NoError(err)

File diff suppressed because it is too large Load Diff

View File

@ -30,8 +30,10 @@ service CA {
message ConfigureRequest {
string cluster_id = 1;
bool is_root = 2;
bytes config = 3; // JSON-encoded structure
string datacenter_name = 2;
string dns_domain = 3;
bool is_root = 4;
bytes config = 5; // JSON-encoded structure
}
message SetIntermediateRequest {

View File

@ -20,7 +20,7 @@ func (p *providerPluginGRPCServer) Configure(_ context.Context, req *ConfigureRe
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) {
@ -95,6 +95,8 @@ type providerPluginGRPCClient struct {
func (p *providerPluginGRPCClient) Configure(
clusterId string,
datacenterName string,
dnsDomain string,
isRoot bool,
rawConfig map[string]interface{}) error {
config, err := json.Marshal(rawConfig)
@ -104,6 +106,8 @@ func (p *providerPluginGRPCClient) Configure(
_, err = p.client.Configure(p.doneCtx, &ConfigureRequest{
ClusterId: clusterId,
DatacenterName: datacenterName,
DnsDomain: dnsDomain,
IsRoot: isRoot,
Config: config,
})

View File

@ -15,7 +15,7 @@ type providerPluginRPCServer struct {
}
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 {
@ -95,10 +95,14 @@ type providerPluginRPCClient struct {
func (p *providerPluginRPCClient) Configure(
clusterId string,
datacenterName string,
dnsDomain string,
isRoot bool,
rawConfig map[string]interface{}) error {
return p.client.Call("Plugin.Configure", &ConfigureRPCRequest{
ClusterId: clusterId,
DatacenterName: datacenterName,
DNSDomain: dnsDomain,
IsRoot: isRoot,
RawConfig: rawConfig,
}, &struct{}{})
@ -175,6 +179,8 @@ var _ ca.Provider = &providerPluginRPCClient{}
type ConfigureRPCRequest struct {
ClusterId string
DatacenterName string
DNSDomain string
IsRoot bool
RawConfig map[string]interface{}
}

View File

@ -12,7 +12,8 @@ import (
type Provider interface {
// Configure initializes the provider based on the given cluster ID, root status
// 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.
// This can also be a no-op if a root certificate already exists for the given