@@ -596,6 +596,7 @@ func getImgPostInfo(ctx context.Context, s *state.State, r *http.Request, buildd
596
596
info .Public = util .IsTrue (r .Header .Get ("X-Incus-public" ))
597
597
propHeaders := r .Header [http .CanonicalHeaderKey ("X-Incus-properties" )]
598
598
profilesHeaders := r .Header .Get ("X-Incus-profiles" )
599
+ aliasesHeaders := r .Header .Get ("X-Incus-aliases" )
599
600
ctype , ctypeParams , err := mime .ParseMediaType (r .Header .Get ("Content-Type" ))
600
601
if err != nil {
601
602
ctype = "application/octet-stream"
@@ -781,6 +782,19 @@ func getImgPostInfo(ctx context.Context, s *state.State, r *http.Request, buildd
781
782
}
782
783
}
783
784
785
+ if len (aliasesHeaders ) > 0 {
786
+ info .Aliases = []api.ImageAlias {}
787
+ aliasNames , _ := url .ParseQuery (aliasesHeaders )
788
+
789
+ for _ , aliasName := range aliasNames ["alias" ] {
790
+ alias := api.ImageAlias {
791
+ Name : aliasName ,
792
+ }
793
+
794
+ info .Aliases = append (info .Aliases , alias )
795
+ }
796
+ }
797
+
784
798
var profileIds []int64
785
799
if len (profilesHeaders ) > 0 {
786
800
p , _ := url .ParseQuery (profilesHeaders )
@@ -806,7 +820,6 @@ func getImgPostInfo(ctx context.Context, s *state.State, r *http.Request, buildd
806
820
}
807
821
808
822
var exists bool
809
-
810
823
err = s .DB .Cluster .Transaction (ctx , func (ctx context.Context , tx * db.ClusterTx ) error {
811
824
// Check if the image already exists
812
825
exists , err = tx .ImageExists (ctx , project , info .Fingerprint )
@@ -945,6 +958,13 @@ func imageCreateInPool(s *state.State, info *api.Image, storagePool string) erro
945
958
// schema:
946
959
// type: string
947
960
// - in: header
961
+ // name: X-Incus-aliases
962
+ // description: List of aliases to assign
963
+ // schema:
964
+ // type: array
965
+ // items:
966
+ // type: string
967
+ // - in: header
948
968
// name: X-Incus-properties
949
969
// description: Descriptive properties
950
970
// schema:
@@ -996,7 +1016,6 @@ func imagesPost(d *Daemon, r *http.Request) response.Response {
996
1016
fingerprint := r .Header .Get ("X-Incus-fingerprint" )
997
1017
998
1018
var imageMetadata map [string ]any
999
-
1000
1019
if ! trusted && (secret == "" || fingerprint == "" ) {
1001
1020
return response .Forbidden (nil )
1002
1021
} else {
@@ -1172,9 +1191,18 @@ func imagesPost(d *Daemon, r *http.Request) response.Response {
1172
1191
}
1173
1192
1174
1193
// Apply any provided alias
1175
- aliases , ok := imageMetadata ["aliases" ]
1176
- if ok {
1177
- req .Aliases = aliases .([]api.ImageAlias )
1194
+ if len (req .Aliases ) == 0 {
1195
+ aliases , ok := imageMetadata ["aliases" ]
1196
+ if ok {
1197
+ // Used to get aliases from push mode image copy operation.
1198
+ aliases , ok := aliases .([]api.ImageAlias )
1199
+ if ok {
1200
+ req .Aliases = aliases
1201
+ }
1202
+ } else if len (info .Aliases ) > 0 {
1203
+ // Used to get aliases from HTTP headers on raw image imports.
1204
+ req .Aliases = info .Aliases
1205
+ }
1178
1206
}
1179
1207
1180
1208
err = s .DB .Cluster .Transaction (context .TODO (), func (ctx context.Context , tx * db.ClusterTx ) error {
@@ -1199,7 +1227,7 @@ func imagesPost(d *Daemon, r *http.Request) response.Response {
1199
1227
}
1200
1228
1201
1229
// Add the image alias to the authorizer.
1202
- err = s .Authorizer .AddImageAlias (r . Context () , projectName , alias .Name )
1230
+ err = s .Authorizer .AddImageAlias (ctx , projectName , alias .Name )
1203
1231
if err != nil {
1204
1232
logger .Error ("Failed to add image alias to authorizer" , logger.Ctx {"name" : alias .Name , "project" : projectName , "error" : err })
1205
1233
}
0 commit comments