Skip to content

Commit

Permalink
Merge pull request #411 from harness/SRM-15418-2
Browse files Browse the repository at this point in the history
[fix]: [SRM-15418]: Add type support for dependency in Monitored Services
  • Loading branch information
deepak-harness committed Oct 9, 2023
2 parents a610f1a + cc4442c commit 7fd41e2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 13 deletions.
16 changes: 10 additions & 6 deletions harness/nextgen/api_srm_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ SaveSrmNotification saves srm notification data
@return NotificationRuleResponse
*/
func (a *SrmNotificationApiService) SaveSrmNotification(ctx context.Context, accountId string, localVarOptionals *SrmNotificationServiceSaveSrmNotificationOpts) (NotificationRuleResponse, *http.Response, error) {
func (a *SrmNotificationApiService) SaveSrmNotification(ctx context.Context, accountId string, localVarOptionals *SrmNotificationServiceSaveSrmNotificationOpts) (RestResponseSrmNotificationResponse, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Post")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue NotificationRuleResponse
localVarReturnValue RestResponseSrmNotificationResponse
)

// create path and map variables
Expand Down Expand Up @@ -153,13 +153,13 @@ GetSrmNotification get srm notirication data
@return NotificationRuleResponse
*/
func (a *SrmNotificationApiService) GetSrmNotification(ctx context.Context, identifier string, accountId string, orgIdentifier string, projectIdentifier string) (NotificationRuleResponse, *http.Response, error) {
func (a *SrmNotificationApiService) GetSrmNotification(ctx context.Context, identifier string, accountId string, orgIdentifier string, projectIdentifier string) (RestResponseSrmNotificationResponse, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Get")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue NotificationRuleResponse
localVarReturnValue RestResponseSrmNotificationResponse
)

// create path and map variables
Expand Down Expand Up @@ -254,19 +254,21 @@ func (a *SrmNotificationApiService) GetSrmNotification(ctx context.Context, iden
UpdateSrmNotification updates srm notification data
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param accountId
- @param orgIdentifier
- @param projectIdentifier
- @param identifier
- @param optional nil or *SrmNotificationApiUpdateSrmNotificationOpts - Optional Parameters:
- @param "Body" (optional.Interface of NotificationRule) -
@return NotificationRuleResponse
*/
func (a *SrmNotificationApiService) UpdateSrmNotification(ctx context.Context, accountId string, identifier string, localVarOptionals *SrmNotificationApiUpdateSrmNotificationOpts) (NotificationRuleResponse, *http.Response, error) {
func (a *SrmNotificationApiService) UpdateSrmNotification(ctx context.Context, accountId string, orgIdentifier string, projectIdentifier string, identifier string, localVarOptionals *SrmNotificationApiUpdateSrmNotificationOpts) (RestResponseSrmNotificationResponse, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Put")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue NotificationRuleResponse
localVarReturnValue RestResponseSrmNotificationResponse
)

// create path and map variables
Expand All @@ -280,6 +282,8 @@ func (a *SrmNotificationApiService) UpdateSrmNotification(ctx context.Context, a
localVarHeaderParams["Harness-Account"] = a.client.cfg.AccountId

localVarQueryParams.Add("accountId", parameterToString(accountId, ""))
localVarQueryParams.Add("orgIdentifier", parameterToString(orgIdentifier, ""))
localVarQueryParams.Add("projectIdentifier", parameterToString(projectIdentifier, ""))
// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json"}

Expand Down
1 change: 1 addition & 0 deletions harness/nextgen/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
c.ServicesApi = (*ServicesApiService)(&c.common)
c.ServiceOverridesApi = (*ServiceOverridesApiService)(&c.common)
c.SloApi = (*SloApiService)(&c.common)
c.SrmNotificationApiService = (*SrmNotificationApiService)(&c.common)
c.SourceCodeManagerApi = (*SourceCodeManagerApiService)(&c.common)
c.TargetGroupsApi = (*TargetGroupsApiService)(&c.common)
c.TargetsApi = (*TargetsApiService)(&c.common)
Expand Down
3 changes: 1 addition & 2 deletions harness/nextgen/model_kubernetes_dependency_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package nextgen

type KubernetesDependencyMetadata struct {
Type_ string `json:"type"`
Namespace string `json:"namespace"`
Workload string `json:"workload"`
Workload string `json:"workload"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/
package nextgen

type ServiceDependencyMetadata struct {
Type_ DependencyMetadataType `json:"type,omitempty"`
KUBERNETES *KubernetesDependencyMetadata `json:"-"`
type RestResponseSrmNotificationResponse struct {
MetaData map[string]interface{} `json:"metaData,omitempty"`
Resource *NotificationRuleResponse `json:"resource,omitempty"`
ResponseMessages []ResponseMessage `json:"responseMessages,omitempty"`
}
10 changes: 8 additions & 2 deletions harness/nextgen/model_service_dependency_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
*/
package nextgen

import "encoding/json"

type ServiceDependencyDto struct {
MonitoredServiceIdentifier string `json:"monitoredServiceIdentifier,omitempty"`
DependencyMetadata *ServiceDependencyMetadata `json:"dependencyMetadata,omitempty"`
MonitoredServiceIdentifier string `json:"monitoredServiceIdentifier,omitempty"`

Type_ DependencyMetadataType `json:"type,omitempty"`
KUBERNETES *KubernetesDependencyMetadata `json:"-"`

DependencyMetadata json.RawMessage `json:"dependencyMetadata"`
}
53 changes: 53 additions & 0 deletions harness/nextgen/model_service_dependency_dto_serializer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package nextgen

import (
"encoding/json"
"fmt"
)

func (a *ServiceDependencyDto) UnmarshalJSON(data []byte) error {

type Alias ServiceDependencyDto

aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}

switch a.Type_ {
case DependencyMetadataTypes.KUBERNETES:
err = json.Unmarshal(aux.DependencyMetadata, &a.KUBERNETES)
default:
panic(fmt.Sprintf("unknown dependency metadata type %s", a.Type_))
}

return err
}

func (a *ServiceDependencyDto) MarshalJSON() ([]byte, error) {
type Alias ServiceDependencyDto

var dependencyMetadata []byte
var err error

switch a.Type_ {
case DependencyMetadataTypes.KUBERNETES:
dependencyMetadata, err = json.Marshal(a.KUBERNETES)
default:
panic(fmt.Sprintf("unknown dependency metadata type %s", a.Type_))
}

if err != nil {
return nil, err
}

a.DependencyMetadata = dependencyMetadata

return json.Marshal((*Alias)(a))
}

0 comments on commit 7fd41e2

Please sign in to comment.