Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support specify apikey for auth service request #264

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/network-support/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.0] 2024-03-15

## [1.0.0] 2024-03-07

## [0.2.0] 2024-01-12
Expand All @@ -19,7 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- It's a internal library.

[unreleased]: https://github.com/subquery/network-support/compare/v1.0.0...HEAD
[unreleased]: https://github.com/subquery/network-support/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/subquery/network-support/releases/tag/v1.1.0
[1.0.0]: https://github.com/subquery/network-support/releases/tag/v1.0.0
[0.2.0]: https://github.com/subquery/network-support/releases/tag/v0.2.0
[0.1.1]: https://github.com/subquery/network-support/releases/tag/v0.1.1
Expand Down
2 changes: 1 addition & 1 deletion packages/network-support/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/network-support",
"version": "1.0.2",
"version": "1.1.0",
"main": "dist/index.js",
"author": "SubQuery Pte Limited",
"license": "Apache-2.0",
Expand Down
12 changes: 10 additions & 2 deletions packages/network-support/src/orderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum ResponseFormat {
type Options = {
logger: Logger;
authUrl: string;
apikey?: string;
fallbackServiceUrl?: string;
projectId: string;
projectType: ProjectType;
Expand Down Expand Up @@ -56,6 +57,7 @@ export class OrderManager {
private scoreManager: ScoreManager;

private authUrl: string;
private apikey?: string;
private projectId: string;
private interval = 300_000;
private minScore = 0;
Expand All @@ -68,6 +70,7 @@ export class OrderManager {
constructor(options: Options) {
const {
authUrl,
apikey,
fallbackServiceUrl,
projectId,
logger,
Expand All @@ -78,6 +81,7 @@ export class OrderManager {
timeout = 60000,
} = options;
this.authUrl = authUrl;
this.apikey = apikey;
this.projectId = projectId;
this.projectType = projectType;
this.logger = logger;
Expand Down Expand Up @@ -133,7 +137,7 @@ export class OrderManager {

private async refreshAgreements() {
try {
const orders = await fetchOrders(this.authUrl, this.projectId, this.projectType);
const orders = await fetchOrders(this.authUrl, this.projectId, this.projectType, this.apikey);
if (orders.agreements) {
this._agreements = orders.agreements;
}
Expand Down Expand Up @@ -199,6 +203,7 @@ export class OrderManager {
const signedState = await POST<ChannelAuth>(tokenUrl.toString(), {
deployment: this.projectId,
channelId,
apikey: this.apikey,
});

this.logger?.debug(`request new state signature for runner ${runner} success`);
Expand Down Expand Up @@ -274,7 +279,10 @@ export class OrderManager {
async syncChannelState(state: ChannelState): Promise<void> {
try {
const stateUrl = new URL('/channel/state', this.authUrl);
const res = await POST<{ consumerSign: string }>(stateUrl.toString(), state);
const res = await POST<{ consumerSign: string }>(stateUrl.toString(), {
...state,
apikey: this.apikey,
});

if (res.consumerSign) {
this.logger?.debug(`syncChannelState succeed`);
Expand Down
10 changes: 9 additions & 1 deletion packages/network-support/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ interface AgreementsResponse {
plans: FlexPlanOrder[];
}

export async function fetchOrders(authUrl: string, projectId: string, projectType: ProjectType) {
export async function fetchOrders(
authUrl: string,
projectId: string,
projectType: ProjectType,
apikey?: string
) {
try {
const agreementsURL = new URL(`/orders/${projectType}/${projectId}`, authUrl);
if (apikey) {
agreementsURL.searchParams.append('apikey', apikey);
}
return await GET<AgreementsResponse>(agreementsURL.toString());
} catch {
return { agreements: [], plans: [] };
Expand Down
Loading