Skip to content

Commit 3352a3c

Browse files
committed
feat:otp for my_secrets
1 parent afb60e7 commit 3352a3c

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/pybritive/britive_cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,18 +915,20 @@ def configure_tenant(self, tenant, alias, output_format):
915915
def configure_global(self, default_tenant_name, output_format, backend):
916916
self.config.save_global(default_tenant_name=default_tenant_name, output_format=output_format, backend=backend)
917917

918-
def viewsecret(self, path, blocktime, justification, maxpolltime):
918+
def viewsecret(self, path, blocktime, justification, otp, maxpolltime):
919919
self._validate_justification(justification)
920920
self.login()
921921

922922
try:
923923
value = self.b.my_secrets.view(
924-
path=path, justification=justification, wait_time=blocktime, max_wait_time=maxpolltime
924+
path=path, justification=justification, otp=otp, wait_time=blocktime, max_wait_time=maxpolltime
925925
)
926926
except exceptions.AccessDenied as e:
927927
raise click.ClickException('user does not have access to the secret.') from e
928928
except exceptions.ApprovalRequiredButNoJustificationProvided as e:
929929
raise click.ClickException('approval required and no justification provided.') from e
930+
except exceptions.StepUpAuthRequiredButNotProvided as e:
931+
raise click.ClickException('Step Up Authentication required and no OTP provided.') from e
930932

931933
# handle the generic note template type for a better UX
932934
if len(value) == 1 and 'Note' in value:
@@ -943,18 +945,20 @@ def viewsecret(self, path, blocktime, justification, maxpolltime):
943945
# and finally print the secret data
944946
self.print(value, ignore_silent=True)
945947

946-
def downloadsecret(self, path, blocktime, justification, maxpolltime, file):
948+
def downloadsecret(self, path, blocktime, justification, otp, maxpolltime, file):
947949
self._validate_justification(justification)
948950
self.login()
949951

950952
try:
951953
response = self.b.my_secrets.download(
952-
path=path, justification=justification, wait_time=blocktime, max_wait_time=maxpolltime
954+
path=path, justification=justification, otp=otp, wait_time=blocktime, max_wait_time=maxpolltime
953955
)
954956
except exceptions.AccessDenied as e:
955957
raise click.ClickException('user does not have access to the secret.') from e
956958
except exceptions.ApprovalRequiredButNoJustificationProvided as e:
957959
raise click.ClickException('approval required and no justification provided.') from e
960+
except exceptions.StepUpAuthRequiredButNotProvided as e:
961+
raise click.ClickException('Step Up Authentication required and no OTP provided.') from e
958962

959963
filename_from_secret = response['filename']
960964
content = response['content_bytes']

src/pybritive/commands/secret.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ def secret():
1212

1313
@secret.command()
1414
@build_britive
15-
@britive_options(names='blocktime,justification,maxpolltime,format,tenant,token,silent,passphrase,federation_provider')
15+
@britive_options(
16+
names='blocktime,justification,otp,maxpolltime,format,tenant,token,silent,passphrase,federation_provider'
17+
)
1618
@click.argument('path')
1719
def view(
1820
ctx,
1921
blocktime,
2022
justification,
23+
otp,
2124
maxpolltime,
2225
output_format,
2326
tenant,
@@ -35,20 +38,23 @@ def view(
3538
if not path.startswith('/'):
3639
path = f'/{path}'
3740

38-
ctx.obj.britive.viewsecret(path=path, blocktime=blocktime, justification=justification, maxpolltime=maxpolltime)
41+
ctx.obj.britive.viewsecret(
42+
path=path, blocktime=blocktime, justification=justification, otp=otp, maxpolltime=maxpolltime
43+
)
3944

4045

4146
@secret.command()
4247
@build_britive
4348
@britive_options(
44-
names='file,blocktime,justification,maxpolltime,format,silent,tenant,token,' 'passphrase,federation_provider'
49+
names='file,blocktime,justification,otp,maxpolltime,format,silent,tenant,token,passphrase,federation_provider'
4550
)
4651
@click.argument('path')
4752
def download(
4853
ctx,
4954
file,
5055
blocktime,
5156
justification,
57+
otp,
5258
maxpolltime,
5359
output_format,
5460
silent,
@@ -67,5 +73,5 @@ def download(
6773
path = f'/{path}'
6874

6975
ctx.obj.britive.downloadsecret(
70-
path=path, blocktime=blocktime, justification=justification, maxpolltime=maxpolltime, file=file
76+
path=path, blocktime=blocktime, justification=justification, otp=otp, maxpolltime=maxpolltime, file=file
7177
)

src/pybritive/options/justification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
'-j',
66
default=None,
77
show_default=True,
8-
help='Justification for the checkout approval process, if the profile checkout requires approval.',
8+
help='Justification for the approval process, if a profile checkout or secret access requires approval.',
99
)

src/pybritive/options/otp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
'-o',
66
default=None,
77
show_default=False,
8-
help='OTP to checkout a profile, if the profile checkout requires MFA.',
8+
help='OTP to checkout a profile, download a secret, or view a secret, if MFA is required.',
99
)

0 commit comments

Comments
 (0)