{cmd,services}/application: Remove JSON hack.
With https://vanadium-review.googlesource.com/8564, the JSON-encoding
hack is no longer needed.
Resolves veyron/release-issues#1233
MultiPart: 2/2
Change-Id: I59414810990b7a3c2540ed659462c1ba12846e27
diff --git a/cmd/application/impl.go b/cmd/application/impl.go
index b22c73b..60b01cc 100644
--- a/cmd/application/impl.go
+++ b/cmd/application/impl.go
@@ -8,71 +8,15 @@
"io/ioutil"
"os"
"os/exec"
- "reflect"
"strings"
"time"
"v.io/v23/context"
- "v.io/v23/security"
"v.io/v23/services/mgmt/application"
- "v.io/v23/vom"
"v.io/x/lib/cmdline"
"v.io/x/ref/services/mgmt/repository"
)
-// TODO(ashankar): application.Envelope is no longer JSON friendly
-// (after https://vanadium-review.googlesource.com/#/c/6300/).
-//
-// This mirrored structure is required in order to work around that
-// problem. Figure out what we want to do.
-type appenv struct {
- Title string
- Args []string
- Binary application.SignedFile
- Publisher security.WireBlessings
- Env []string
- Packages application.Packages
-}
-
-func (a *appenv) Load(env application.Envelope) {
- a.Title = env.Title
- a.Args = env.Args
- a.Binary = env.Binary
- a.Publisher = security.MarshalBlessings(env.Publisher)
- a.Env = env.Env
- a.Packages = env.Packages
-}
-
-func (a *appenv) Store() (application.Envelope, error) {
- // Have to roundtrip through vom to convert from WireBlessings to Blessings.
- // This may seem silly, but this whole appenv type is silly too :).
- // Figure out how to get rid of it.
- bytes, err := vom.Encode(a.Publisher)
- if err != nil {
- return application.Envelope{}, err
- }
- var publisher security.Blessings
- if err := vom.Decode(bytes, &publisher); err != nil {
- return application.Envelope{}, err
- }
- return application.Envelope{
- Title: a.Title,
- Args: a.Args,
- Binary: a.Binary,
- Publisher: publisher,
- Env: a.Env,
- Packages: a.Packages,
- }, nil
-}
-
-func init() {
- // Ensure that no fields have been added to application.Envelope,
- // because if so, then appenv needs to change.
- if n := reflect.TypeOf(application.Envelope{}).NumField(); n != 6 {
- panic(fmt.Sprintf("It appears that fields have been added to or removed from application.Envelope before the hack in this file around json-encodeability was removed. Please also update appenv, appenv.Load and appenv.Store in this file"))
- }
-}
-
func getEnvelopeJSON(app repository.ApplicationClientMethods, profiles string) ([]byte, error) {
ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
@@ -80,9 +24,7 @@
if err != nil {
return nil, err
}
- var appenv appenv
- appenv.Load(env)
- j, err := json.MarshalIndent(appenv, "", " ")
+ j, err := json.MarshalIndent(env, "", " ")
if err != nil {
return nil, fmt.Errorf("MarshalIndent(%v) failed: %v", env, err)
}
@@ -90,14 +32,10 @@
}
func putEnvelopeJSON(app repository.ApplicationClientMethods, profiles string, j []byte) error {
- var appenv appenv
- if err := json.Unmarshal(j, &appenv); err != nil {
+ var env application.Envelope
+ if err := json.Unmarshal(j, &env); err != nil {
return fmt.Errorf("Unmarshal(%v) failed: %v", string(j), err)
}
- env, err := appenv.Store()
- if err != nil {
- return err
- }
ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if err := app.Put(ctx, strings.Split(profiles, ","), env); err != nil {
diff --git a/cmd/application/impl_test.go b/cmd/application/impl_test.go
index f508b40..aa3960f 100644
--- a/cmd/application/impl_test.go
+++ b/cmd/application/impl_test.go
@@ -49,9 +49,7 @@
"S": null
}
},
- "Publisher": {
- "CertificateChains": null
- },
+ "Publisher": "",
"Env": [
"env1",
"env2",
diff --git a/services/mgmt/application/applicationd/applicationd_v23_test.go b/services/mgmt/application/applicationd/applicationd_v23_test.go
index 7c3902f..759ca71 100644
--- a/services/mgmt/application/applicationd/applicationd_v23_test.go
+++ b/services/mgmt/application/applicationd/applicationd_v23_test.go
@@ -6,7 +6,7 @@
"strings"
"v.io/v23/naming"
- "v.io/v23/security"
+ "v.io/v23/services/mgmt/application"
"v.io/x/ref/test/v23tests"
)
@@ -72,38 +72,28 @@
if err != nil {
i.Fatal(err)
}
- sigJSON, err := json.MarshalIndent(sig, " ", " ")
- if err != nil {
- i.Fatal(err)
- }
- pubJSON, err := json.MarshalIndent(security.MarshalBlessings(publisher.Principal().BlessingStore().Default()), " ", " ")
- if err != nil {
- i.Fatal(err)
- }
-
// Create an application envelope.
appRepoSuffix := "test-application/v1"
appEnvelopeFile := i.NewTempFile()
- wantEnvelope := `{
- "Title": "title",
- "Args": null,
- "Binary": {
- "File": "foo",
- "Signature": ` + string(sigJSON) + `
- },
- "Publisher": ` + string(pubJSON) + `,
- "Env": null,
- "Packages": null
-}`
+ wantEnvelope, err := json.MarshalIndent(application.Envelope{
+ Title: "title",
+ Binary: application.SignedFile{
+ File: "foo",
+ Signature: sig,
+ },
+ Publisher: publisher.Principal().BlessingStore().Default(),
+ }, "", " ")
+ if err != nil {
+ i.Fatal(err)
+ }
if _, err := appEnvelopeFile.Write([]byte(wantEnvelope)); err != nil {
i.Fatalf("Write() failed: %v", err)
}
putEnvelope(i, clientBin, appRepoName, appRepoSuffix, appEnvelopeFile.Name())
// Match the application envelope.
- gotEnvelope := matchEnvelope(i, clientBin, false, appRepoName, appRepoSuffix)
- if gotEnvelope != wantEnvelope {
- i.Fatalf("unexpected output: got %v, want %v", gotEnvelope, wantEnvelope)
+ if got, want := matchEnvelope(i, clientBin, false, appRepoName, appRepoSuffix), string(wantEnvelope); got != want {
+ i.Fatalf("unexpected output: got %v, want %v", got, want)
}
// Remove the application envelope.