decodeSecrets decodes secrets from the diff output.
(old, new *manifest.MappingResult)
| 404 | |
| 405 | // decodeSecrets decodes secrets from the diff output. |
| 406 | func decodeSecrets(old, new *manifest.MappingResult) { |
| 407 | if (old != nil && old.Kind != kindSecret) || (new != nil && new.Kind != kindSecret) { |
| 408 | return |
| 409 | } |
| 410 | serializer := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme) |
| 411 | |
| 412 | oldSecret, newSecret, oldSecretDecodeErr, newSecretDecodeErr := preHandleSecrets(old, new) |
| 413 | |
| 414 | if old != nil && oldSecretDecodeErr == nil { |
| 415 | oldSecret.StringData = make(map[string]string, len(oldSecret.Data)) |
| 416 | for k, v := range oldSecret.Data { |
| 417 | oldSecret.StringData[k] = string(v) |
| 418 | } |
| 419 | } |
| 420 | if new != nil && newSecretDecodeErr == nil { |
| 421 | newSecret.StringData = make(map[string]string, len(newSecret.Data)) |
| 422 | for k, v := range newSecret.Data { |
| 423 | newSecret.StringData[k] = string(v) |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | // remove Data field now that we are using StringData for serialization |
| 428 | if old != nil && oldSecretDecodeErr == nil { |
| 429 | oldSecretBuf := bytes.NewBuffer(nil) |
| 430 | oldSecret.Data = nil |
| 431 | if err := serializer.Encode(&oldSecret, oldSecretBuf); err != nil { |
| 432 | new.Content = fmt.Sprintf("Error encoding new secret: %s", err) |
| 433 | } |
| 434 | old.Content = getComment(old.Content) + strings.Replace(oldSecretBuf.String(), " creationTimestamp: null\n", "", 1) |
| 435 | oldSecretBuf.Reset() |
| 436 | } |
| 437 | if new != nil && newSecretDecodeErr == nil { |
| 438 | newSecretBuf := bytes.NewBuffer(nil) |
| 439 | newSecret.Data = nil |
| 440 | if err := serializer.Encode(&newSecret, newSecretBuf); err != nil { |
| 441 | new.Content = fmt.Sprintf("Error encoding new secret: %s", err) |
| 442 | } |
| 443 | new.Content = getComment(new.Content) + strings.Replace(newSecretBuf.String(), " creationTimestamp: null\n", "", 1) |
| 444 | newSecretBuf.Reset() |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // return the first line of a string if its a comment. |
| 449 | // This gives as the # Source: lines from the rendering |