Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
feat: Introduced interfaces for different types of APIs (#379)
Browse files Browse the repository at this point in the history
* feat: Introduced interfaces for different types of APIs

Signed-off-by: warber <bernd.warmuth@dynatrace.com>

* added missing method in APIV1Interface

Signed-off-by: warber <bernd.warmuth@dynatrace.com>
  • Loading branch information
warber committed Jan 28, 2022
1 parent d68990e commit 349cd94
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 22 deletions.
11 changes: 11 additions & 0 deletions pkg/api/utils/apiUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import (
const v1EventPath = "/v1/event"
const v1MetadataPath = "/v1/metadata"

type APIV1Interface interface {
SendEvent(event models.KeptnContextExtendedCE) (*models.EventContext, *models.Error)
TriggerEvaluation(project string, stage string, service string, evaluation models.Evaluation) (*models.EventContext, *models.Error)
CreateProject(project models.CreateProject) (string, *models.Error)
UpdateProject(project models.CreateProject) (string, *models.Error)
DeleteProject(project models.Project) (*models.DeleteProjectResponse, *models.Error)
CreateService(project string, service models.CreateService) (string, *models.Error)
DeleteService(project string, service string) (*models.DeleteServiceResponse, *models.Error)
GetMetadata() (*models.Metadata, *models.Error)
}

// APIHandler handles projects
type APIHandler struct {
BaseURL string
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/utils/authUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/keptn/go-utils/pkg/api/models"
)

type AuthV1Interface interface {
Authenticate() (*models.EventContext, *models.Error)
}

// AuthHandler handles projects
type AuthHandler struct {
BaseURL string
Expand Down
46 changes: 24 additions & 22 deletions pkg/api/utils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import (
"net/url"
)

var _ KeptnInterface = (*APISet)(nil)

type KeptnInterface interface {
APIV1() *APIHandler
AuthV1() *AuthHandler
EventsV1() *EventHandler
LogsV1() *LogHandler
ProjectsV1() *ProjectHandler
ResourcesV1() *ResourceHandler
SecretsV1() *SecretHandler
SequencesV1() *SequenceControlHandler
ServicesV1() *ServiceHandler
StagesV1() *StageHandler
UniformV1() *UniformHandler
APIV1() APIV1Interface
AuthV1() AuthV1Interface
EventsV1() EventsV1Interface
LogsV1() LogsV1Interface
ProjectsV1() ProjectsV1Interface
ResourcesV1() ResourcesV1Interface
SecretsV1() SecretsV1Interface
SequencesV1() SequencesV1Interface
ServicesV1() ServicesV1Interface
StagesV1() StagesV1Interface
UniformV1() UniformV1Interface
}

// APISet contains the API utils for all keptn APIs
Expand All @@ -42,57 +44,57 @@ type APISet struct {
}

// APIV1 retrieves the APIHandler
func (c *APISet) APIV1() *APIHandler {
func (c *APISet) APIV1() APIV1Interface {
return c.apiHandler
}

// AuthV1 retrieves the AuthHandler
func (c *APISet) AuthV1() *AuthHandler {
func (c *APISet) AuthV1() AuthV1Interface {
return c.authHandler
}

// EventsV1 retrieves the EventHandler
func (c *APISet) EventsV1() *EventHandler {
func (c *APISet) EventsV1() EventsV1Interface {
return c.eventHandler
}

// LogsV1 retrieves the LogHandler
func (c *APISet) LogsV1() *LogHandler {
func (c *APISet) LogsV1() LogsV1Interface {
return c.logHandler
}

// ProjectsV1 retrieves the ProjectHandler
func (c *APISet) ProjectsV1() *ProjectHandler {
func (c *APISet) ProjectsV1() ProjectsV1Interface {
return c.projectHandler
}

// ResourcesV1 retrieves the ResourceHandler
func (c *APISet) ResourcesV1() *ResourceHandler {
func (c *APISet) ResourcesV1() ResourcesV1Interface {
return c.resourceHandler
}

// SecretsV1 retrieves the SecretHandler
func (c *APISet) SecretsV1() *SecretHandler {
func (c *APISet) SecretsV1() SecretsV1Interface {
return c.secretHandler
}

// SequencesV1 retrieves the SequenceControlHandler
func (c *APISet) SequencesV1() *SequenceControlHandler {
func (c *APISet) SequencesV1() SequencesV1Interface {
return c.sequenceControlHandler
}

// ServicesV1 retrieves the ServiceHandler
func (c *APISet) ServicesV1() *ServiceHandler {
func (c *APISet) ServicesV1() ServicesV1Interface {
return c.serviceHandler
}

// StagesV1 retrieves the StageHandler
func (c *APISet) StagesV1() *StageHandler {
func (c *APISet) StagesV1() StagesV1Interface {
return c.stageHandler
}

// UniformV1 retrieves the UniformHandler
func (c *APISet) UniformV1() *UniformHandler {
func (c *APISet) UniformV1() UniformV1Interface {
return c.uniformHandler
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/api/utils/eventUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/keptn/go-utils/pkg/api/models"
)

type EventsV1Interface interface {
GetEvents(filter *EventFilter) ([]*models.KeptnContextExtendedCE, *models.Error)
GetEventsWithRetry(filter *EventFilter, maxRetries int, retrySleepTime time.Duration) ([]*models.KeptnContextExtendedCE, error)
}

// EventHandler handles services
type EventHandler struct {
BaseURL string
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/utils/logUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const v1LogPath = "/v1/log"

var defaultSyncInterval = 1 * time.Minute

type LogsV1Interface interface {
ILogHandler
}

//go:generate moq -pkg utils_mock -skip-ensure -out ./fake/log_handler_mock.go . ILogHandler
type ILogHandler interface {
Log(logs []models.LogEntry)
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/utils/projectUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import (

const v1ProjectPath = "/v1/project"

type ProjectsV1Interface interface {
CreateProject(project models.Project) (*models.EventContext, *models.Error)
DeleteProject(project models.Project) (*models.EventContext, *models.Error)
GetProject(project models.Project) (*models.Project, *models.Error)
GetAllProjects() ([]*models.Project, error)
UpdateConfigurationServiceProject(project models.Project) (*models.EventContext, *models.Error)
}

// ProjectHandler handles projects
type ProjectHandler struct {
BaseURL string
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/utils/resourceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ const pathToService = "/service"
const pathToStage = "/stage"
const pathToProject = v1ProjectPath + "/"

type ResourcesV1Interface interface {
CreateResources(project string, stage string, service string, resources []*models.Resource) (*models.EventContext, *models.Error)
CreateProjectResources(project string, resources []*models.Resource) (string, error)
GetProjectResource(project string, resourceURI string, options ...GetOption) (*models.Resource, error)
UpdateProjectResource(project string, resource *models.Resource) (string, error)
DeleteProjectResource(project string, resourceURI string) error
UpdateProjectResources(project string, resources []*models.Resource) (string, error)
CreateStageResources(project string, stage string, resources []*models.Resource) (string, error)
GetStageResource(project string, stage string, resourceURI string, options ...GetOption) (*models.Resource, error)
UpdateStageResource(project string, stage string, resource *models.Resource) (string, error)
UpdateStageResources(project string, stage string, resources []*models.Resource) (string, error)
DeleteStageResource(project string, stage string, resourceURI string) error
CreateServiceResources(project string, stage string, service string, resources []*models.Resource) (string, error)
GetServiceResource(project string, stage string, service string, resourceURI string, options ...GetOption) (*models.Resource, error)
UpdateServiceResource(project string, stage string, service string, resource *models.Resource) (string, error)
UpdateServiceResources(project string, stage string, service string, resources []*models.Resource) (string, error)
DeleteServiceResource(project string, stage string, service string, resourceURI string) error
GetAllStageResources(project string, stage string) ([]*models.Resource, error)
GetAllServiceResources(project string, stage string, service string) ([]*models.Resource, error)
}

// ResourceHandler handles resources
type ResourceHandler struct {
BaseURL string
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/utils/secretUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
const secretServiceBaseURL = "secrets"
const v1SecretPath = "/v1/secret"

type SecretsV1Interface interface {
SecretHandlerInterface
}

//go:generate moq -pkg utils_mock -skip-ensure -out ./fake/secret_handler_mock.go . SecretHandlerInterface
type SecretHandlerInterface interface {
CreateSecret(secret models.Secret) error
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/utils/sequenceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

const v1SequenceControlPath = "/v1/sequence/%s/%s/control"

type SequencesV1Interface interface {
ControlSequence(params SequenceControlParams) error
}

type SequenceControlHandler struct {
BaseURL string
AuthToken string
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/utils/serviceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
"github.com/keptn/go-utils/pkg/api/models"
)

type ServicesV1Interface interface {
CreateServiceInStage(project string, stage string, serviceName string) (*models.EventContext, *models.Error)
DeleteServiceFromStage(project string, stage string, serviceName string) (*models.EventContext, *models.Error)
GetService(project, stage, service string) (*models.Service, error)
GetAllServices(project string, stage string) ([]*models.Service, error)
}

// ServiceHandler handles services
type ServiceHandler struct {
BaseURL string
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/utils/shipyardControllerUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (

const shipyardControllerBaseURL = "controlPlane"

type ShipyardControlV1Interface interface {
GetOpenTriggeredEvents(filter EventFilter) ([]*models.KeptnContextExtendedCE, error)
}

// ShipyardControllerHandler handles services
type ShipyardControllerHandler struct {
BaseURL string
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/utils/stageUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

type StagesV1Interface interface {
CreateStage(project string, stageName string) (*models.EventContext, *models.Error)
GetAllStages(project string) ([]*models.Stage, error)
}

// StageHandler handles stages
type StageHandler struct {
BaseURL string
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/utils/uniformUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import (
const uniformRegistrationBaseURL = "uniform/registration"
const v1UniformPath = "/v1/uniform/registration"

type UniformV1Interface interface {
Ping(integrationID string) (*models.Integration, error)
RegisterIntegration(integration models.Integration) (string, error)
CreateSubscription(integrationID string, subscription models.EventSubscription) (string, error)
UnregisterIntegration(integrationID string) error
GetRegistrations() ([]*models.Integration, error)
}

type UniformHandler struct {
BaseURL string
AuthToken string
Expand Down

0 comments on commit 349cd94

Please sign in to comment.