Skip to content

Commit ba4c6e1

Browse files
committed
client: Switches to operationMetadataSecrets function
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
1 parent f8fe483 commit ba4c6e1

2 files changed

Lines changed: 9 additions & 75 deletions

File tree

client/lxd_instances.go

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,7 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,
843843

844844
opAPI := op.Get()
845845

846-
targetSecrets := map[string]string{}
847-
for k, v := range opAPI.Metadata {
848-
vStr, ok := v.(string)
849-
if !ok {
850-
continue
851-
}
852-
853-
targetSecrets[k] = vStr
854-
}
846+
targetSecrets := operationMetadataSecrets(opAPI.Metadata)
855847

856848
// Prepare the source request
857849
target := api.InstancePostTarget{}
@@ -876,15 +868,7 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,
876868

877869
opAPI := op.Get()
878870

879-
sourceSecrets := map[string]string{}
880-
for k, v := range opAPI.Metadata {
881-
vStr, ok := v.(string)
882-
if !ok {
883-
continue
884-
}
885-
886-
sourceSecrets[k] = vStr
887-
}
871+
sourceSecrets := operationMetadataSecrets(opAPI.Metadata)
888872

889873
// Relay mode migration
890874
if args != nil && args.Mode == "relay" {
@@ -901,15 +885,7 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,
901885
targetOpAPI := targetOp.Get()
902886

903887
// Extract the websockets
904-
targetSecrets := map[string]string{}
905-
for k, v := range targetOpAPI.Metadata {
906-
vStr, ok := v.(string)
907-
if !ok {
908-
continue
909-
}
910-
911-
targetSecrets[k] = vStr
912-
}
888+
targetSecrets := operationMetadataSecrets(targetOpAPI.Metadata)
913889

914890
// Launch the relay
915891
err = r.proxyMigration(targetOp.(*operation), targetSecrets, source, op.(*operation), sourceSecrets)
@@ -1961,15 +1937,7 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s
19611937

19621938
opAPI := op.Get()
19631939

1964-
targetSecrets := map[string]string{}
1965-
for k, v := range opAPI.Metadata {
1966-
vStr, ok := v.(string)
1967-
if !ok {
1968-
continue
1969-
}
1970-
1971-
targetSecrets[k] = vStr
1972-
}
1940+
targetSecrets := operationMetadataSecrets(opAPI.Metadata)
19731941

19741942
// Prepare the source request
19751943
target := api.InstancePostTarget{}
@@ -1994,15 +1962,7 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s
19941962

19951963
opAPI := op.Get()
19961964

1997-
sourceSecrets := map[string]string{}
1998-
for k, v := range opAPI.Metadata {
1999-
vStr, ok := v.(string)
2000-
if !ok {
2001-
continue
2002-
}
2003-
2004-
sourceSecrets[k] = vStr
2005-
}
1965+
sourceSecrets := operationMetadataSecrets(opAPI.Metadata)
20061966

20071967
// Relay mode migration
20081968
if args != nil && args.Mode == "relay" {
@@ -2019,15 +1979,7 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s
20191979
targetOpAPI := targetOp.Get()
20201980

20211981
// Extract the websockets
2022-
targetSecrets := map[string]string{}
2023-
for k, v := range targetOpAPI.Metadata {
2024-
vStr, ok := v.(string)
2025-
if !ok {
2026-
continue
2027-
}
2028-
2029-
targetSecrets[k] = vStr
2030-
}
1982+
targetSecrets := operationMetadataSecrets(targetOpAPI.Metadata)
20311983

20321984
// Launch the relay
20331985
err = r.proxyMigration(targetOp.(*operation), targetSecrets, source, op.(*operation), sourceSecrets)

client/lxd_storage_volumes.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,7 @@ func (r *ProtocolLXD) CopyStoragePoolVolume(pool string, source InstanceServer,
681681

682682
opAPI := op.Get()
683683

684-
targetSecrets := map[string]string{}
685-
for k, v := range opAPI.Metadata {
686-
value, ok := v.(string)
687-
if ok {
688-
targetSecrets[k] = value
689-
}
690-
}
684+
targetSecrets := operationMetadataSecrets(opAPI.Metadata)
691685

692686
// Prepare the source request
693687
target := api.StorageVolumePostTarget{}
@@ -714,13 +708,7 @@ func (r *ProtocolLXD) CopyStoragePoolVolume(pool string, source InstanceServer,
714708
opAPI := op.Get()
715709

716710
// Prepare source server secrets for remote
717-
sourceSecrets := map[string]string{}
718-
for k, v := range opAPI.Metadata {
719-
value, ok := v.(string)
720-
if ok {
721-
sourceSecrets[k] = value
722-
}
723-
}
711+
sourceSecrets := operationMetadataSecrets(opAPI.Metadata)
724712

725713
// Relay mode migration
726714
if args != nil && args.Mode == "relay" {
@@ -740,13 +728,7 @@ func (r *ProtocolLXD) CopyStoragePoolVolume(pool string, source InstanceServer,
740728
targetOpAPI := targetOp.Get()
741729

742730
// Extract the websockets
743-
targetSecrets := map[string]string{}
744-
for k, v := range targetOpAPI.Metadata {
745-
value, ok := v.(string)
746-
if ok {
747-
targetSecrets[k] = value
748-
}
749-
}
731+
targetSecrets := operationMetadataSecrets(targetOpAPI.Metadata)
750732

751733
// Launch the relay
752734
err = r.proxyMigration(targetOp.(*operation), targetSecrets, source, op.(*operation), sourceSecrets)

0 commit comments

Comments
 (0)