mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-24 16:17:11 +08:00
Implement tctl create -f for devices (#23801)
* Implement `tctl create -f` for devices * Update e/ reference
This commit is contained in:
+1
-1
Submodule e updated: 219ed708e4...31c66422be
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user