public override Task<Secret> Get(string scope, string resourceType, string resourceName, string key) { // Sharepoint API isn't Async :( try { // Open the site connection var context = new ClientContext(SiteRoot); var list = context.Web.Lists.GetByTitle("Secret Store"); // Build the full key string fullKey = resourceType + "." + resourceName; if (!String.IsNullOrEmpty(key)) { fullKey += ":" + key; } // Build a Caml query var query = new CamlQuery(); query.ViewXml = @" <View> <Query> <Where> <And> <Eq> <FieldRef Name='Key' /> <Value Type='Text'>" + fullKey + @"</Value> </Eq> <Contains> <FieldRef Name='Scopes' /> <Value Type='Text'>" + scope + @"</Value> </Contains> </And> </Where> </Query> <RowLimit>1</RowLimit> </View>"; // Get the items var itemQuery = list.GetItems(query); context.Load(itemQuery); context.ExecuteQuery(); var items = itemQuery.ToList(); if (items.Count > 1) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.SharepointSecretStoreConnection_AmbiguousMatch, fullKey, scope)); } var item = items.FirstOrDefault(); if (item == null) { return null; } var secret = new Secret(); secret.Title = (string)item["Title"]; secret.ResourceType = resourceType; secret.ResourceName = resourceName; secret.Key = key; secret.Username = (string)item["Username"]; secret.Password = (string)item["Password"]; secret.Value = (string)item["Value"]; return Task.FromResult(secret); } catch (Exception ex) { throw; } }
public abstract Task Set(Secret value);
public override Task Set(Secret value) { throw new NotImplementedException(); }