Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor - Use interface for rekor #98

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
)

require (
github.com/golang/mock v1.6.0
github.com/sigstore/cosign v1.7.2
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
)
Expand Down
185 changes: 1 addition & 184 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func verify(ctx context.Context,
}

/* Verify signature on the intoto attestation. */
env, cert, err := pkg.VerifyProvenanceSignature(ctx, rClient, provenance, artifactHash)
env, cert, err := pkg.VerifyProvenanceSignature(ctx, provenance, artifactHash, rClient.Index, rClient.Tlog, rClient.Entries)
if err != nil {
return nil, err
}
Expand Down
124 changes: 124 additions & 0 deletions pkg/mockentries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package pkg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put generated mocks in a separate package.


import (
reflect "reflect"

runtime "github.com/go-openapi/runtime"
gomock "github.com/golang/mock/gomock"
entries "github.com/sigstore/rekor/pkg/generated/client/entries"
)

// MockEntriesClientService is a mock of ClientService interface.
type MockEntriesClientService struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe provide a Makefile target or instructions somewhere on how to regenerate these?

ctrl *gomock.Controller
recorder *MockEntriesClientServiceMockRecorder
}

// MockEntriesClientServiceMockRecorder is the mock recorder for MockEntriesClientService.
type MockEntriesClientServiceMockRecorder struct {
mock *MockEntriesClientService
}

// NewMockEntriesClientService creates a new mock instance.
func NewMockEntriesClientService(ctrl *gomock.Controller) *MockEntriesClientService {
mock := &MockEntriesClientService{ctrl: ctrl}
mock.recorder = &MockEntriesClientServiceMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockEntriesClientService) EXPECT() *MockEntriesClientServiceMockRecorder {
return m.recorder
}

// CreateLogEntry mocks base method.
func (m *MockEntriesClientService) CreateLogEntry(params *entries.CreateLogEntryParams, opts ...entries.ClientOption) (*entries.CreateLogEntryCreated, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "CreateLogEntry", varargs...)
ret0, _ := ret[0].(*entries.CreateLogEntryCreated)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// CreateLogEntry indicates an expected call of CreateLogEntry.
func (mr *MockEntriesClientServiceMockRecorder) CreateLogEntry(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLogEntry", reflect.TypeOf((*MockEntriesClientService)(nil).CreateLogEntry), varargs...)
}

