客户端Stubs接入恒星API
stellarstation的Python项目详细描述
恒星站API
StellarStation和受支持客户端的公共api定义 图书馆/助手。
当事情不清楚或对使用问题有疑问时,可以随时发送prs来改进文档。
用法
恒星站API基于gRPCAPI客户端可以用任何 GRPC支持的语言,请遵循特定于语言的指南之一here。
用于生成特定于语言的存根代码的主要协议定义是here。
特定语言文档:
在客户端代码中直接使用此存储库中的proto
文件时,请确保仅使用tagged releases。
使用任何未标记的修订版中的proto
文件可能无法正常工作或保持向后兼容。
API遵循语义版本控制-在增加 主要版本。
爪哇语
我们为java提供预编译的客户机存根。Java用户只需在 而不需要将协议编译成代码本身。
渐变用户应该将stellarstation-api
工件添加到他们的dependencies
中,例如
dependencies{compile'com.stellarstation.api:stellarstation-api:0.3.0'}
maven用户将添加到他们的pom.xml
<dependencies><dependency><groupId>com.stellarstation.api</groupId><artifactId>stellarstation-api</artifactId><version>0.3.0</version></dependency></dependencies>
可以找到java api客户机的完整示例here。
我们将SNAPSHOT
版本发布到https://oss.jfrog.org/libs-snapshot/以访问预览功能。
与使用未标记的版本相同的注意事项也适用-并非构建中的所有函数都可以
尚未实现,并且不能保证SNAPSHOT
生成的向后兼容性。它是
通常不建议在未事先咨询Stellarstation代表的情况下使用SNAPSHOT
版本。
Alpine Linux用户注意事项
对于任何试图在Alpine Linux容器中使用Java API客户机的人来说,他们会发现它没有 由于grpc和java 8的限制而工作。有很多方法可以解决这个问题,比如 使用jetty-alpn或 安装Java 9+版本,但我们建议Java 8用户使用 distroless,其中 同样紧凑,但可以与GRPC配合使用。
Python
我们为python提供预编译的客户端存根。Python用户可以使用pip
安装它们
$ pip install --upgrade stellarstation
python api客户端的完整示例可以找到here。
开始
我们为go提供预编译的客户机存根,找到here。
importstellarstation"github.com/infostellarinc/go-stellarstation/api/v1"
nodejs
我们为NodeJS提供预编译的客户端存根nodejs用户可以使用npm
安装它们。
$ npm install @infostellarinc/stellarstation-api
身份验证
使用jwt承载令牌(https://jwt.io)完成对stellarstation api的身份验证。什么时候? 初始化api客户端时,请确保使用下载的私钥注册调用凭据 从星站控制台在GRPC存根上注册呼叫凭据的详细信息可以是 找到here。请注意,如果在 控制台,它将无法使用API进行身份验证
爪哇语
对于java,可以使用grpc-auth
和google-auth-library-oauth2-http
库轻松设置
API客户端的身份验证。
// Load the private key downloaded from the StellarStation Console.ServiceAccountJwtAccessCredentialscredentials=ServiceAccountJwtAccessCredentials.fromStream(Resources.getResource("stellarstation-private-key.json").openStream(),URI.create("https://api.stellarstation.com"));// Setup the gRPC client.ManagedChannelchannel=ManagedChannelBuilder.forAddress("api.stellarstation.com",443).build();StellarStationServiceStubclient=StellarStationServiceGrpc.newStub(channel).withCallCredentials(MoreCallCredentials.from(credentials));
Python
google-auth
for python可用于api客户端的身份验证。
# Load the private key downloaded from the StellarStation Console.credentials=google_auth_jwt.Credentials.from_service_account_file('stellarstation-private-key.json',audience='https://api.stellarstation.com')# Setup the gRPC client.jwt_creds=google_auth_jwt.OnDemandCredentials.from_signing_credentials(credentials)channel=google_auth_transport_grpc.secure_authorized_channel(jwt_creds,None,'api.stellarstation.com:443')client=stellarstation_pb2_grpc.StellarStationServiceStub(channel)
其他语言
其他语言也有类似的方法来加载服务帐户jwt访问凭据。 例如,
- 去-https://github.com/grpc/grpc-go/blob/96cefb43cfc8b2cd3fed9f19f59830bc69e30093/credentials/oauth/oauth.go#L60