| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Runtime.InteropServices; |
| | | 7 | | using Azure.Core; |
| | | 8 | | |
| | | 9 | | namespace Azure.Identity |
| | | 10 | | { |
| | | 11 | | internal sealed class LinuxVisualStudioCodeAdapter : IVisualStudioCodeAdapter |
| | | 12 | | { |
| | 0 | 13 | | private static readonly string s_userSettingsJsonPath = Path.Combine(Environment.GetFolderPath(Environment.Speci |
| | | 14 | | |
| | 0 | 15 | | public string GetUserSettingsPath() => s_userSettingsJsonPath; |
| | | 16 | | |
| | | 17 | | public string GetCredentials(string serviceName, string accountName) |
| | | 18 | | { |
| | 0 | 19 | | Argument.AssertNotNullOrEmpty(serviceName, nameof(serviceName)); |
| | 0 | 20 | | Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); |
| | | 21 | | |
| | 0 | 22 | | IntPtr schemaPtr = GetLibsecretSchema(); |
| | | 23 | | |
| | | 24 | | try |
| | | 25 | | { |
| | 0 | 26 | | return LookupPassword(schemaPtr, serviceName, accountName); |
| | | 27 | | } |
| | | 28 | | finally |
| | | 29 | | { |
| | 0 | 30 | | LinuxNativeMethods.secret_schema_unref(schemaPtr); |
| | 0 | 31 | | } |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | private static string LookupPassword(in IntPtr schemaPtr, string serviceName, string accountName) |
| | 0 | 35 | | => LinuxNativeMethods.secret_password_lookup_sync(schemaPtr, IntPtr.Zero, "service", serviceName, "account", |
| | | 36 | | |
| | | 37 | | private static IntPtr GetLibsecretSchema() |
| | 0 | 38 | | => LinuxNativeMethods.secret_schema_new("org.freedesktop.Secret.Generic", |
| | 0 | 39 | | LinuxNativeMethods.SecretSchemaFlags.SECRET_SCHEMA_DONT_MATCH_NAME, |
| | 0 | 40 | | "service", |
| | 0 | 41 | | LinuxNativeMethods.SecretSchemaAttributeType.SECRET_SCHEMA_ATTRIBUTE_STRING, |
| | 0 | 42 | | "account", |
| | 0 | 43 | | LinuxNativeMethods.SecretSchemaAttributeType.SECRET_SCHEMA_ATTRIBUTE_STRING); |
| | | 44 | | } |
| | | 45 | | } |