我想在 go 中使用 ed25519 生成与 openssh 兼容的 ssh 密钥来替换 rsa.GenerateKey因为 github 不再支持它。
它应该相当于:
ssh-keygen -t ed25519 -C "your_email@example.com"
Run Code Online (Sandbox Code Playgroud)
但我找不到办法做到这一点。
现在,我有这个代码:
func GenerateSSHKeys() (*ED25519Keys, error) {
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
publicED25519Key, err := ssh.NewPublicKey(publicKey)
if err != nil {
return nil, err
}
pubKeyBytes := ssh.MarshalAuthorizedKey(publicED25519Key)
bytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
return nil, err
}
privBlock := pem.Block{
Type: "PRIVATE KEY",
Headers: nil,
Bytes: bytes,
} …Run Code Online (Sandbox Code Playgroud) 我有一个使用 async io 对不同服务执行并行请求的应用程序。这是一个用Gunicorn运行的flask APP。
不幸的是,有些请求有点长(长达 10 秒)。到目前为止,我一直在使用 Gunicorn 的基础工作人员(同步),但由于它们的数量有限,我有时会用完它们。
所以我听说过 gevent 工作类,对于大多数请求,它允许我并行处理,但我不明白应该如何使用 asyncio 处理代码。我用这个简单的例子重现了我的问题:
我使用这个命令来启动服务器:
gunicorn test_wsgi:app --config=test_wsgi_config.py
Run Code Online (Sandbox Code Playgroud)
使用 test_wsgi.py:
import asyncio
from flask import Flask
app = Flask(__name__)
async def a_long_task():
await asyncio.sleep(5)
@app.route('/')
def hello():
loop = asyncio.get_event_loop()
loop.run_until_complete(
loop.create_task(a_long_task())
)
return f'Hello, world'
Run Code Online (Sandbox Code Playgroud)
和 test_wsgi_config.py
worker_class = "gevent"
Run Code Online (Sandbox Code Playgroud)
当我使用worker_class =sync时,它工作正常,但所有请求都排队。但有了 gevent,我一直有:
RuntimeError: There is no current event loop in thread 'DummyThread-1'
Run Code Online (Sandbox Code Playgroud)
如果我创建一个事件循环:
@app.route('/')
def hello():
asyncio.set_event_loop(asyncio.new_event_loop())
loop = asyncio.get_event_loop()
loop.run_until_complete(
loop.create_task(a_long_task())
)
return f'Hello, world'
Run Code Online (Sandbox Code Playgroud)
我得到: …
我正在 python uuid4 字符串中生成。
我用它来识别我的服务帐户,但我的系统之一(GCP 服务帐户)有 30 个字符的限制,现在使用其他帐户为时已晚:
Service account ID must be between 6 and 30 characters.
Service account ID must start with a lower case letter, followed by one or more lower case alphanumerical characters that can be separated by hyphens.
Run Code Online (Sandbox Code Playgroud)
如何获得具有有限冲突风险的较短版本的 UUID?
我见过一些 base64 编码 hack,但我能做的最短是 22。理想情况下,我会拥有类似 git commit hash 的东西,因为冲突的风险是有限的。