@@ -17,13 +17,12 @@ limitations under the License.
1717package projection
1818
1919import (
20- "crypto/sha1"
21- "encoding/hex"
2220 "fmt"
2321 "strings"
2422
2523 "github.com/kcp-dev/logicalcluster/v3"
2624
25+ "github.com/kcp-dev/api-syncagent/internal/crypto"
2726 syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
2827
2928 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -44,9 +43,9 @@ func GenerateLocalObjectName(pr *syncagentv1alpha1.PublishedResource, object met
4443 replacer := strings .NewReplacer (
4544 // order of elements is important here, "$fooHash" needs to be defined before "$foo"
4645 syncagentv1alpha1 .PlaceholderRemoteClusterName , clusterName .String (),
47- syncagentv1alpha1 .PlaceholderRemoteNamespaceHash , shortSha1Hash (object .GetNamespace ()),
46+ syncagentv1alpha1 .PlaceholderRemoteNamespaceHash , crypto . ShortHash (object .GetNamespace ()),
4847 syncagentv1alpha1 .PlaceholderRemoteNamespace , object .GetNamespace (),
49- syncagentv1alpha1 .PlaceholderRemoteNameHash , shortSha1Hash (object .GetName ()),
48+ syncagentv1alpha1 .PlaceholderRemoteNameHash , crypto . ShortHash (object .GetName ()),
5049 syncagentv1alpha1 .PlaceholderRemoteName , object .GetName (),
5150 )
5251
@@ -68,17 +67,3 @@ func GenerateLocalObjectName(pr *syncagentv1alpha1.PublishedResource, object met
6867
6968 return result
7069}
71-
72- func shortSha1Hash (value string ) string {
73- hash := sha1 .New ()
74- if _ , err := hash .Write ([]byte (value )); err != nil {
75- // This is not something that should ever happen at runtime and is also not
76- // something we can really gracefully handle, so crashing and restarting might
77- // be a good way to signal the service owner that something is up.
78- panic (fmt .Sprintf ("Failed to hash string: %v" , err ))
79- }
80-
81- encoded := hex .EncodeToString (hash .Sum (nil ))
82-
83- return encoded [:20 ]
84- }
0 commit comments