@@ -2,6 +2,7 @@ package cli
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"fmt"
6
7
"os"
7
8
"path/filepath"
@@ -12,6 +13,7 @@ import (
12
13
13
14
"cdr.dev/slog"
14
15
"cdr.dev/slog/sloggers/sloghuman"
16
+ "github.com/coder/code-marketplace/internal/extensionsign"
15
17
16
18
"github.com/coder/code-marketplace/storage"
17
19
"github.com/coder/code-marketplace/util"
@@ -22,6 +24,7 @@ func add() *cobra.Command {
22
24
artifactory string
23
25
extdir string
24
26
repo string
27
+ signature bool
25
28
)
26
29
27
30
cmd := & cobra.Command {
@@ -73,7 +76,7 @@ func add() *cobra.Command {
73
76
return err
74
77
}
75
78
for _ , file := range files {
76
- s , err := doAdd (ctx , filepath .Join (args [0 ], file .Name ()), store )
79
+ s , err := doAdd (ctx , filepath .Join (args [0 ], file .Name ()), signature , store )
77
80
if err != nil {
78
81
_ , _ = fmt .Fprintf (cmd .OutOrStdout (), "Failed to unpack %s: %s\n " , file .Name (), err .Error ())
79
82
failed = append (failed , file .Name ())
@@ -82,7 +85,7 @@ func add() *cobra.Command {
82
85
}
83
86
}
84
87
} else {
85
- s , err := doAdd (ctx , args [0 ], store )
88
+ s , err := doAdd (ctx , args [0 ], signature , store )
86
89
if err != nil {
87
90
return err
88
91
}
@@ -102,11 +105,12 @@ func add() *cobra.Command {
102
105
cmd .Flags ().StringVar (& extdir , "extensions-dir" , "" , "The path to extensions." )
103
106
cmd .Flags ().StringVar (& artifactory , "artifactory" , "" , "Artifactory server URL." )
104
107
cmd .Flags ().StringVar (& repo , "repo" , "" , "Artifactory repository." )
108
+ cmd .Flags ().BoolVar (& signature , "signature" , true , "Include signature" )
105
109
106
110
return cmd
107
111
}
108
112
109
- func doAdd (ctx context.Context , source string , store storage.Storage ) ([]string , error ) {
113
+ func doAdd (ctx context.Context , source string , includeSignature bool , store storage.Storage ) ([]string , error ) {
110
114
// Read in the extension. In the future we might support stdin as well.
111
115
vsix , err := storage .ReadVSIX (ctx , source )
112
116
if err != nil {
@@ -120,7 +124,31 @@ func doAdd(ctx context.Context, source string, store storage.Storage) ([]string,
120
124
return nil , err
121
125
}
122
126
123
- location , err := store .AddExtension (ctx , manifest , vsix )
127
+ var extra []storage.File
128
+ if includeSignature {
129
+ sigManifest , err := extensionsign .GenerateSignatureManifest (vsix )
130
+ if err != nil {
131
+ return nil , xerrors .Errorf ("generate signature manifest: %w" , err )
132
+ }
133
+
134
+ data , err := json .Marshal (sigManifest )
135
+ if err != nil {
136
+ return nil , xerrors .Errorf ("marshal signature manifest: %w" , err )
137
+ }
138
+
139
+ extra = append (extra , storage.File {
140
+ RelativePath : "extension.sigzip" ,
141
+ Content : data ,
142
+ })
143
+
144
+ manifest .Assets .Asset = append (manifest .Assets .Asset , storage.VSIXAsset {
145
+ Type : storage .VSIXSignatureType ,
146
+ Path : "extension.sigzip" ,
147
+ Addressable : "true" , // TODO: Idk if this is right
148
+ })
149
+ }
150
+
151
+ location , err := store .AddExtension (ctx , manifest , vsix , extra ... )
124
152
if err != nil {
125
153
return nil , err
126
154
}
0 commit comments