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

オブジェクトストレージとの通信にProxyを使うかを選択できるように #6245

Closed
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
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ objectStorageRegion: "Region"
objectStorageRegionDesc: "'xx-east-1'のようなregionを指定してください。使用サービスにregionの概念がない場合は、空または'us-east-1'にしてください。"
objectStorageUseSSL: "SSLを使用する"
objectStorageUseSSLDesc: "API接続にhttpsを使用しない場合はオフにしてください"
objectStorageUseProxy: "Proxyを利用する"
objectStorageUseProxyDesc: "API接続にproxyを利用しない場合はオフにしてください"
serverLogs: "サーバーログ"
deleteAll: "全て削除"
showFixedPostForm: "タイムライン上部に投稿フォームを表示する"
Expand Down
14 changes: 14 additions & 0 deletions migration/1586624197029-AddObjectStorageUseProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from 'typeorm';

export class AddObjectStorageUseProxy1586624197029 implements MigrationInterface {
name = 'AddObjectStorageUseProxy1586624197029'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "meta" ADD "objectStorageUseProxy" boolean NOT NULL DEFAULT true`, undefined);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "objectStorageUseProxy"`, undefined);
}

}
4 changes: 4 additions & 0 deletions src/client/pages/instance/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<mk-input v-model="objectStorageSecretKey" :disabled="!useObjectStorage"><template #icon><fa :icon="faKey"/></template>Secret key</mk-input>
</div>
<mk-switch v-model="objectStorageUseSSL" :disabled="!useObjectStorage">{{ $t('objectStorageUseSSL') }}<template #desc>{{ $t('objectStorageUseSSLDesc') }}</template></mk-switch>
<mk-switch v-model="objectStorageUseProxy" :disabled="!useObjectStorage">{{ $t('objectStorageUseProxy') }}<template #desc>{{ $t('objectStorageUseProxyDesc') }}</template></mk-switch>
</template>
</div>
<div class="_footer">
Expand Down Expand Up @@ -249,6 +250,7 @@ export default Vue.extend({
objectStorageAccessKey: null,
objectStorageSecretKey: null,
objectStorageUseSSL: false,
objectStorageUseProxy: false,
enableTwitterIntegration: false,
twitterConsumerKey: null,
twitterConsumerSecret: null,
Expand Down Expand Up @@ -303,6 +305,7 @@ export default Vue.extend({
this.objectStorageAccessKey = this.meta.objectStorageAccessKey;
this.objectStorageSecretKey = this.meta.objectStorageSecretKey;
this.objectStorageUseSSL = this.meta.objectStorageUseSSL;
this.objectStorageUseProxy = this.meta.objectStorageUseProxy;
this.enableTwitterIntegration = this.meta.enableTwitterIntegration;
this.twitterConsumerKey = this.meta.twitterConsumerKey;
this.twitterConsumerSecret = this.meta.twitterConsumerSecret;
Expand Down Expand Up @@ -411,6 +414,7 @@ export default Vue.extend({
objectStorageAccessKey: this.objectStorageAccessKey ? this.objectStorageAccessKey : null,
objectStorageSecretKey: this.objectStorageSecretKey ? this.objectStorageSecretKey : null,
objectStorageUseSSL: this.objectStorageUseSSL,
objectStorageUseProxy: this.objectStorageUseProxy,
enableTwitterIntegration: this.enableTwitterIntegration,
twitterConsumerKey: this.twitterConsumerKey,
twitterConsumerSecret: this.twitterConsumerSecret,
Expand Down
5 changes: 5 additions & 0 deletions src/models/entities/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,9 @@ export class Meta {
default: true,
})
public objectStorageUseSSL: boolean;

@Column('boolean', {
default: true,
})
public objectStorageUseProxy: boolean;
}
8 changes: 8 additions & 0 deletions src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ export const meta = {
objectStorageUseSSL: {
validator: $.optional.bool
},

objectStorageUseProxy: {
validator: $.optional.bool
}
}
};

Expand Down Expand Up @@ -632,6 +636,10 @@ export default define(meta, async (ps, me) => {
set.objectStorageUseSSL = ps.objectStorageUseSSL;
}

if (ps.objectStorageUseProxy !== undefined) {
set.objectStorageUseProxy = ps.objectStorageUseProxy;
}

await getConnection().transaction(async transactionalEntityManager => {
const meta = await transactionalEntityManager.findOne(Meta, {
order: {
Expand Down
1 change: 1 addition & 0 deletions src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default define(meta, async (ps, me) => {
response.objectStorageAccessKey = instance.objectStorageAccessKey;
response.objectStorageSecretKey = instance.objectStorageSecretKey;
response.objectStorageUseSSL = instance.objectStorageUseSSL;
response.objectStorageUseProxy = instance.objectStorageUseProxy;
}

return response;
Expand Down
2 changes: 1 addition & 1 deletion src/services/drive/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getS3(meta: Meta) {
sslEnabled: meta.objectStorageUseSSL,
s3ForcePathStyle: !!meta.objectStorageEndpoint,
httpOptions: {
agent: meta.objectStorageUseSSL ? httpsAgent : httpAgent
agent: meta.objectStorageUseProxy ? (meta.objectStorageUseProxy ? httpsAgent : httpAgent) : undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSL で Prxoyを使う場合 HttpsProxyAgent
SSL で Prxoyを使う場合 https.Agent
非SSL で Prxoyを使う場合 HttpProxyAgent
非SSL で Prxoyを使う場合 http.Agent
なのでこれだとちょっと挙動が違う
結局下のところを分解しないといけない
https://github.com/syuilo/misskey/blob/c62aff76af427eb5f7cff0ddc835996754785f44/src/misc/fetch.ts#L30-L42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別にproxy入る前はundefined相当だったしundefined返せばよいのではという気持ち

https://github.com/syuilo/misskey/blob/bb7edfee04d990fcf56e0cee46f1da7b62693cb6/src/services/drive/s3.ts

Copy link
Contributor

@mei23 mei23 Apr 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefinedだと (httpsでも) keep-aliveなどが効かなくなるのでパフォーマンスが悪くなります

proxyとkeep-aliveは同時に入れていってます

  • httpsのproxyとkeep-alive対応 を追加
  • httpもproxyとkeep-alive対応 を追加

(httpに) proxy入る前は (httpは) undefined相当 だったけど
(https) は proxyとkeep-alive が入った状態です

}
});
}