Implement tctl create -f for devices (#23801)

* Implement `tctl create -f` for devices

* Update e/ reference
This commit is contained in:
Alan Parra
2023-03-31 15:07:58 +00:00
committed by GitHub
parent 5478cde0e6
commit 79d9812a29
2 changed files with 24 additions and 11 deletions
+1 -1
Submodule e updated: 219ed708e4...31c66422be
+23 -10
View File
@@ -784,25 +784,38 @@ func (rc *ResourceCommand) createSAMLIdPServiceProvider(ctx context.Context, cli
}
func (rc *ResourceCommand) createDevice(ctx context.Context, client auth.ClientI, raw services.UnknownResource) error {
if rc.IsForced() {
fmt.Printf("Warning: Devices cannot be overwritten with the --force flag\n")
}
dev, err := device.UnmarshalDevice(raw.Raw)
if err != nil {
return trace.Wrap(err)
}
// TODO(codingllama): Figure out a way to call BulkCreateDevices here?
_, err = client.DevicesClient().CreateDevice(ctx, &devicepb.CreateDeviceRequest{
Device: dev,
CreateAsResource: true,
})
if rc.IsForced() {
_, err = client.DevicesClient().UpsertDevice(ctx, &devicepb.UpsertDeviceRequest{
Device: dev,
CreateAsResource: true,
})
// err checked below
} else {
_, err = client.DevicesClient().CreateDevice(ctx, &devicepb.CreateDeviceRequest{
Device: dev,
CreateAsResource: true,
})
// err checked below
}
if err != nil {
return trail.FromGRPC(err)
}
fmt.Printf("Device %v/%v added to the inventory\n", dev.AssetTag, devicetrust.FriendlyOSType(dev.OsType))
verb := "created"
if rc.IsForced() {
verb = "updated"
}
fmt.Printf("Device %v/%v %v\n",
dev.AssetTag,
devicetrust.FriendlyOSType(dev.OsType),
verb,
)
return nil
}