// GetLogEntryByIndex mocks base method.
func (m *MockEntriesClientService) GetLogEntryByIndex(params *entries.GetLogEntryByIndexParams, opts ...entries.ClientOption) (*entries.GetLogEntryByIndexOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetLogEntryByIndex", varargs...)
ret0, _ := ret[0].(*entries.GetLogEntryByIndexOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// GetLogEntryByIndex indicates an expected call of GetLogEntryByIndex.
func (mr *MockEntriesClientServiceMockRecorder) GetLogEntryByIndex(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogEntryByIndex", reflect.TypeOf((*MockEntriesClientService)(nil).GetLogEntryByIndex), varargs...)
}

// GetLogEntryByUUID mocks base method.
func (m *MockEntriesClientService) GetLogEntryByUUID(params *entries.GetLogEntryByUUIDParams, opts ...entries.ClientOption) (*entries.GetLogEntryByUUIDOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetLogEntryByUUID", varargs...)
ret0, _ := ret[0].(*entries.GetLogEntryByUUIDOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// GetLogEntryByUUID indicates an expected call of GetLogEntryByUUID.
func (mr *MockEntriesClientServiceMockRecorder) GetLogEntryByUUID(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogEntryByUUID", reflect.TypeOf((*MockEntriesClientService)(nil).GetLogEntryByUUID), varargs...)
}

// SearchLogQuery mocks base method.
func (m *MockEntriesClientService) SearchLogQuery(params *entries.SearchLogQueryParams, opts ...entries.ClientOption) (*entries.SearchLogQueryOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SearchLogQuery", varargs...)
ret0, _ := ret[0].(*entries.SearchLogQueryOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// SearchLogQuery indicates an expected call of SearchLogQuery.
func (mr *MockEntriesClientServiceMockRecorder) SearchLogQuery(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchLogQuery", reflect.TypeOf((*MockEntriesClientService)(nil).SearchLogQuery), varargs...)
}

// SetTransport mocks base method.
func (m *MockEntriesClientService) SetTransport(transport runtime.ClientTransport) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetTransport", transport)
}

// SetTransport indicates an expected call of SetTransport.
func (mr *MockEntriesClientServiceMockRecorder) SetTransport(transport interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTransport", reflect.TypeOf((*MockEntriesClientService)(nil).SetTransport), transport)
}
64 changes: 64 additions & 0 deletions pkg/mockindex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pkg

import (
reflect "reflect"

runtime "github.com/go-openapi/runtime"
gomock "github.com/golang/mock/gomock"
"github.com/sigstore/rekor/pkg/generated/client/index"
)

// MockClientService is a mock of ClientService interface.
type MockClientService struct {
ctrl *gomock.Controller
recorder *MockClientServiceMockRecorder
}

// MockClientServiceMockRecorder is the mock recorder for MockClientService.
type MockClientServiceMockRecorder struct {
mock *MockClientService
}

// NewMockClientService creates a new mock instance.
func NewMockClientService(ctrl *gomock.Controller) *MockClientService {
mock := &MockClientService{ctrl: ctrl}
mock.recorder = &MockClientServiceMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockClientService) EXPECT() *MockClientServiceMockRecorder {
return m.recorder
}

// SearchIndex mocks base method.
func (m *MockClientService) SearchIndex(params *index.SearchIndexParams, opts ...index.ClientOption) (*index.SearchIndexOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SearchIndex", varargs...)
ret0, _ := ret[0].(*index.SearchIndexOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// SearchIndex indicates an expected call of SearchIndex.
func (mr *MockClientServiceMockRecorder) SearchIndex(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchIndex", reflect.TypeOf((*MockClientService)(nil).SearchIndex), varargs...)
}

// SetTransport mocks base method.
func (m *MockClientService) SetTransport(transport runtime.ClientTransport) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetTransport", transport)
}

// SetTransport indicates an expected call of SetTransport.
func (mr *MockClientServiceMockRecorder) SetTransport(transport interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTransport", reflect.TypeOf((*MockClientService)(nil).SetTransport), transport)
}
84 changes: 84 additions & 0 deletions pkg/mocktlog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package pkg

import (
reflect "reflect"

runtime "github.com/go-openapi/runtime"
gomock "github.com/golang/mock/gomock"
tlog "github.com/sigstore/rekor/pkg/generated/client/tlog"
)

// MockTlogClientService is a mock of ClientService interface.
type MockTlogClientService struct {
ctrl *gomock.Controller
recorder *MockTlogClientServiceMockRecorder
}

// MockTlogClientServiceMockRecorder is the mock recorder for MockTlogClientService.
type MockTlogClientServiceMockRecorder struct {
mock *MockTlogClientService
}

// NewMockTlogClientService creates a new mock instance.
func NewMockTlogClientService(ctrl *gomock.Controller) *MockTlogClientService {
mock := &MockTlogClientService{ctrl: ctrl}
mock.recorder = &MockTlogClientServiceMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockTlogClientService) EXPECT() *MockTlogClientServiceMockRecorder {
return m.recorder
}

// GetLogInfo mocks base method.
func (m *MockTlogClientService) GetLogInfo(params *tlog.GetLogInfoParams, opts ...tlog.ClientOption) (*tlog.GetLogInfoOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetLogInfo", varargs...)
ret0, _ := ret[0].(*tlog.GetLogInfoOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// GetLogInfo indicates an expected call of GetLogInfo.
func (mr *MockTlogClientServiceMockRecorder) GetLogInfo(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogInfo", reflect.TypeOf((*MockTlogClientService)(nil).GetLogInfo), varargs...)
}

// GetLogProof mocks base method.
func (m *MockTlogClientService) GetLogProof(params *tlog.GetLogProofParams, opts ...tlog.ClientOption) (*tlog.GetLogProofOK, error) {
m.ctrl.T.Helper()
varargs := []interface{}{params}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetLogProof", varargs...)
ret0, _ := ret[0].(*tlog.GetLogProofOK)
ret1, _ := ret[1].(error)
return ret0, ret1
}

// GetLogProof indicates an expected call of GetLogProof.
func (mr *MockTlogClientServiceMockRecorder) GetLogProof(params interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{params}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogProof", reflect.TypeOf((*MockTlogClientService)(nil).GetLogProof), varargs...)
}

// SetTransport mocks base method.
func (m *MockTlogClientService) SetTransport(transport runtime.ClientTransport) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetTransport", transport)
}

// SetTransport indicates an expected call of SetTransport.
func (mr *MockTlogClientServiceMockRecorder) SetTransport(transport interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTransport", reflect.TypeOf((*MockTlogClientService)(nil).SetTransport), transport)
}
Loading