Skip to content

Commit 36be83d

Browse files
committed
refactor(api-key): rename store method to set and simplify key retrieval
1 parent e69f5a1 commit 36be83d

2 files changed

Lines changed: 3 additions & 18 deletions

File tree

src/lib/api-key/index.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
import type { SecretStorage } from "vscode";
21
import { SquareCloudAPI } from "@squarecloud/api";
32

4-
import { Config, ExtensionID } from "../constants";
53
import { ApiKeyStore } from "./store";
64

75
export class ApiKey {
86
private readonly store = new ApiKeyStore();
97

10-
constructor(private readonly secrets: SecretStorage) {}
11-
128
async get() {
13-
let apiKey = await this.store.get();
14-
15-
if (!apiKey) {
16-
const secretsApiKey = await this.secrets.get(
17-
`${ExtensionID}.${Config.APIKey}`,
18-
);
19-
if (secretsApiKey) {
20-
await this.set(secretsApiKey);
21-
apiKey = secretsApiKey;
22-
}
23-
}
24-
9+
const apiKey = await this.store.get();
2510
return apiKey;
2611
}
2712

2813
async set(value: string | undefined) {
2914
if (!value) return void (await this.store.delete());
30-
await this.store.store(value);
15+
await this.store.set(value);
3116
}
3217

3318
async test(apiKey?: string) {

src/lib/api-key/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ApiKeyStore {
2424
}
2525
}
2626

27-
async store(apiKey: string): Promise<void> {
27+
async set(apiKey: string): Promise<void> {
2828
await this.reload();
2929
this.apiKey = apiKey;
3030
await this.write(apiKey);

0 commit comments

Comments
 (0)