Skip to content

Commit d0fcbe5

Browse files
Sophie Wigmoreryanmoran
Sophie Wigmore
authored andcommitted
Add licenses to cargo dependency metadata
1 parent cdad8b1 commit d0fcbe5

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

cargo/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type ConfigMetadataDependency struct {
5050
CPE string `toml:"cpe" json:"cpe,omitempty"`
5151
DeprecationDate *time.Time `toml:"deprecation_date" json:"deprecation_date,omitempty"`
5252
ID string `toml:"id" json:"id,omitempty"`
53+
Licenses []string `toml:"licenses" json:"licenses,omitempty"`
5354
Name string `toml:"name" json:"name,omitempty"`
5455
SHA256 string `toml:"sha256" json:"sha256,omitempty"`
5556
Source string `toml:"source" json:"source,omitempty"`

cargo/config_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func testConfig(t *testing.T, context spec.G, it spec.S) {
6565
CPE: "some-cpe",
6666
DeprecationDate: &deprecationDate,
6767
ID: "some-dependency",
68+
Licenses: []string{"fancy-license", "fancy-license-2"},
6869
Name: "Some Dependency",
6970
SHA256: "shasum",
7071
Source: "source",
@@ -125,6 +126,7 @@ api = "0.2"
125126
cpe = "some-cpe"
126127
deprecation_date = "2020-06-01T00:00:00Z"
127128
id = "some-dependency"
129+
licenses = ["fancy-license", "fancy-license-2"]
128130
name = "Some Dependency"
129131
sha256 = "shasum"
130132
source = "source"
@@ -222,6 +224,7 @@ api = "0.2"
222224
[[metadata.dependencies]]
223225
cpe = "some-cpe"
224226
id = "some-dependency"
227+
licenses = ["fancy-license", "fancy-license-2"]
225228
name = "Some Dependency"
226229
sha256 = "shasum"
227230
source = "source"
@@ -289,6 +292,7 @@ api = "0.2"
289292
{
290293
CPE: "some-cpe",
291294
ID: "some-dependency",
295+
Licenses: []string{"fancy-license", "fancy-license-2"},
292296
Name: "Some Dependency",
293297
SHA256: "shasum",
294298
Source: "source",

cargo/jam/internal/dependency.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ import (
1717
type Dependency struct {
1818
DeprecationDate string `json:"deprecation_date,omitempty"`
1919
// The ID field should be the `name` from the dep-server
20-
ID string `json:"name,omitempty"`
21-
SHA256 string `json:"sha256,omitempty"`
22-
Source string `json:"source,omitempty"`
23-
SourceSHA256 string `json:"source_sha256,omitempty"`
24-
Stacks []Stack `json:"stacks,omitempty"`
25-
URI string `json:"uri,omitempty"`
26-
Version string `json:"version,omitempty"`
27-
CreatedAt string `json:"created_at,omitempty"`
28-
ModifedAt string `json:"modified_at,omitempty"`
29-
CPE string `json:"cpe,omitempty"`
20+
ID string `json:"name,omitempty"`
21+
SHA256 string `json:"sha256,omitempty"`
22+
Source string `json:"source,omitempty"`
23+
SourceSHA256 string `json:"source_sha256,omitempty"`
24+
Stacks []Stack `json:"stacks,omitempty"`
25+
URI string `json:"uri,omitempty"`
26+
Version string `json:"version,omitempty"`
27+
CreatedAt string `json:"created_at,omitempty"`
28+
ModifedAt string `json:"modified_at,omitempty"`
29+
CPE string `json:"cpe,omitempty"`
30+
Licenses []string `json:"licenses,omitempty"`
3031
}
3132

3233
type Stack struct {
@@ -138,5 +139,8 @@ func convertToCargoDependency(dependency Dependency, dependencyName string) carg
138139
for _, stack := range dependency.Stacks {
139140
cargoDependency.Stacks = append(cargoDependency.Stacks, stack.ID)
140141
}
142+
for _, license := range dependency.Licenses {
143+
cargoDependency.Licenses = append(cargoDependency.Licenses, license)
144+
}
141145
return cargoDependency
142146
}

cargo/jam/internal/dependency_test.go

+34-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
3838
CreatedAt: "sometime",
3939
ModifedAt: "another-time",
4040
CPE: "cpe-notation",
41+
Licenses: []string{
42+
"fancy-license",
43+
"fancy-license-2",
44+
},
4145
},
4246
{
4347
DeprecationDate: "",
@@ -55,6 +59,10 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
5559
CreatedAt: "sometime",
5660
ModifedAt: "another-time",
5761
CPE: "cpe-notation",
62+
Licenses: []string{
63+
"fancy-license",
64+
"fancy-license-2",
65+
},
5866
},
5967
{
6068
DeprecationDate: "",
@@ -72,6 +80,10 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
7280
CreatedAt: "sometime",
7381
ModifedAt: "another-time",
7482
CPE: "cpe-notation",
83+
Licenses: []string{
84+
"fancy-license",
85+
"fancy-license-2",
86+
},
7587
},
7688
{
7789
DeprecationDate: "",
@@ -89,6 +101,10 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
89101
CreatedAt: "sometime",
90102
ModifedAt: "another-time",
91103
CPE: "cpe-notation",
104+
Licenses: []string{
105+
"fancy-license",
106+
"fancy-license-2",
107+
},
92108
},
93109
{
94110
DeprecationDate: "",
@@ -106,6 +122,10 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
106122
CreatedAt: "sometime",
107123
ModifedAt: "another-time",
108124
CPE: "cpe-notation",
125+
Licenses: []string{
126+
"fancy-license",
127+
"fancy-license-2",
128+
},
109129
},
110130
}
111131
})
@@ -142,7 +162,8 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
142162
"created_at": "sometime",
143163
"modified_at": "another-time",
144164
"cpe": "cpe-notation",
145-
"deprecation_date" : ""
165+
"deprecation_date": "",
166+
"licenses": ["fancy-license", "fancy-license-2"]
146167
},
147168
{
148169
"name": "some-dep",
@@ -158,7 +179,8 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
158179
"source_sha256": "some-source-sha-two",
159180
"created_at": "sometime",
160181
"modified_at": "another-time",
161-
"cpe": "cpe-notation"
182+
"cpe": "cpe-notation",
183+
"licenses": ["fancy-license", "fancy-license-2"]
162184
},
163185
{
164186
"name": "some-dep",
@@ -174,7 +196,8 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
174196
"source_sha256": "some-source-sha-three",
175197
"created_at": "sometime",
176198
"modified_at": "another-time",
177-
"cpe": "cpe-notation"
199+
"cpe": "cpe-notation",
200+
"licenses": ["fancy-license", "fancy-license-2"]
178201
},
179202
{
180203
"name": "some-dep",
@@ -190,7 +213,8 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
190213
"source_sha256": "some-source-sha-four",
191214
"created_at": "sometime",
192215
"modified_at": "another-time",
193-
"cpe": "cpe-notation"
216+
"cpe": "cpe-notation",
217+
"licenses": ["fancy-license", "fancy-license-2"]
194218
},
195219
{
196220
"name": "different-dep",
@@ -206,7 +230,8 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
206230
"source_sha256": "different-dep-source-sha",
207231
"created_at": "sometime",
208232
"modified_at": "another-time",
209-
"cpe": "cpe-notation"
233+
"cpe": "cpe-notation",
234+
"licenses": ["fancy-license", "fancy-license-2"]
210235
}
211236
]`)
212237
}
@@ -278,6 +303,7 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
278303
{
279304
CPE: "cpe-notation",
280305
ID: "some-dep",
306+
Licenses: []string{"fancy-license", "fancy-license-2"},
281307
Version: "1.0.0",
282308
Stacks: []string{"some-stack"},
283309
URI: "some-dep-uri",
@@ -288,6 +314,7 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
288314
{
289315
CPE: "cpe-notation",
290316
ID: "some-dep",
317+
Licenses: []string{"fancy-license", "fancy-license-2"},
291318
Version: "1.1.2",
292319
Stacks: []string{"some-stack-two"},
293320
URI: "some-dep-uri-two",
@@ -298,6 +325,7 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
298325
{
299326
CPE: "cpe-notation",
300327
ID: "some-dep",
328+
Licenses: []string{"fancy-license", "fancy-license-2"},
301329
Version: "1.5.6",
302330
Stacks: []string{"some-stack-three"},
303331
URI: "some-dep-uri-three",
@@ -347,6 +375,7 @@ func testDependency(t *testing.T, context spec.G, it spec.S) {
347375
CreatedAt: "sometime",
348376
ModifedAt: "another-time",
349377
CPE: "cpe-notation",
378+
Licenses: []string{"fancy-license", "fancy-license-2"},
350379
},
351380
}
352381

cargo/jam/update_dependencies_test.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func testUpdateDependencies(t *testing.T, context spec.G, it spec.S) {
5555
],
5656
"source": "some-source",
5757
"source_sha256": "some-source-sha",
58-
"cpe": "node-cpe"
58+
"cpe": "node-cpe",
59+
"licenses": ["MIT", "MIT-2"]
5960
},
6061
{
6162
"name": "node",
@@ -69,7 +70,8 @@ func testUpdateDependencies(t *testing.T, context spec.G, it spec.S) {
6970
],
7071
"source": "some-source",
7172
"source_sha256": "some-source-sha",
72-
"cpe": "node-cpe"
73+
"cpe": "node-cpe",
74+
"licenses": ["MIT", "MIT-2"]
7375
},
7476
{
7577
"name": "node",
@@ -83,7 +85,8 @@ func testUpdateDependencies(t *testing.T, context spec.G, it spec.S) {
8385
],
8486
"source": "some-source",
8587
"source_sha256": "some-source-sha",
86-
"cpe": "node-cpe"
88+
"cpe": "node-cpe",
89+
"licenses": ["MIT", "MIT-2"]
8790
},
8891
{
8992
"name": "node",
@@ -97,7 +100,8 @@ func testUpdateDependencies(t *testing.T, context spec.G, it spec.S) {
97100
],
98101
"source": "some-source",
99102
"source_sha256": "some-source-sha",
100-
"cpe": "node-cpe"
103+
"cpe": "node-cpe",
104+
"licenses": ["MIT", "MIT-2"]
101105
}]`)
102106
}
103107

