carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package appconfig
2
3import (
4 "context"
5 "crypto/ecdh"
6
7 "github.com/carlosframework/platform/internal/instancekey"
8 "github.com/carlosframework/platform/internal/registry"
9 "github.com/carlosframework/platform/internal/release"
10)
11
12// ConfiguredKeyDigest is the SHA-256 of the CARLOS_INSTANCE_KEY rt's
13// configuration in the bucket renders now, "" when it renders none: the
14// same merge and renderer SyncExec writes <host>.config.env with
15// (LoadMergedHostVersions, RenderEnv), read fresh rather than from the
16// box's last sync. A replica launch whose configured key is not this
17// digest is refused (instance-key plan ruling 27): a configuration change
18// is in flight, and the home may already hold the new key. The value
19// never leaves this function.
20func ConfiguredKeyDigest(ctx context.Context, s release.Store, priv *ecdh.PrivateKey, rt registry.Route) (string, error) {
21 m, _, err := LoadMergedHostVersions(ctx, s, release.RouteAccount(rt), rt.App, rt.Environment, rt.Host)
22 if err != nil || m == nil {
23 return "", err
24 }
25 rendered, err := RenderEnv(m, priv, routeBinding(rt))
26 if err != nil {
27 return "", err
28 }
29 key, _ := instancekey.Effective(instancekey.ParseEnv(rendered), nil)
30 if key == "" {
31 return "", nil
32 }
33 return instancekey.Digest(key), nil
34}
35