{"id":322996,"date":"2021-05-12T15:01:27","date_gmt":"2021-05-12T15:01:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=322996"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=322996","title":{"rendered":"SecretStorage\u00a0VSCode\u00a0extension\u00a0API"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412&nbsp;VSCode&nbsp;\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442&nbsp;\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e&nbsp;\u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432&nbsp;\u0445\u0440\u0430\u043d\u0438\u0442\u044c&nbsp;\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438&nbsp;\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u0414\u043e&nbsp;\u043f\u0440\u0438\u0445\u043e\u0434\u0430&nbsp;\u0432\u0435\u0440\u0441\u0438\u0438&nbsp;1.53.0&nbsp;\u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e&nbsp;\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e&nbsp;\u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c&nbsp;\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432&nbsp;Memento&nbsp;\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445&nbsp;\u0432 <a href=\"https:\/\/code.visualstudio.com\/api\/references\/vscode-api#ExtensionContext\" rel=\"noopener noreferrer nofollow\">workspaceState \u0438 globalState<\/a> \u0438\u043b\u0438&nbsp;\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/github.com\/microsoft\/vscode-docker\/pull\/2709\/files\" rel=\"noopener noreferrer nofollow\">keytar<\/a>. \u0410 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u0441 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u044f\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u043d\u0435 \u0441\u0430\u043c\u043e\u0439 \u043b\u0443\u0447\u0448\u0435\u0439 \u0438\u0434\u0435\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u044b \u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 <code>settings.json <\/code>\u0438 <code>environment variables<\/code>. \u0410 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0434\u0430\u0447\u0443 \u043a\u043b\u044e\u0447\u0435\u0439 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 VSCode SecretStorage. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/268\/2e8\/bfc\/2682e8bfcda83a25ceac83c89426820a.png\" alt=\"\" title=\"\" width=\"1160\" height=\"580\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0430\u0437\u043e\u0432\u0435\u043c <code>fancycolor<\/code>. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/code.visualstudio.com\/api\/get-started\/your-first-extension\" rel=\"noopener noreferrer nofollow\">VSCode Extensions<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443.<\/p>\n<h2>settings.json<\/h2>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043e\u0442 \u0432\u0441\u0435\u0445 VSCode extensions \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u0431\u0449\u0435\u043c \u0444\u0430\u0439\u043b\u0435 <code>settings.json<\/code> \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>fancycolor<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0445\u043e\u0441\u0442\u043e\u0432 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>SSH - Remote<\/code>.<\/p>\n<pre><code class=\"javascript\">const configurationWorkspace = workspace.getConfiguration() const sshRemotePlatform: string | undefined = configurationWorkspace.get(   \"remote.SSH.remotePlatform\" ) console.log(sshRemotePlatform)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>SSH - Remote<\/code>.<\/p>\n<pre><code class=\"bash\">Proxy {ubuntu: 'linux', home: 'linux', raspberry: 'linux'}<\/code><\/pre>\n<h2>environment variables<\/h2>\n<p>VSCode \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0432 <code>.bashrc<\/code> \u0432 Linux \u0438\u043b\u0438 <code>User.Environment<\/code> \u0432 Windows \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>process.env<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>\/home\/ubuntu\/.env<\/code> \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ACCESS_TOKEN_ENV<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u0432 <code>.bashrc<\/code>.<\/p>\n<pre><code class=\"bash\">echo 'export ACCESS_TOKEN_ENV=\"d8aba3b2-fda0-414a-b867-4798b7892bb4\"' &gt;&gt; \/home\/ubuntu\/.env echo \"source \/home\/ubuntu\/.env\" &gt;&gt; \/home\/ubuntu\/.bashrc<\/code><\/pre>\n<p>\u0412 Windows \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Powershell.<\/p>\n<pre><code class=\"powershell\">[System.Environment]::SetEnvironmentVariable('ACCESS_TOKEN_ENV', 'd8aba3b2-fda0-414a-b867-4798b7892bb4', [System.EnvironmentVariableTarget]::User)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0435\u0433\u043e \u0432 VSCode <code>fancycolor<\/code> extension.<\/p>\n<pre><code class=\"javascript\">import * as process from \"process\" export const accessTokenEnv = process.env[\"ACCESS_TOKEN_ENV\"] console.log(accessTokenEnv)<\/code><\/pre>\n<p>\u0412 \u0432\u044b\u0432\u043e\u0434\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448 \u0442\u043e\u043a\u0435\u043d.<\/p>\n<pre><code class=\"bash\">d8aba3b2-fda0-414a-b867-4798b7892bb4<\/code><\/pre>\n<h2>SecretStorage<\/h2>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u0435\u0439, \u043b\u043e\u0433\u0438\u043d\u043e\u0432, \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 VSCode. \u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <code>AuthSettings<\/code>, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c <code>fancycolor_token<\/code>, \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><code>init<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e SecretStorage<\/p>\n<\/li>\n<li>\n<p>getter <code>instance<\/code><\/p>\n<\/li>\n<li>\n<p><code>storeAuthData<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 SecretStorage<\/p>\n<\/li>\n<li>\n<p><code>getAuthData<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 SecretStorage<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">import { ExtensionContext, SecretStorage } from \"vscode\"  export default class AuthSettings { \tprivate static _instance: AuthSettings  \tconstructor(private secretStorage: SecretStorage) {}  \tstatic init(context: ExtensionContext): void { \t\t\/* \t\tCreate instance of new AuthSettings. \t\t*\/ \t\tAuthSettings._instance = new AuthSettings(context.secrets) \t}  \tstatic get instance(): AuthSettings { \t\t\/* \t\tGetter of our AuthSettings existing instance. \t\t*\/ \t\treturn AuthSettings._instance \t}  \tasync storeAuthData(token?: string): Promise&lt;void&gt; { \t\t\/* \t\tUpdate values in bugout_auth secret storage. \t\t*\/ \t\tif (token) { \t\t\tthis.secretStorage.store(\"fancycolor_token\", token) \t\t} \t}  \tasync getAuthData(): Promise&lt;string | undefined&gt; { \t\t\/* \t\tRetrieve data from secret storage. \t\t*\/ \t\treturn await this.secretStorage.get(\"fancycolor_token\") \t} }<\/code><\/pre>\n<p>\u0412 <code>extension.ts<\/code> \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 Command Palette.<\/p>\n<pre><code class=\"javascript\">import * as vscode from \"vscode\"  import AuthSettings from \".\/settings\"  export function activate(context: vscode.ExtensionContext) { \t\/\/ Initialize and get current instance of our Secret Storage \tAuthSettings.init(context) \tconst settings = AuthSettings.instance \t \t\/\/ Register commands to save and retrieve token \tvscode.commands.registerCommand(\"fancycolor.setToken\", async () =&gt; { \t\tconst tokenInput = await vscode.window.showInputBox() \t\tawait settings.storeAuthData(tokenInput) \t}) \tvscode.commands.registerCommand(\"fancycolor.getToken\", async () =&gt; { \t\tconst tokenOutput = await settings.getAuthData() \t\tconsole.log(tokenOutput) \t}) }  export function deactivate() {}<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>package.json<\/code> \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>fancycolor.setToken<\/code> \u0438 <code>fancycolor.getToken<\/code>. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 VSCode SecretStorage, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 SecretStorage \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u0441\u0432\u043e\u0439 <code>_id: 'undefined_publisher.fancycolor'<\/code>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/556916\/\"> https:\/\/habr.com\/ru\/post\/556916\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412&nbsp;VSCode&nbsp;\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442&nbsp;\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e&nbsp;\u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432&nbsp;\u0445\u0440\u0430\u043d\u0438\u0442\u044c&nbsp;\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438&nbsp;\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.&nbsp;\u0414\u043e&nbsp;\u043f\u0440\u0438\u0445\u043e\u0434\u0430&nbsp;\u0432\u0435\u0440\u0441\u0438\u0438&nbsp;1.53.0&nbsp;\u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e&nbsp;\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e&nbsp;\u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c&nbsp;\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432&nbsp;Memento&nbsp;\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445&nbsp;\u0432 <a href=\"https:\/\/code.visualstudio.com\/api\/references\/vscode-api#ExtensionContext\" rel=\"noopener noreferrer nofollow\">workspaceState \u0438 globalState<\/a> \u0438\u043b\u0438&nbsp;\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/github.com\/microsoft\/vscode-docker\/pull\/2709\/files\" rel=\"noopener noreferrer nofollow\">keytar<\/a>. \u0410 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u0441 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u044f\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u043d\u0435 \u0441\u0430\u043c\u043e\u0439 \u043b\u0443\u0447\u0448\u0435\u0439 \u0438\u0434\u0435\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u044b \u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 <code>settings.json <\/code>\u0438 <code>environment variables<\/code>. \u0410 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0434\u0430\u0447\u0443 \u043a\u043b\u044e\u0447\u0435\u0439 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 VSCode SecretStorage. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0430\u0437\u043e\u0432\u0435\u043c <code>fancycolor<\/code>. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/code.visualstudio.com\/api\/get-started\/your-first-extension\" rel=\"noopener noreferrer nofollow\">VSCode Extensions<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443.<\/p>\n<h2>settings.json<\/h2>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043e\u0442 \u0432\u0441\u0435\u0445 VSCode extensions \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u0431\u0449\u0435\u043c \u0444\u0430\u0439\u043b\u0435 <code>settings.json<\/code> \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>fancycolor<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0445\u043e\u0441\u0442\u043e\u0432 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>SSH - Remote<\/code>.<\/p>\n<pre><code class=\"javascript\">const configurationWorkspace = workspace.getConfiguration() const sshRemotePlatform: string | undefined = configurationWorkspace.get(   \"remote.SSH.remotePlatform\" ) console.log(sshRemotePlatform)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>SSH - Remote<\/code>.<\/p>\n<pre><code class=\"bash\">Proxy {ubuntu: 'linux', home: 'linux', raspberry: 'linux'}<\/code><\/pre>\n<h2>environment variables<\/h2>\n<p>VSCode \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0432 <code>.bashrc<\/code> \u0432 Linux \u0438\u043b\u0438 <code>User.Environment<\/code> \u0432 Windows \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>process.env<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>\/home\/ubuntu\/.env<\/code> \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ACCESS_TOKEN_ENV<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u0432 <code>.bashrc<\/code>.<\/p>\n<pre><code class=\"bash\">echo 'export ACCESS_TOKEN_ENV=\"d8aba3b2-fda0-414a-b867-4798b7892bb4\"' &gt;&gt; \/home\/ubuntu\/.env echo \"source \/home\/ubuntu\/.env\" &gt;&gt; \/home\/ubuntu\/.bashrc<\/code><\/pre>\n<p>\u0412 Windows \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Powershell.<\/p>\n<pre><code class=\"powershell\">[System.Environment]::SetEnvironmentVariable('ACCESS_TOKEN_ENV', 'd8aba3b2-fda0-414a-b867-4798b7892bb4', [System.EnvironmentVariableTarget]::User)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0435\u0433\u043e \u0432 VSCode <code>fancycolor<\/code> extension.<\/p>\n<pre><code class=\"javascript\">import * as process from \"process\" export const accessTokenEnv = process.env[\"ACCESS_TOKEN_ENV\"] console.log(accessTokenEnv)<\/code><\/pre>\n<p>\u0412 \u0432\u044b\u0432\u043e\u0434\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448 \u0442\u043e\u043a\u0435\u043d.<\/p>\n<pre><code class=\"bash\">d8aba3b2-fda0-414a-b867-4798b7892bb4<\/code><\/pre>\n<h2>SecretStorage<\/h2>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u0435\u0439, \u043b\u043e\u0433\u0438\u043d\u043e\u0432, \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 VSCode. \u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <code>AuthSettings<\/code>, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c <code>fancycolor_token<\/code>, \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><code>init<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e SecretStorage<\/p>\n<\/li>\n<li>\n<p>getter <code>instance<\/code><\/p>\n<\/li>\n<li>\n<p><code>storeAuthData<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 SecretStorage<\/p>\n<\/li>\n<li>\n<p><code>getAuthData<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 SecretStorage<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">import { ExtensionContext, SecretStorage } from \"vscode\"  export default class AuthSettings { \tprivate static _instance: AuthSettings  \tconstructor(private secretStorage: SecretStorage) {}  \tstatic init(context: ExtensionContext): void { \t\t\/* \t\tCreate instance of new AuthSettings. \t\t*\/ \t\tAuthSettings._instance = new AuthSettings(context.secrets) \t}  \tstatic get instance(): AuthSettings { \t\t\/* \t\tGetter of our AuthSettings existing instance. \t\t*\/ \t\treturn AuthSettings._instance \t}  \tasync storeAuthData(token?: string): Promise&lt;void&gt; { \t\t\/* \t\tUpdate values in bugout_auth secret storage. \t\t*\/ \t\tif (token) { \t\t\tthis.secretStorage.store(\"fancycolor_token\", token) \t\t} \t}  \tasync getAuthData(): Promise&lt;string | undefined&gt; { \t\t\/* \t\tRetrieve data from secret storage. \t\t*\/ \t\treturn await this.secretStorage.get(\"fancycolor_token\") \t} }<\/code><\/pre>\n<p>\u0412 <code>extension.ts<\/code> \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 Command Palette.<\/p>\n<pre><code class=\"javascript\">import * as vscode from \"vscode\"  import AuthSettings from \".\/settings\"  export function activate(context: vscode.ExtensionContext) { \t\/\/ Initialize and get current instance of our Secret Storage \tAuthSettings.init(context) \tconst settings = AuthSettings.instance \t \t\/\/ Register commands to save and retrieve token \tvscode.commands.registerCommand(\"fancycolor.setToken\", async () =&gt; { \t\tconst tokenInput = await vscode.window.showInputBox() \t\tawait settings.storeAuthData(tokenInput) \t}) \tvscode.commands.registerCommand(\"fancycolor.getToken\", async () =&gt; { \t\tconst tokenOutput = await settings.getAuthData() \t\tconsole.log(tokenOutput) \t}) }  export function deactivate() {}<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>package.json<\/code> \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>fancycolor.setToken<\/code> \u0438 <code>fancycolor.getToken<\/code>. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 VSCode SecretStorage, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 SecretStorage \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u0441\u0432\u043e\u0439 <code>_id: 'undefined_publisher.fancycolor'<\/code>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/556916\/\"> https:\/\/habr.com\/ru\/post\/556916\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-322996","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322996"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322996\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}