mirror of
https://github.com/paralus/paralus.git
synced 2026-05-06 16:36:46 +00:00
Merge pull request #129 from RafayLabs/hasher-upd
removing references to sensitive hash information
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
runtimeutil "github.com/RafayLabs/rcloud-base/pkg/controller/runtime"
|
||||
"github.com/RafayLabs/rcloud-base/pkg/hasher"
|
||||
|
||||
"github.com/RafayLabs/rcloud-base/pkg/log"
|
||||
controllerv2 "github.com/RafayLabs/rcloud-base/proto/types/controller"
|
||||
@@ -32,31 +31,15 @@ var (
|
||||
var _log = log.GetLogger()
|
||||
|
||||
func getIngressAnnotations(name string, orgID, partnerID string) map[string]string {
|
||||
orgHash, err := hasher.HashFromHex(orgID)
|
||||
if err != nil {
|
||||
orgHash = "unknown"
|
||||
}
|
||||
partnerHash, err := hasher.HashFromHex(partnerID)
|
||||
if err != nil {
|
||||
partnerHash = "unknown"
|
||||
}
|
||||
return map[string]string{
|
||||
ingressAnnotationConfigSnippetKey: fmt.Sprintf("set $workload_name \"%s\";set $orgId \"%s\";set $partnerId \"%s\";", name, orgHash, partnerHash),
|
||||
ingressAnnotationConfigSnippetKey: fmt.Sprintf("set $workload_name \"%s\";set $orgId \"%s\";set $partnerId \"%s\";", name, orgID, partnerID),
|
||||
}
|
||||
}
|
||||
|
||||
func addIngressAnnotations(annotations map[string]string, name string, orgId, partnerId string) {
|
||||
if _, ok := annotations[ingressAnnotationConfigSnippetKey]; !ok {
|
||||
orgHash, err := hasher.HashFromHex(orgId)
|
||||
if err != nil {
|
||||
orgHash = "unknown"
|
||||
}
|
||||
partnerHash, err := hasher.HashFromHex(partnerId)
|
||||
if err != nil {
|
||||
partnerHash = "unknown"
|
||||
}
|
||||
annotations[ingressAnnotationConfigSnippetKey] = fmt.Sprintf("set $workload_name \"%s\";set $orgId \"%s\";set $partnerId \"%s\";",
|
||||
name, orgHash, partnerHash)
|
||||
name, orgId, partnerId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,26 +75,10 @@ func addDebugLabels(stepTemplate *controllerv2.StepTemplate, debugLabels []byte)
|
||||
}
|
||||
|
||||
func getDebugLabelsMap(orgID, partnerID, projectID string, name string, isSystemWorkload bool) (map[string]string, error) {
|
||||
orgHashID, err := hasher.HashFromHex(orgID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to convert org id %s %s", orgID, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
partnerHashID, err := hasher.HashFromHex(partnerID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to convert partner id %s %s", partnerID, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
projectHashID, err := hasher.HashFromHex(projectID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to convert project id %s %s", orgID, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
labels := make(map[string]string)
|
||||
labels["rep-organization"] = orgHashID
|
||||
labels["rep-partner"] = partnerHashID
|
||||
labels["rep-project"] = projectHashID
|
||||
labels["rep-organization"] = orgID
|
||||
labels["rep-partner"] = partnerID
|
||||
labels["rep-project"] = projectID
|
||||
if isSystemWorkload {
|
||||
labels["rep-addon"] = name
|
||||
} else {
|
||||
|
||||
@@ -7,67 +7,16 @@ import (
|
||||
"sort"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/speps/go-hashids"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
k8sapijson "sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/runtime/serializer/json"
|
||||
)
|
||||
|
||||
var hd *hashids.HashID
|
||||
|
||||
const (
|
||||
// ObjectHash is the hash of the object processed by Rafay
|
||||
ObjectHash = "rafay.dev/object-hash"
|
||||
)
|
||||
|
||||
func init() {
|
||||
hd, _ = hashids.NewWithData(&hashids.HashIDData{
|
||||
Alphabet: "abcdefghijklmnopqrstuvwxyz1234567890",
|
||||
Salt: "***REMOVED***",
|
||||
MinLength: 7,
|
||||
})
|
||||
}
|
||||
|
||||
// IDFromString returns new RafayID for hash id string
|
||||
func IDFromString(hashID string) (int64, error) {
|
||||
ids, err := hd.DecodeInt64WithError(hashID)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
if len(ids) < 1 {
|
||||
return -1, fmt.Errorf("no ids could be constructed from string %s", hashID)
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// HashFromInt64 returns new RafayID for hash id string
|
||||
func HashFromInt64(id int64) (string, error) {
|
||||
stringHash, err := hd.EncodeInt64([]int64{id})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return stringHash, nil
|
||||
}
|
||||
|
||||
// HashFromHex returns new Hash for uuid string
|
||||
func HashFromHex(id string) (string, error) {
|
||||
stringHash, err := hd.EncodeHex(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return stringHash, nil
|
||||
}
|
||||
|
||||
// HashFromHex returns new Hash for uuid string
|
||||
func IDFromHash(hash string) (string, error) {
|
||||
id, err := hd.DecodeHex(hash)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
var json = k8sapijson.CaseSensitiveJsonIterator()
|
||||
|
||||
// GetHash returns the hash of spec/data for a kubernetes style object
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package hashid_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/RafayLabs/rcloud-base/pkg/hasher"
|
||||
)
|
||||
|
||||
func TestGetRSID(t *testing.T) {
|
||||
s, e := hasher.HashFromInt64(1)
|
||||
if e != nil || s != "rx28oml" {
|
||||
t.Fatalf("failure")
|
||||
}
|
||||
s, e = hasher.HashFromInt64(140)
|
||||
if e != nil || s != "pkvwv2n" {
|
||||
t.Fatalf("failure")
|
||||
}
|
||||
i, _ := hasher.IDFromString("kgxw87m")
|
||||
fmt.Printf("%d\n", i)
|
||||
}
|
||||
Reference in New Issue
Block a user