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

feat: Add v2.KeptnInterface that adds context.Context support to api.KeptnInterface #449

Merged
merged 61 commits into from
Jun 23, 2022

Conversation

arthurpitman
Copy link
Contributor

@arthurpitman arthurpitman commented Apr 19, 2022

This PR

  • Provides a v2 package with the same functionality as the api package, just with added context.Context

return r.GetStageResourceWithContext(context.TODO(), project, stage, resourceURI)
}

// GetStageResourceContext retrieves a stage resource from the configuration service.

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
comment on exported method ResourceHandler.GetStageResourceWithContext should be of the form "GetStageResourceWithContext ..."

return s.ControlSequenceWithContext(context.TODO(), params)
}

func (s *SequenceControlHandler) ControlSequenceWithContext(ctx context.Context, params SequenceControlParams) error {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method SequenceControlHandler.ControlSequenceWithContext should have comment or be unexported

return u.PingWithContext(context.TODO(), integrationID)
}

func (u *UniformHandler) PingWithContext(ctx context.Context, integrationID string) (*models.Integration, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.PingWithContext should have comment or be unexported

return u.RegisterIntegrationWithContext(context.TODO(), integration)
}

func (u *UniformHandler) RegisterIntegrationWithContext(ctx context.Context, integration models.Integration) (string, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.RegisterIntegrationWithContext should have comment or be unexported

return u.CreateSubscriptionWithContext(context.TODO(), integrationID, subscription)
}

func (u *UniformHandler) CreateSubscriptionWithContext(ctx context.Context, integrationID string, subscription models.EventSubscription) (string, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.CreateSubscriptionWithContext should have comment or be unexported

return u.UnregisterIntegrationWithContext(context.TODO(), integrationID)
}

func (u *UniformHandler) UnregisterIntegrationWithContext(ctx context.Context, integrationID string) error {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.UnregisterIntegrationWithContext should have comment or be unexported


req, err := http.NewRequest("GET", url.String(), nil)
func (u *UniformHandler) GetRegistrationsWithContext(ctx context.Context) ([]*models.Integration, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.GetRegistrationsWithContext should have comment or be unexported

@arthurpitman arthurpitman changed the title Feature/add context to api set feat: Add context.Context support to interfaces offered by api.KeptnInterface Apr 19, 2022
@arthurpitman arthurpitman changed the title feat: Add context.Context support to interfaces offered by api.KeptnInterface feat: Add context.Context support to Keptn, KeptnBase and interfaces offered by api.KeptnInterface Apr 26, 2022
pkg/lib/v0_2_0/keptn.go Outdated Show resolved Hide resolved
@arthurpitman arthurpitman force-pushed the feature/add-context-to-api-set branch from b8b854e to 0b944d0 Compare May 6, 2022 13:27
GetMetadata() (*models.Metadata, *models.Error)
}

// APIV2SendEventOptions are options for APIV2Interface.SendEvent().
type APIV2SendEventOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2SendEventOptions by other packages, and that stutters; consider calling this V2SendEventOptions

type APIV2SendEventOptions struct{}

// APIV2TriggerEvaluationOptions are options for APIV2Interface.TriggerEvaluation().
type APIV2TriggerEvaluationOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2TriggerEvaluationOptions by other packages, and that stutters; consider calling this V2TriggerEvaluationOptions

type APIV2TriggerEvaluationOptions struct{}

// APIV2CreateProjectOptions are options for APIV2Interface.CreateProject().
type APIV2CreateProjectOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2CreateProjectOptions by other packages, and that stutters; consider calling this V2CreateProjectOptions

type APIV2CreateProjectOptions struct{}

// APIV2UpdateProjectOptions are options for APIV2Interface.UpdateProject().
type APIV2UpdateProjectOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2UpdateProjectOptions by other packages, and that stutters; consider calling this V2UpdateProjectOptions

type APIV2UpdateProjectOptions struct{}

// APIV2DeleteProjectOptions are options for APIV2Interface.DeleteProject().
type APIV2DeleteProjectOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2DeleteProjectOptions by other packages, and that stutters; consider calling this V2DeleteProjectOptions

type APIV2CreateServiceOptions struct{}

// APIV2DeleteServiceOptions are options for APIV2Interface.DeleteService().
type APIV2DeleteServiceOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2DeleteServiceOptions by other packages, and that stutters; consider calling this V2DeleteServiceOptions

type APIV2DeleteServiceOptions struct{}

// APIV2GetMetadataOptions are options for APIV2Interface.GetMetadata().
type APIV2GetMetadataOptions struct{}
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2GetMetadataOptions by other packages, and that stutters; consider calling this V2GetMetadataOptions

// APIV2GetMetadataOptions are options for APIV2Interface.GetMetadata().
type APIV2GetMetadataOptions struct{}

type APIV2Interface interface {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type APIV2Interface should have comment or be unexported

// APIV2GetMetadataOptions are options for APIV2Interface.GetMetadata().
type APIV2GetMetadataOptions struct{}

type APIV2Interface interface {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2Interface by other packages, and that stutters; consider calling this V2Interface

}

// APIV2Handler handles projects
type APIV2Handler struct {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
type name will be used as api.APIV2Handler by other packages, and that stutters; consider calling this V2Handler

@arthurpitman arthurpitman force-pushed the feature/add-context-to-api-set branch from 677fee8 to 5d35c95 Compare May 6, 2022 15:05
// APIGetMetadataOptions are options for APIInterface.GetMetadata().
type APIGetMetadataOptions struct{}

type APIInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type APIInterface should have comment or be unexported

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golint

pkg/api/utils/v2/uniformUtils.go|104 col 1| exported method UniformHandler.Ping should have comment or be unexported
pkg/api/utils/v2/uniformUtils.go|122 col 1| exported method UniformHandler.RegisterIntegration should have comment or be unexported
pkg/api/utils/v2/uniformUtils.go|141 col 1| exported method UniformHandler.CreateSubscription should have comment or be unexported
pkg/api/utils/v2/uniformUtils.go|160 col 1| exported method UniformHandler.UnregisterIntegration should have comment or be unexported
pkg/api/utils/v2/uniformUtils.go|168 col 1| exported method UniformHandler.GetRegistrations should have comment or be unexported

// AuthAuthenticateOptions are options for AuthInterface.Authenticate().
type AuthAuthenticateOptions struct{}

type AuthInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type AuthInterface should have comment or be unexported


var _ KeptnInterface = (*APISet)(nil)

type KeptnInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type KeptnInterface should have comment or be unexported

// EventsGetEventsWithRetryOptions are options for EventsInterface.GetEventsWithRetry().
type EventsGetEventsWithRetryOptions struct{}

type EventsInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type EventsInterface should have comment or be unexported

}
}

const mongodbDatastoreServiceBaseUrl = "mongodb-datastore"

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
const mongodbDatastoreServiceBaseUrl should be mongodbDatastoreServiceBaseURL

"net/http"
)