@@ -209,6 +213,7 @@ api = "0.2"
209213
[[metadata.dependencies]]
210214
cpe = "node-cpe"
211215
id = "node"
216+
licenses = ["MIT", "MIT-2"]
212217
name = "Node Engine"
213218
sha256 = "some-sha"
214219
source = "some-source"
@@ -220,6 +225,7 @@ api = "0.2"
220225
[[metadata.dependencies]]
221226
cpe = "node-cpe"
222227
id = "node"
228+
licenses = ["MIT", "MIT-2"]
223229
name = "Node Engine"
224230
sha256 = "some-sha"
225231
source = "some-source"
@@ -231,6 +237,7 @@ api = "0.2"
231237
[[metadata.dependencies]]
232238
cpe = "node-cpe"
233239
id = "node"
240+
licenses = ["MIT", "MIT-2"]
234241
name = "Node Engine"
235242
sha256 = "some-sha"
236243
source = "some-source"
@@ -270,6 +277,7 @@ api = "0.2"
270277
[[metadata.dependencies]]
271278
cpe = "node-cpe"
272279
id = "node"
280+
licenses = ["MIT", "MIT-2"]
273281
name = "Node Engine"
274282
sha256 = "some-sha"
275283
source = "some-source"
@@ -323,6 +331,7 @@ api = "0.2"
323331
[[metadata.dependencies]]
324332
cpe = "node-cpe"
325333
id = "node"
334+
licenses = ["MIT", "MIT-2"]
326335
name = "Node Engine"
327336
sha256 = "some-sha"
328337
source = "some-source"
@@ -359,6 +368,7 @@ api = "0.2"
359368
cpe = "node-cpe"
360369
id = "node"
361370
name = "Node Engine"
371+
licenses = ["MIT", "MIT-2"]
362372
sha256 = "some-sha"
363373
source = "some-source"
364374
source_sha256 = "some-source-sha"
@@ -411,6 +421,7 @@ api = "0.2"
411421
[[metadata.dependencies]]
412422
cpe = "node-cpe"
413423
id = "node"
424+
licenses = ["MIT", "MIT-2"]
414425
name = "Node Engine"
415426
sha256 = "some-sha"
416427
source = "some-source"
@@ -500,6 +511,7 @@ api = "0.2"
500511
[[metadata.dependencies]]
501512
cpe = "non-existent-cpe"
502513
id = "non-existent"
514+
licenses = ["MIT", "MIT-2"]
503515
sha256 = "some-sha"
504516
source = "some-source"
505517
source_sha256 = "some-source-sha"

0 commit comments

Comments
 (0)