func getAnnotationByKey()

in pre-sync/oci-image-verification/main.go [27:45]


func getAnnotationByKey(raw []byte, key string) (string, error) {
	var metadata map[string]interface{}
	if err := json.Unmarshal(raw, &metadata); err != nil {
		return "", err
	}

	annotations, ok := metadata["metadata"].(map[string]interface{})["annotations"].(map[string]interface{})
	if !ok {
		klog.Infof("No annotations found in the object")
		return "", nil
	}

	if value, found := annotations[key]; found {
		return fmt.Sprintf("%v", value), nil
	}

	klog.Infof("Annotation %s not found in the object", key)
	return "", nil
}