Skip to content

Commit 2d79348

Browse files
authored
Merge pull request #145 from britive/develop
v1.7.0rc3
2 parents bc7ca00 + 61060e1 commit 2d79348

File tree

12 files changed

+184
-33
lines changed

12 files changed

+184
-33
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ site/
1212
lock-test.py
1313
test.py
1414

15+
# IDE
16+
.vscode/
17+
1518
# C extensions
1619
*.so
1720

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
* As of v1.4.0 release candidates will be published in an effort to get new features out faster while still allowing time for full QA testing before moving the release candidate to a full release.
44

5+
## v1.7.0rc3 [2024-04-03]
6+
#### What's New
7+
* Support for OpenShift checkout modes `os-oclogin` and `os-ocloginexec`. These checkout modes will perform the OIDC authorization code grant flow and extraction of the `oc login` command in code vs. having to use the browser. It is a "best effort" approach as the OpenShift login pages and programmatic access pages could change over time.
8+
9+
#### Enhancements
10+
* Adds 3 part profile name for command `ls profiles -f json` - [#141](https://github.com/britive/python-cli/issues/141)
11+
12+
#### Bug Fixes
13+
* Fixes issue with `--force-renew` on `checkout` not providing the `--console` flag properly to `checkin`
14+
* Flag `-p` was being used by `--maxpolltime` and `--passphrase` for command `checkout`. Switched `--maxpolltime` to `-x`.
15+
16+
#### Dependencies
17+
* `britive>=2.24.0rc5`
18+
* Removal of `pkg_resources` dependency
19+
20+
#### Other
21+
* Documentation updates for `--federation-provider` and `spacelift`
22+
* Documentation update for Azure Managed Identities
23+
* Introduction of `__version__` in `__init.py__`
24+
* Re-enabling the system banner/announcement logic
25+
526
## v1.7.0rc2 [2024-01-19]
627
#### What's New
728
* None
829

930
#### Enhancements
1031
* None
32+
1133
#### Bug Fixes
1234
* Remove the banner logic as the banner api is not yet available in production
1335

TECH_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pip install --editable .
66

77
## Build
88

9-
* Update version in `setup.cfg`
9+
* Update version in `setup.cfg` and `src/pybritive/__init__.py` (TODO: create some pre-build script that will update one of these automatically)
1010
* Push code to GitHub
1111
* Cut a new PR and merge when appropriate
1212
* Run below commands

docs/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ order of operations for determining the tenant.
7575
4. If none of the above are available then check for configured tenants in `~/.britive/pybritive.config` and if there is only 1 tenant configured use it
7676
5. If all the above fail then error
7777

78-
7978
## Credential Selection Logic
8079

8180
There are numerous ways to provide the CLI with the Britive credentials that should be used to authenticate to the
@@ -124,7 +123,6 @@ Any of the above values in the `Environment Name` position will be accepted.
124123

125124
When running `ls profiles -f list` and `cache profiles`, the `environmentName` field will be shown.
126125

127-
128126
## Workload Federation Providers
129127

130128
*NOTE*: Before any of the below will work there is required setup and configuration within your Britive tenant
@@ -146,10 +144,9 @@ At feature launch the following types of identity providers are supported for wo
146144
* Bitbucket
147145
* Azure System Assigned Managed Identities
148146
* Azure User Assigned Managed Identities
147+
* Spacelift.io
149148

150-
For more information on Azure Managed Identities reference the below link.
151-
152-
https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
149+
For more information on [Azure Managed Identities reference](https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview 'Link to Microsoft Documentaion')
153150

154151
It is possible to source an identity token from a different OIDC provider and explicitly set it via the `--token\-T` flag.
155152
However, if you are using one of the above providers, a shortcut is provided to abstract away the complexity of sourcing these tokens.
@@ -176,6 +173,9 @@ pybritive checkout "profile" --federation-provider aws_expirationseconds # use
176173
# bitbucket (note that no additional options are available for bitbucket)
177174
pybritive checkout "profile" --federation-provider bitbucket
178175

176+
# spacelift.io (note that no additional options are available for spacelift.io)
177+
pybritive checkout "profile" --federation-provider spacelift
178+
179179
# azure system assigned managed identities
180180
pybritive checkout "profile" --federation-provider azuresmi # use system assigned managed identities with the default OIDC audience
181181
pybritive checkout "profile" --federation-provider azuresmi-audience # use system assigned managed identities with a custom OIDC audience
@@ -207,15 +207,13 @@ The user will be prompted for a passphrase to use to encrypt the file. The user
207207
via flag `--passphrase/-p` or via environment variable `PYBRITIVE_ENCRYPTED_CREDENTIAL_PASSPHRASE`. If no passphrase is
208208
provided `pybritive` will use an internally generated passphrase unique to the machine on which the application is running.
209209

210-
211210
## Home Directory
212211
By default, files that `pybritive` requires will be persisted to `~/.britive/`.
213212

214213
This can be overwritten by specifying environment variable `PYBRITIVE_HOME_DIR`. This can be either one of the following choices to where
215214
the end user wants to persist the `.britive` directory. Note that `.britive` will still be created so do not specify
216215
that as part of the path.
217216

218-
219217
## Browser
220218
By default, `pybritive` will use the OS defined default for any actions that have browser interaction(s).
221219

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
boto3
2-
britive>=2.24.0rc1
2+
britive>=2.24.0rc5
33
certifi>=2022.12.7
44
charset-normalizer==2.1.0
55
click~=8.1.3
@@ -21,3 +21,4 @@ toml==0.10.2
2121
twine~=4.0.1
2222
urllib3>=1.26.17; urllib3 == 1
2323
urllib3>=2.0.6; urllib3 == 2
24+
beautifulsoup4~=4.12.0

setup.cfg

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 1.7.0rc2
3+
version = 1.7.0rc3
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive
@@ -27,7 +27,7 @@ install_requires =
2727
toml
2828
cryptography>=41.0.0
2929
python-dateutil
30-
britive>=2.24.0rc1
30+
britive>=2.24.0rc5
3131
jmespath
3232
pyjwt
3333

@@ -38,4 +38,10 @@ where = src
3838
console_scripts =
3939
pybritive = pybritive.cli_interface:safe_cli
4040
pybritive-aws-cred-process = pybritive.helpers.aws_credential_process:main
41-
pybritive-kube-exec = pybritive.helpers.k8s_exec:main
41+
pybritive-kube-exec = pybritive.helpers.k8s_exec:main
42+
43+
[options.extras_require]
44+
openshift =
45+
beautifulsoup4
46+
aws =
47+
boto3

src/pybritive/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.7.0rc3'

src/pybritive/britive_cli.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pathlib import Path
1111
import sys
1212
import uuid
13-
import pkg_resources
1413
import yaml
1514
import click
1615
import jmespath
@@ -169,8 +168,7 @@ def login(self, explicit: bool = False, browser: str = None):
169168
if explicit and should_get_profiles:
170169
self._set_available_profiles() # will handle calling cache_profiles() and construct_kube_config()
171170

172-
# handle printing the banner - commenting out until the banner api is released into production
173-
# self._display_banner()
171+
self._display_banner()
174172

175173
def _display_banner(self):
176174
if self.silent:
@@ -190,7 +188,8 @@ def _update_sdk_user_agent(self):
190188
user_agent = self.b.session.headers.get('User-Agent')
191189

192190
try:
193-
version = pkg_resources.get_distribution('pybritive').version
191+
import pybritive
192+
version = pybritive.__version__
194193
except Exception:
195194
version = 'unknown'
196195

@@ -400,6 +399,9 @@ def list_profiles(self, checked_out: bool = False):
400399
row.pop('Expiration', None)
401400
if profile['2_part_profile_format_allowed']:
402401
row.pop('Environment', None)
402+
elif self.output_format == 'json':
403+
row['Name'] = f"{row['Application']}/{row['Environment']}/{row['Profile']}"
404+
403405
data.append(row)
404406

405407
# set special list output if needed
@@ -564,6 +566,15 @@ def __get_cloud_credential_printer(self, app_type, console, mode, profile, silen
564566
cli=self,
565567
k8s_processor=k8s_processor
566568
)
569+
elif app_type in ['OpenShift']:
570+
return printer.OpenShiftCredentialPrinter(
571+
console=console,
572+
mode=mode,
573+
profile=profile,
574+
credentials=credentials,
575+
silent=silent,
576+
cli=self
577+
)
567578
else:
568579
return printer.GenericCloudCredentialPrinter(
569580
console=console,
@@ -696,9 +707,9 @@ def checkout(self, alias, blocktime, console, justification, mode, maxpolltime,
696707
from .helpers.k8s_exec_credential_builder import KubernetesExecCredentialProcessor
697708
k8s_processor = KubernetesExecCredentialProcessor()
698709

699-
# these 2 modes implicitly say that console access should be checked out without having to provide
710+
# these 3 modes implicitly say that console access should be checked out without having to provide
700711
# the --console flag
701-
if mode and (mode == 'console' or mode.startswith('browser')):
712+
if mode and (mode == 'console' or mode.startswith('browser') or mode.startswith('os-')):
702713
console = True
703714
if mode.startswith('browser'):
704715
self.browser = mode.replace('browser-', '')
@@ -751,7 +762,7 @@ def checkout(self, alias, blocktime, console, justification, mode, maxpolltime,
751762
diff = (expiration - now).total_seconds() / 60.0
752763
if diff < force_renew: # time to checkin the profile so we can refresh creds
753764
self.print('checking in the profile to get renewed credentials....standby')
754-
self.checkin(profile=profile)
765+
self.checkin(profile=profile, console=console)
755766
response = self._checkout(**params)
756767
cached_credentials_found = False # need to write new creds to cache
757768
credentials = response['credentials']
@@ -1224,13 +1235,16 @@ def _ssh_generate_key(self, username, hostname, key_source):
12241235
'key_pair': key_pair
12251236
}
12261237

1238+
@staticmethod
1239+
def build_import_exception_message(extras: str):
1240+
return f'required packages not found. run `pip3 install pybritive[{extras}]`'
1241+
12271242
@staticmethod
12281243
def _ssh_aws_push_key(aws_profile, aws_region, instance_id, username, key_pair):
12291244
try:
12301245
import boto3
12311246
except ImportError as e:
1232-
message = 'boto3 package is required. Please ensure the package is installed.'
1233-
raise click.ClickException(message) from e
1247+
raise click.ClickException(BritiveCli.build_import_exception_message('aws')) from e
12341248

12351249
# we know we will be pushing the key to the instance so establish the
12361250
# boto3 clients which are required to perform those actions
@@ -1288,8 +1302,7 @@ def aws_console(profile, duration, browser):
12881302
try:
12891303
import boto3
12901304
except ImportError as e:
1291-
message = 'boto3 package is required. Please ensure the package is installed.'
1292-
raise click.ClickException(message) from e
1305+
raise click.ClickException(BritiveCli.build_import_exception_message('aws')) from e
12931306

12941307
creds = boto3.Session(profile_name=profile).get_credentials()
12951308
session_id = creds.access_key

src/pybritive/choices/mode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
'browser-chromium',
2727
'kube-exec', # bake into kubeconfig with oidc exec output and additional caching to make kubectl more performant
2828
'gcloudauthexec', # will effectively execute results of gcloudauth in a sub-shell
29+
'os-oclogin', # will attempt an oidc authorization code grant flow for generating the `oc login ...` command for OpenShift
30+
'os-ocloginexec', # will attempt an oidc authorization code grant flow for generating the `oc login ...` command for OpenShift and exec the result in a subshell
2931
],
3032
case_sensitive=False
3133
)

0 commit comments

Comments
 (0)