Skip to content

Commit

Permalink
Do not send raw data in the instance-key due to privacy concerns.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlanigan committed Oct 6, 2021
1 parent 3212461 commit 1990ea5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions charmhub/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package charmhub

import (
"context"
"crypto/sha512"
"encoding/base64"
"fmt"
"net/http"
"strings"
Expand All @@ -14,6 +16,7 @@ import (
"github.com/juju/loggo"
"github.com/juju/utils/v2"
"github.com/kr/pretty"
"golang.org/x/crypto/pbkdf2"

"github.com/juju/juju/charmhub/path"
"github.com/juju/juju/charmhub/transport"
Expand Down Expand Up @@ -200,10 +203,10 @@ func RefreshOne(key, id string, revision int, channel string, base RefreshBase)
// CreateInstanceKey creates an InstanceKey which can be unique and stable
// from Refresh action to Refresh action. Required for KPI collection
// on the charmhub side, see LP:1944582. Rather than saving in
// state, use the model uuid + the app name, which are unique. Modeled
// after the applicationDoc DocID and globalKey in state.
func CreateInstanceKey(uuid, appName string) string {
return uuid + ":a#" + appName
// state, use a hash of the model uuid + the app name, which are unique.
func CreateInstanceKey(appName, uuid string) string {
h := pbkdf2.Key([]byte(appName), []byte(uuid), 8192, 32, sha512.New)
return base64.RawURLEncoding.EncodeToString(h)
}

// Build a refresh request that can be past to the API.
Expand Down

0 comments on commit 1990ea5

Please sign in to comment.