type StatusBody struct {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type StatusBody should have comment or be unexported

// ShipyardControlGetOpenTriggeredEventsOptions are options for ShipyardControlInterface.GetOpenTriggeredEvents().
type ShipyardControlGetOpenTriggeredEventsOptions struct{}

type ShipyardControlInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type ShipyardControlInterface should have comment or be unexported

// StagesGetAllStagesOptions are options for StagesInterface.GetAllStages().
type StagesGetAllStagesOptions struct{}

type StagesInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type StagesInterface should have comment or be unexported

// UniformGetRegistrationsOptions are options for UniformInterface.GetRegistrations().
type UniformGetRegistrationsOptions struct{}

type UniformInterface interface {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type UniformInterface should have comment or be unexported

GetRegistrations(ctx context.Context, opts UniformGetRegistrationsOptions) ([]*models.Integration, error)
}

type UniformHandler struct {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type UniformHandler should have comment or be unexported

Scheme string
}

func NewUniformHandler(baseURL string) *UniformHandler {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported function NewUniformHandler should have comment or be unexported

@arthurpitman arthurpitman force-pushed the feature/add-context-to-api-set branch from 1841665 to a8d49da Compare May 10, 2022 13:23
return u.HTTPClient
}

func (u *UniformHandler) Ping(ctx context.Context, integrationID string, opts UniformPingOptions) (*models.Integration, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.Ping should have comment or be unexported

return response, nil
}

func (u *UniformHandler) RegisterIntegration(ctx context.Context, integration models.Integration, opts UniformRegisterIntegrationOptions) (string, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.RegisterIntegration should have comment or be unexported

return registerIntegrationResponse.ID, nil
}

func (u *UniformHandler) CreateSubscription(ctx context.Context, integrationID string, subscription models.EventSubscription, opts UniformCreateSubscriptionOptions) (string, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.CreateSubscription should have comment or be unexported

return createSubscriptionResponse.ID, nil
}

func (u *UniformHandler) UnregisterIntegration(ctx context.Context, integrationID string, opts UniformUnregisterIntegrationOptions) error {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.UnregisterIntegration should have comment or be unexported

return nil
}

func (u *UniformHandler) GetRegistrations(ctx context.Context, opts UniformGetRegistrationsOptions) ([]*models.Integration, error) {

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method UniformHandler.GetRegistrations should have comment or be unexported

@arthurpitman arthurpitman changed the title feat: Add context.Context support to Keptn, KeptnBase and interfaces offered by api.KeptnInterface feat: Add v2.KeptnInterface that adds context.Context support to api.KeptnInterface May 31, 2022
return r.UpdateResourcesByURI(ctx, r.Scheme+"://"+r.BaseURL+v1ProjectPath+"/"+project+pathToStage+"/"+stage+pathToService+"/"+url.QueryEscape(service)+pathToResource, resources)
}

func (r *ResourceHandler) CreateResourcesByURI(ctx context.Context, uri string, resources []*models.Resource) (string, error) {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method ResourceHandler.CreateResourcesByURI should have comment or be unexported

return r.writeResources(ctx, uri, "POST", resources)
}

func (r *ResourceHandler) UpdateResourcesByURI(ctx context.Context, uri string, resources []*models.Resource) (string, error) {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method ResourceHandler.UpdateResourcesByURI should have comment or be unexported

return version.Version, nil
}

func (r *ResourceHandler) UpdateResourceByURI(ctx context.Context, uri string, resource *models.Resource) (string, error) {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method ResourceHandler.UpdateResourceByURI should have comment or be unexported

return r.CreateResourcesByURI(ctx, r.applyOptions(buildURI, opts.URIOptions), resource)
}

func (r *ResourceHandler) GetResourceByURI(ctx context.Context, uri string) (*models.Resource, error) {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method ResourceHandler.GetResourceByURI should have comment or be unexported

return resource, nil
}

func (r *ResourceHandler) DeleteResourceByURI(ctx context.Context, uri string) error {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported method ResourceHandler.DeleteResourceByURI should have comment or be unexported

@arthurpitman arthurpitman force-pushed the feature/add-context-to-api-set branch 3 times, most recently from 3fbb0ed to 7d9743d Compare June 2, 2022 12:44
@arthurpitman arthurpitman force-pushed the feature/add-context-to-api-set branch from 7d9743d to 3ea9b5c Compare June 2, 2022 12:45
GetMetadata(ctx context.Context, opts APIGetMetadataOptions) (*models.Metadata, *models.Error)
}

type APIHandler struct {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type APIHandler should have comment or be unexported

Authenticate(ctx context.Context, opts AuthAuthenticateOptions) (*models.EventContext, *models.Error)
}

type AuthHandler struct {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type AuthHandler should have comment or be unexported

GetEventsWithRetry(ctx context.Context, filter *EventFilter, maxRetries int, retrySleepTime time.Duration, opts EventsGetEventsWithRetryOptions) ([]*models.KeptnContextExtendedCE, error)
}

type EventHandler struct {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type EventHandler should have comment or be unexported

return createEventHandler(baseURL, "", "", httpClient, "http")
}

const mongodbDatastoreServiceBaseUrl = "mongodb-datastore"
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
const mongodbDatastoreServiceBaseUrl should be mongodbDatastoreServiceBaseURL

return nil
}

