Skip to content

Commit f517a71

Browse files
Add authorized_users as one of the required params alongside root_pass and authorized_keys
1 parent 37834a9 commit f517a71

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

linode_api4/groups/linode.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def instance_create(
165165
root_pass: Optional[str] = None,
166166
kernel: Optional[str] = None,
167167
boot_size: Optional[int] = None,
168+
authorized_users: Optional[List[str]] = None,
168169
**kwargs,
169170
):
170171
"""
@@ -175,7 +176,7 @@ def instance_create(
175176
To create an Instance from an :any:`Image`, call `instance_create` with
176177
a :any:`Type`, a :any:`Region`, and an :any:`Image`. All three of
177178
these fields may be provided as either the ID or the appropriate object.
178-
When an Image is provided, at least one of ``root_pass`` or
179+
When an Image is provided, at least one of ``root_pass``, ``authorized_users``, or
179180
``authorized_keys`` must also be given. If ``root_pass`` is provided,
180181
the Instance and the password are returned as a tuple.
181182
@@ -314,6 +315,11 @@ def instance_create(
314315
be a single key, or a path to a file containing
315316
the key.
316317
:type authorized_keys: list or str
318+
:param authorized_users: A list of usernames whose keys should be installed
319+
as trusted for the root user. These user's keys
320+
should already be set up, see :any:`ProfileGroup.ssh_keys`
321+
for details.
322+
:type authorized_users: list[str]
317323
:param label: The display label for the new Instance
318324
:type label: str
319325
:param group: The display group for the new Instance
@@ -366,10 +372,10 @@ def instance_create(
366372
an outdated library.
367373
"""
368374

369-
if image and not root_pass and not authorized_keys:
375+
if image and not root_pass and not authorized_keys and not authorized_users:
370376
raise ValueError(
371377
"When creating an Instance from an Image, at least one of "
372-
"root_pass or authorized_keys must be provided."
378+
"root_pass, authorized_users, or authorized_keys must be provided."
373379
)
374380

375381
params = {
@@ -378,6 +384,7 @@ def instance_create(
378384
"image": image,
379385
"root_pass": root_pass,
380386
"authorized_keys": load_and_validate_keys(authorized_keys),
387+
"authorized_users": authorized_users,
381388
# These will automatically be flattened below
382389
"firewall_id": firewall,
383390
"backup_id": backup,

linode_api4/objects/linode.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def disk_create(
13961396
if creating a disk without an image.
13971397
:param read_only: If True, creates a read-only disk
13981398
:param image: The Image to deploy to the disk. If provided, at least one of
1399-
root_pass or authorized_keys must also be given.
1399+
root_pass, authorized_users or authorized_keys must also be given.
14001400
:param root_pass: The password to configure for the root user when deploying an
14011401
image to this disk. Not used if image is not given. If an
14021402
image is given and root_pass is provided, it will be returned
@@ -1419,10 +1419,10 @@ def disk_create(
14191419
:rtype: Disk or tuple(Disk, str)
14201420
"""
14211421

1422-
if image and not root_pass and not authorized_keys:
1422+
if image and not root_pass and not authorized_keys and not authorized_users:
14231423
raise ValueError(
14241424
"When creating a Disk from an Image, at least one of "
1425-
"root_pass or authorized_keys must be provided."
1425+
"root_pass, authorized_users, or authorized_keys must be provided."
14261426
)
14271427

14281428
authorized_keys = load_and_validate_keys(authorized_keys)
@@ -1586,6 +1586,7 @@ def rebuild(
15861586
disk_encryption: Optional[
15871587
Union[InstanceDiskEncryptionType, str]
15881588
] = None,
1589+
authorized_users: Optional[List[str]] = None,
15891590
**kwargs,
15901591
):
15911592
"""
@@ -1598,24 +1599,29 @@ def rebuild(
15981599
:param image: The Image to deploy to this Instance
15991600
:type image: str or Image
16001601
:param root_pass: The root password for the newly rebuilt Instance. At least
1601-
one of root_pass or authorized_keys must be provided.
1602+
one of root_pass, authorized_users, or authorized_keys must be provided.
16021603
:type root_pass: str
16031604
:param authorized_keys: The ssh public keys to install in the linode's
16041605
/root/.ssh/authorized_keys file. Each entry may
16051606
be a single key, or a path to a file containing
16061607
the key.
16071608
:type authorized_keys: list or str
1609+
:param authorized_users: A list of usernames whose keys should be installed
1610+
as trusted for the root user. These user's keys
1611+
should already be set up, see :any:`ProfileGroup.ssh_keys`
1612+
for details.
1613+
:type authorized_users: list[str]
16081614
:param disk_encryption: The disk encryption policy for this Linode.
16091615
NOTE: Disk encryption may not currently be available to all users.
16101616
:type disk_encryption: InstanceDiskEncryptionType or str
16111617
16121618
:returns: The root_pass if provided, otherwise True.
16131619
:rtype: str or bool
16141620
"""
1615-
if not root_pass and not authorized_keys:
1621+
if not root_pass and not authorized_keys and not authorized_users:
16161622
raise ValueError(
16171623
"When rebuilding an Instance, at least one of "
1618-
"root_pass or authorized_keys must be provided."
1624+
"root_pass, authorized_users, or authorized_keys must be provided."
16191625
)
16201626

16211627
authorized_keys = load_and_validate_keys(authorized_keys)
@@ -1627,6 +1633,7 @@ def rebuild(
16271633
"disk_encryption": (
16281634
str(disk_encryption) if disk_encryption else None
16291635
),
1636+
"authorized_users": authorized_users,
16301637
}
16311638

16321639
params.update(kwargs)

0 commit comments

Comments
 (0)