guard_exception
- guard all exception for swift run python
install
- pip install guard-exception
functions
- guardExceptionWithOutParams: execute function without parameters
- guardException: execute function with parameters
- guardSearchKeyException: look for a key
- guardSearchKeryRecursiveException: look for a key recursively
- guardExceptionIsIterable: return 1 or 0, if exists key on dic
example
import guard_exception as ge
gg = ge.guard_exception()
def divide(a, b):
return a / b
print(gg.guardException(divide, a=1, b=0))
# result cli
# {'data:': None, 'error': 'division by zero'}
example on swift with PythonKit
import PythonKit
let hvac = Python.import("hvac")
let ge = Python.import("guard_exception")
let gg = ge.guard_exception()
let client = hvac.Client(url: "http://0.0.0.0:8200")
let user = "incorrect_user"
let params = Python.dict()
params["username"] = PythonObject(user)
params["password"] = PythonObject("incorrect_password")
print(gg.guardException(client.login, url: "v1/auth/userpass/login/\(user)", use_token: true, json: params))
// result: cli
//{'data': None, 'error': 'invalid username or password, on post http://0.0.0.0:8200/v1/auth/userpass/login/incorrect_user'}
example complete on swift
// guardException
// guardSearchKeyException
// guardSearchKeryRecursiveException
import Vapor
import PythonKit
let hvac = Python.import("hvac")
let ge = Python.import("guard_exception")
let gg = ge.guard_exception()
// token structure for authentication
// Content: help resolve the api response -> json
public struct Token: Content {
public var client_token: String!
public var accessor: String!
public var policies: [String]!
public var token_policies: [String]!
}
// swift class for authentication
public class autentication {
// MARK: - Properties
let client = hvac.Client(url: "http://0.0.0.0:8200")
var token: Token?
// MARK: - Initializers
public init() { }
public func login(user: String, password: String) -> Token {
let params = Python.dict()
params["username"] = PythonObject(user)
params["password"] = PythonObject(password)
let generated = Python.dict(gg.guardException(self.client.login, url: "v1/auth/userpass/login/\(user)", use_token: true, json: params))
// result genereted
/*
{
'data':
{
'request_id': '45464674xxxxxxxb',
'lease_id': '',
'renewable': False,
'lease_duration': 0,
'data': None,
'wrap_info': None,
'warnings': None,
'auth': {
'client_token': 'hvs.CAESasdfasdfxxxxxxxxxxxxxxxxxxx',
'accessor': 'TvExxxxxxxxxxxxxxx1ESqjW',
'policies': ['default'],
'token_policies': ['default'],
'metadata': {'username': 'rafael'},
'lease_duration': 2764800,
'renewable': True,
'entity_id': 'dadxxxf8-xxxx-xxxxx-xxxxx-xxxxxxxxxxx',
'token_type': 'service',
'orphan': True,
'mfa_requirement': None,
'num_uses': 0
}
},
'error': None
}
*/
let auth = gg.guardExceptionIsIterable(generated, key:"data")
if Int(auth["data"])! > 0 {
let client_token = String(gg.guardSearchKeryRecursiveException(generated, key:["data", "auth", "client_token"])["data"])
let accessor = String(gg.guardSearchKeryRecursiveException(generated, key:["data", "auth", "accessor"])["data"])
let policies = [String](gg.guardSearchKeryRecursiveException(generated, key:["data", "auth", "policies"])["data"])!
let token_policies = [String](gg.guardSearchKeryRecursiveException(generated, key:["data", "auth", "token_policies"])["data"])!
if client_token != nil {
self.token = Token(
client_token: client_token,
accessor: accessor,
policies: policies,
token_policies: token_policies
)
}
}
return self.token ?? Token(client_token: nil, accessor: nil, policies: [], token_policies: [])
}
}
Metadata
Release files for guard-exception 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| guard_exception-1.1.0.tar.gz | 4.8 kB | Without provenance | Details for guard_exception-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| guard_exception-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for guard_exception-1.1.0-py3-none-any.whl |
Total release size: 9.2 kB
Release files / guard_exception-1.1.0.tar.gz
| Download URL | guard_exception-1.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac06c46e029d1b1c31c7dfd8500a7493d45c2e251a291a1cb48f9dc7ce0967c0
|
|
BLAKE2b-256 checksum How to use checksums |
5f9d11a98d36cafa19b4efdb704e851c23aa96b1b596e9172ef1b2c3d3c573d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.8.10 Linux/5.13.0-39-generic
|
Release files / guard_exception-1.1.0-py3-none-any.whl
| Download URL | guard_exception-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02681b2cee3c1cb732243c19c77cb8592127f461cbc9a3badf1463d66298bc4c
|
|
BLAKE2b-256 checksum How to use checksums |
70ad7b277e4e9217aed159cf1682ca9584b9e636291c13419236fbe693b7130f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.8.10 Linux/5.13.0-39-generic
|
Security for guard-exception 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.