// NewSequenceControlHandlerWithHTTPClient returns a new SequenceControlHandler
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
comment on exported function NewSequenceControlHandler should be of the form "NewSequenceControlHandler ..."

GetOpenTriggeredEvents(ctx context.Context, filter EventFilter, opts ShipyardControlGetOpenTriggeredEventsOptions) ([]*models.KeptnContextExtendedCE, error)
}

type ShipyardControllerHandler struct {
Copy link

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported type ShipyardControllerHandler should have comment or be unexported

Signed-off-by: Arthur Pitman <[email protected]>
func (a *APIHandler) GetMetadata(ctx context.Context, opts APIGetMetadataOptions) (*models.Metadata, *models.Error) {
baseURL := a.getAPIServicePath()

body, mErr := getAndExpectSuccess(ctx, a.scheme+"://"+baseURL+v1MetadataPath, nil)
Copy link
Member

Choose a reason for hiding this comment

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

I think here we also need to pass the api handler, instead of nil, otherwise we will get a nil pointer exception later in the addAuthHeader() function

)

const pathToResource = "/resource"
const pathToService = "/service"
const pathToStage = "/stage"
const configurationServiceBaseURL = "configuration-service"

var ResourceNotFoundError = errors.New("Resource not found")
var ResourceNotFoundError = v2.ResourceNotFoundError

Choose a reason for hiding this comment

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

[golint] reported by reviewdog 🐶
exported var ResourceNotFoundError should have comment or be unexported

… v1 (#479)

* debug output

Signed-off-by: Florian Bacher <[email protected]>

* debug output

Signed-off-by: Florian Bacher <[email protected]>

* ensure that uniform handler is set

Signed-off-by: Florian Bacher <[email protected]>

* ensure that uniform handler is set

Signed-off-by: Florian Bacher <[email protected]>

* ensure that all api handlers are set

Signed-off-by: Florian Bacher <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Jun 23, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 8 Code Smells

No Coverage information No Coverage information
16.6% 16.6% Duplication

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants