Skip to content

Commit

Permalink
Update unmarshalJSON logic
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhtc1202 committed Jul 25, 2022
1 parent f4ac56a commit a7a4767
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions pkg/config/piped.go
Expand Up @@ -36,9 +36,7 @@ var defaultKubernetesPlatformProvider = PipedPlatformProvider{
}

// PipedSpec contains configurable data used to while running Piped.
type PipedSpec pipedSpec

type pipedSpec struct {
type PipedSpec struct {
// The identifier of the PipeCD project where this piped belongs to.
ProjectID string `json:"projectID"`
// The unique identifier generated for this piped.
Expand Down Expand Up @@ -85,33 +83,19 @@ type pipedSpec struct {
}

func (s *PipedSpec) UnmarshalJSON(data []byte) error {
ps := pipedSpec{}
type Alias PipedSpec
ps := &struct {
*Alias
}{
Alias: (*Alias)(s),
}
if err := json.Unmarshal(data, &ps); err != nil {
return err
}

s.ProjectID = ps.ProjectID
s.PipedID = ps.PipedID
s.PipedKeyFile = ps.PipedKeyFile
s.PipedKeyData = ps.PipedKeyData
s.Name = ps.Name
s.APIAddress = ps.APIAddress
s.WebAddress = ps.WebAddress
s.SyncInterval = ps.SyncInterval
s.AppConfigSyncInterval = ps.AppConfigSyncInterval
s.Git = ps.Git
s.Repositories = ps.Repositories
s.ChartRegistries = ps.ChartRegistries
s.ChartRepositories = ps.ChartRepositories
// Add all CloudProviders configuration as PlatformProviders configuration.
s.PlatformProviders = append(s.PlatformProviders, ps.PlatformProviders...)
s.PlatformProviders = append(s.PlatformProviders, ps.CloudProviders...)
s.AnalysisProviders = ps.AnalysisProviders
s.Notifications = ps.Notifications
s.SecretManagement = ps.SecretManagement
s.EventWatcher = ps.EventWatcher
s.AppSelector = ps.AppSelector

s.CloudProviders = nil
return nil
}

Expand Down

0 comments on commit a7a4767

Please sign in to comment.