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 12:07:58 -03:00 committed by GitHub
parent 5478cde0e6
commit 79d9812a29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

2
e

@ -1 +1 @@
Subproject commit 219ed708e460ac6f04025fab33861839168d7262
Subproject commit 31c66422be08b3931ec03359e0db5d4cb256705f

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
}