Package: britive
Britive Python SDKPure Python implementation for interacting with the Britive API.This package aims to wrap the Britive API for use in Python. For the most part it is a simple wrapper (sending
potentially bad parameters to the API) but there are a couple of places where liberties were taken to enhance
the developer/end user experience. Some APIs may also be combined into one Python method with a parameter if and
where it makes more sense to present the API that way.This package supports Python 3.7 and higher.InstallationpipinstallbritiveOr execute one of the following commands if you wish to pull directly from the Github repo instead of PyPi.
Or navigate to Releases and use the URL of the tarball release that is needed, if not the lastest.pipinstall$(curl-shttps://api.github.com/repos/britive/python-sdk/releases/latest|jq-r'.assets[] | select(.content_type == "application/x-gzip") | .browser_download_url')OR

pipinstall$(curl-shttps://api.github.com/repos/britive/python-sdk/releases/latest|grep"browser_download_url.*.tar.gz"|cut-d:-f2,3|tr-d\")DocumentationEach public method is documented with a docstring which provides details on what the method does, the parameters the
method accepts, and details about what is returned from the method.Official API documentation can be found athttps://docs.britive.com/v1/docs/en/overview-britive-apis.AuthenticationAuthentication is handled solely via API tokens. The token must be provided in one of two methods.Passed directly into the class constructor.Injected as an environment variable into the execution context where this package is being run. The
environment variable name must be BRITIVE_API_TOKEN.As of v2.5.0 aBearertoken can be provided as well. ABearertoken is generated as part of an interactive
login process and is temporary in nature. This change is to allow for an upcoming Python CLI application.All Britive API tokens are authenticated against a specific Britive tenant. The name of the tenant must be presented
in one of two methods.Passed directly into theBritiveclass constructor.Injected as an environment variable into the execution context where this package is being run. The
environment variable name must beBRITIVE_TENANT.In order to obtain the tenant name, reference the Britive URL used to log into the UI. If the URL ishttps://example.britive-app.comthen the tenant name will beexample.PaginationAll pagination is handled by the package. The caller will never have to deal with paginated responses.AssumptionsThe caller has access to an active Britive tenant.The caller has been granted an API token and/or has the ability to generate an API token. This can be either for
a User or Service Identity.No assumptions are made about the operating system or file system. Nothing is persisted to disk. The end user
must persist responses to disk if and when that is required.Resource CoverageThe following Britive resources are supported with full CRUDL operations where appropriate, and additional actions
where they exist.AccountsAPI Tokens (for Users)ApplicationsAudit LogsEnvironment GroupsEnvironmentGroups (associated with an application/environment)Accounts (associated with an application/environment)Permissions (associated with an application/environment)Identity AttributesIdentity ProvidersMy Access (access granted to the given identity (user or service))My Secrets (access granted to the given identity (user or service))NotificationsProfilesReportsSAML SettingsScansSecurity PoliciesService IdentitiesService Identity TokensTags (aka User Tags)Task ServicesTasksUsersProxiesUnder the covers, pythonrequestsis being used to communicate with the Britive API. As such, any functionality
ofrequestscan be used, including setting an HTTP proxy. HTTP proxies will be set via environment variables.HTTP_PROXYHTTPS_PROXYNO_PROXYhttp_proxyhttps_proxyno_proxyStandard HTTP proxy URLs should be utilized. Examples below.Unauthenticated Proxy:http://internalproxy.domain.com:8080Authenticated Proxy:http://user:pass@internalproxy.domain.com:8080Custom TLS CertificatesUnder the covers, pythonrequestsis being used to communicate with the Britive API. As such, any functionality
ofrequestscan be used, including setting custom TLS certificates. Certificate bundles will be set via environment variables.REQUESTS_CA_BUNDLECURL_CA_BUNDLE (used as a fallback)The values of these environment variables must be a path to a directory of certificates or a specific certificate. Example.../path/to/certfileExamplesImportingThis should be the only class that is required for import.frombritive.britiveimportBritiveOptionally the various exceptions that this package raises can be imported as well.frombritiveimportexceptionsThen a specific exception could be referenced astry:something()exceptexceptions.TokenMissingError():handle()List All Usersfrombritive.britiveimportBritiveimportjsonbritive=Britive()# source needed data from environment variablesprint(json.dumps(britive.users.list(),indent=2,default=str))Provide Needed Authentication Information in the Scriptfrombritive.britiveimportBritiveimportjsonbritive=Britive(tenant='example',token='...')# source token and tenant locally (not from environment variables)print(json.dumps(britive.users.list(),indent=2,default=str))Create API Token for a Service Identityfrombritive.britiveimportBritiveimportjsonbritive=Britive()# source needed data from environment variablesprint(json.dumps(britive.service_identity_tokens.create(service_identity_id='abc123'),indent=2,default=str))Run a Report (JSON and CSV output)frombritive.britiveimportBritiveimportjsonbritive=Britive()# source needed data from environment variablesprint(json.dumps(britive.reports.run(report_id='abc123'),indent=2,default=str))withopen('file.csv','w')asf:f.write(britive.reports.run(report_id='abc123',csv=True))Create a Profile Policy (profiles v2/enhanced profiles)The commands below will create a policy on a profile that allowsuser@domain.comto check out the profile but only
ifapprover@domain.comapproves that request within 10 minutes.frombritive.britiveimportBritiveb=Britive()policy=b.profiles.policies.build(name='example',users=['user@domain.com'],approval_notification_medium='Email',approver_users=['approver@domain.com'],time_to_approve=10)b.profiles.policies.create(profile_id='...',policy=policy)