MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / UpdateLogSource

Method UpdateLogSource

service/log/iml.go:125–176  ·  view source on GitHub ↗
(ctx context.Context, driver string, input *Save)

Source from the content-addressed store, hash-verified

123}
124
125func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, input *Save) error {
126 s, err := i.store.First(ctx, map[string]interface{}{"driver": driver})
127 if err != nil {
128 if !errors.Is(err, gorm.ErrRecordNotFound) {
129 return err
130 }
131 if input.ID == "" {
132 input.ID = uuid.NewString()
133 }
134 if input.Cluster == nil || *input.Cluster == "" {
135 return errors.New("cluster is required")
136 }
137 if input.Config == nil || *input.Config == "" {
138 return errors.New("config is required")
139 }
140
141 now := time.Now()
142 userId := utils.UserId(ctx)
143 s = &log_source.LogSource{
144 UUID: input.ID,
145 Cluster: *input.Cluster,
146 Driver: driver,
147 Config: *input.Config,
148 Creator: userId,
149 Updater: userId,
150 CreateAt: now,
151 UpdateAt: now,
152 }
153 if input.LastPullTime == nil {
154 s.LastPullAt = time.Now().Add(-24 * time.Hour)
155 } else {
156 s.LastPullAt = *input.LastPullTime
157 }
158
159 } else {
160 if input.Config != nil && *input.Config != "" {
161 s.Config = *input.Config
162 }
163 if input.LastPullTime != nil {
164 s.LastPullAt = *input.LastPullTime
165 }
166 s.Updater = utils.UserId(ctx)
167 s.UpdateAt = time.Now()
168 }
169
170 err = i.store.Save(ctx, s)
171 if err != nil {
172 return err
173 }
174
175 return nil
176}
177
178func (i *imlLogService) GetLogSource(ctx context.Context, driver string) (*Source, error) {
179 s, err := i.store.First(ctx, map[string]interface{}{"driver": driver})

Callers

nothing calls this directly

Calls 1

SaveMethod · 0.65

Tested by

no test coverage detected