Skip to content

Commit

Permalink
Remove unused code in marketplace API (#2124)
Browse files Browse the repository at this point in the history
  • Loading branch information
reivaj05 committed Jun 15, 2022
1 parent a024a13 commit e5f7a03
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 253 deletions.
92 changes: 0 additions & 92 deletions operatorapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 4 additions & 55 deletions operatorapi/marketplace.go
Expand Up @@ -54,21 +54,6 @@ func registerMarketplaceHandlers(api *operations.OperatorAPI) {
}
return operator_api.NewPostMPIntegrationCreated()
})

api.OperatorAPIPatchMPIntegrationHandler = operator_api.PatchMPIntegrationHandlerFunc(func(params operator_api.PatchMPIntegrationParams, session *models.Principal) middleware.Responder {
err := patchMPIntegrationResponse(session, params)
if err != nil {
return operator_api.NewPatchMPIntegrationDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewPatchMPIntegrationOK()
})

api.OperatorAPIDeleteMPIntegrationHandler = operator_api.DeleteMPIntegrationHandlerFunc(func(params operator_api.DeleteMPIntegrationParams, session *models.Principal) middleware.Responder {
if err := deleteMPIntegrationResponse(session, params); err != nil {
return operator_api.NewDeleteMPIntegrationDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewDeleteMPIntegrationNoContent()
})
}

func getMPIntegrationResponse(session *models.Principal, params operator_api.GetMPIntegrationParams) (*models.MpIntegration, *models.Error) {
Expand Down Expand Up @@ -108,37 +93,21 @@ func postMPIntegrationResponse(session *models.Principal, params operator_api.Po
if err != nil {
return errors.ErrorWithContext(ctx, err)
}
return setMPIntegration(ctx, params.Body.Email, false, &k8sClient{client: clientSet})
}

func patchMPIntegrationResponse(session *models.Principal, params operator_api.PatchMPIntegrationParams) *models.Error {
if true { // This block will be removed once service to register emails is deployed
return &models.Error{Code: 501}
}
clientSet, err := cluster.K8sClient(session.STSSessionToken)
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()
if err != nil {
return errors.ErrorWithContext(ctx, err)
}
return setMPIntegration(ctx, params.Body.Email, true, &k8sClient{client: clientSet})
return setMPIntegration(ctx, params.Body.Email, &k8sClient{client: clientSet})
}

func setMPIntegration(ctx context.Context, email string, override bool, clientSet K8sClientI) *models.Error {
func setMPIntegration(ctx context.Context, email string, clientSet K8sClientI) *models.Error {
if email == "" {
return errors.ErrorWithContext(ctx, errors.ErrBadRequest, fmt.Errorf(emailNotSetMsg))
}
if _, err := setMPEmail(ctx, email, override, clientSet); err != nil {
if _, err := setMPEmail(ctx, email, clientSet); err != nil {
return errors.ErrorWithContext(ctx, err)
}
return nil
}

func setMPEmail(ctx context.Context, email string, override bool, clientSet K8sClientI) (*corev1.ConfigMap, error) {
func setMPEmail(ctx context.Context, email string, clientSet K8sClientI) (*corev1.ConfigMap, error) {
cm := createCM(email)
if override {
return clientSet.updateConfigMap(ctx, "default", cm, metav1.UpdateOptions{})
}
return clientSet.createConfigMap(ctx, "default", cm, metav1.CreateOptions{})
}

Expand All @@ -156,26 +125,6 @@ func createCM(email string) *corev1.ConfigMap {
}
}

func deleteMPIntegrationResponse(session *models.Principal, params operator_api.DeleteMPIntegrationParams) *models.Error {
if true { // This block will be removed once service to register emails is deployed
return &models.Error{Code: 501}
}
clientSet, err := cluster.K8sClient(session.STSSessionToken)
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()
if err != nil {
return errors.ErrorWithContext(ctx, err)
}
return deleteMPIntegration(ctx, &k8sClient{client: clientSet})
}

func deleteMPIntegration(ctx context.Context, clientSet K8sClientI) *models.Error {
if err := clientSet.deleteConfigMap(ctx, "default", getMPConfigMapKey(mpConfigMapKey), metav1.DeleteOptions{}); err != nil {
return errors.ErrorWithContext(ctx, err)
}
return nil
}

func getMPConfigMapKey(envVar string) string {
if mp := os.Getenv(envVar); mp != "" {
return mp
Expand Down
55 changes: 3 additions & 52 deletions operatorapi/marketplace_test.go
Expand Up @@ -110,13 +110,9 @@ func (suite *MarketplaceTestSuite) TestRegisterMarketplaceHandlers() {
api := &operations.OperatorAPI{}
suite.assert.Nil(api.OperatorAPIGetMPIntegrationHandler)
suite.assert.Nil(api.OperatorAPIPostMPIntegrationHandler)
suite.assert.Nil(api.OperatorAPIPatchMPIntegrationHandler)
suite.assert.Nil(api.OperatorAPIDeleteMPIntegrationHandler)
registerMarketplaceHandlers(api)
suite.assert.NotNil(api.OperatorAPIGetMPIntegrationHandler)
suite.assert.NotNil(api.OperatorAPIPostMPIntegrationHandler)
suite.assert.NotNil(api.OperatorAPIPatchMPIntegrationHandler)
suite.assert.NotNil(api.OperatorAPIDeleteMPIntegrationHandler)
}

// TODO
Expand All @@ -134,27 +130,6 @@ func (suite *MarketplaceTestSuite) TestGetMPIntegrationHandlerWithError() {
suite.assert.True(ok)
}

func (suite *MarketplaceTestSuite) TestPatchMPIntegrationHandlerWithError() {
api := &operations.OperatorAPI{}
registerMarketplaceHandlers(api)
params := operator_api.NewPatchMPIntegrationParams()
params.HTTPRequest = &http.Request{}
params.Body = &models.MpIntegration{Email: "mock@mock.com"}
response := api.OperatorAPIPatchMPIntegrationHandler.Handle(params, &models.Principal{})
_, ok := response.(*operator_api.PatchMPIntegrationDefault)
suite.assert.True(ok)
}

func (suite *MarketplaceTestSuite) TestDeleteMPIntegrationHandlerWithError() {
api := &operations.OperatorAPI{}
registerMarketplaceHandlers(api)
params := operator_api.NewDeleteMPIntegrationParams()
params.HTTPRequest = &http.Request{}
response := api.OperatorAPIDeleteMPIntegrationHandler.Handle(params, &models.Principal{})
_, ok := response.(*operator_api.DeleteMPIntegrationDefault)
suite.assert.True(ok)
}

func (suite *MarketplaceTestSuite) TestGetMPEmailWithError() {
testWithError = true
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -176,47 +151,23 @@ func (suite *MarketplaceTestSuite) TestGetMPEmailNoError() {
func (suite *MarketplaceTestSuite) TestSetMPIntegrationNoEmail() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := setMPIntegration(ctx, "", false, &suite.kClient)
err := setMPIntegration(ctx, "", &suite.kClient)
suite.assert.NotNil(err)
}

func (suite *MarketplaceTestSuite) TestSetMPIntegrationWithError() {
testWithError = true
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := setMPIntegration(ctx, "mock@mock.com", false, &suite.kClient)
err := setMPIntegration(ctx, "mock@mock.com", &suite.kClient)
suite.assert.NotNil(err)
}

func (suite *MarketplaceTestSuite) TestSetMPIntegrationNoError() {
testWithError = false
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := setMPIntegration(ctx, "mock@mock.com", false, &suite.kClient)
suite.assert.Nil(err)
}

func (suite *MarketplaceTestSuite) TestSetMPIntegrationOverrideNoError() {
testWithError = false
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := setMPIntegration(ctx, "mock@mock.com", true, &suite.kClient)
suite.assert.Nil(err)
}

func (suite *MarketplaceTestSuite) TestDeleteMPIntegrationWithError() {
testWithError = true
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := deleteMPIntegration(ctx, &suite.kClient)
suite.assert.NotNil(err)
}

func (suite *MarketplaceTestSuite) TestDeleteMPIntegrationNoError() {
testWithError = false
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := deleteMPIntegration(ctx, &suite.kClient)
err := setMPIntegration(ctx, "mock@mock.com", &suite.kClient)
suite.assert.Nil(err)
}

Expand Down
24 changes: 0 additions & 24 deletions operatorapi/operations/operator_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5f7a03

Please sign in to comment.