|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
use crate::api_core::common::ServiceIdentifier;
|
|
|
|
use crate::api_core::Endpoint;
|
|
|
|
use crate::api_core::Endpoint;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
|
@ -21,7 +22,9 @@ impl Endpoint for CleanTags {
|
|
|
|
pub struct AddTagsRequest {
|
|
|
|
pub struct AddTagsRequest {
|
|
|
|
pub hashes: Vec<String>,
|
|
|
|
pub hashes: Vec<String>,
|
|
|
|
pub service_names_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
pub service_names_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
|
|
|
|
pub service_keys_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
pub service_names_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
pub service_names_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
|
|
|
|
pub service_keys_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct AddTags;
|
|
|
|
pub struct AddTags;
|
|
|
@ -35,10 +38,13 @@ impl Endpoint for AddTags {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct AddTagsRequestBuilder {
|
|
|
|
pub struct AddTagsRequestBuilder {
|
|
|
|
hashes: Vec<String>,
|
|
|
|
hashes: Vec<String>,
|
|
|
|
service_names_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
service_names_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
|
|
|
|
service_keys_to_tags: HashMap<String, Vec<String>>,
|
|
|
|
service_names_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
service_names_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
|
|
|
|
service_keys_to_actions_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// List of actions for a given tag
|
|
|
|
/// List of actions for a given tag
|
|
|
@ -78,16 +84,6 @@ impl TagAction {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for AddTagsRequestBuilder {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
hashes: vec![],
|
|
|
|
|
|
|
|
service_names_to_tags: Default::default(),
|
|
|
|
|
|
|
|
service_names_to_actions_to_tags: Default::default(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl AddTagsRequestBuilder {
|
|
|
|
impl AddTagsRequestBuilder {
|
|
|
|
/// Adds a file hash to the request
|
|
|
|
/// Adds a file hash to the request
|
|
|
|
pub fn add_hash<S: AsRef<str>>(mut self, hash: S) -> Self {
|
|
|
|
pub fn add_hash<S: AsRef<str>>(mut self, hash: S) -> Self {
|
|
|
@ -104,41 +100,48 @@ impl AddTagsRequestBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds a single tag for a given service
|
|
|
|
/// Adds a single tag for a given service
|
|
|
|
pub fn add_tag<S1: AsRef<str>, S2: AsRef<str>>(mut self, service_name: S1, tag: S2) -> Self {
|
|
|
|
pub fn add_tag<S: AsRef<str>>(mut self, service_id: ServiceIdentifier, tag: S) -> Self {
|
|
|
|
if let Some(mappings) = self.service_names_to_tags.get_mut(service_name.as_ref()) {
|
|
|
|
let (service, relevant_mappings) = match service_id {
|
|
|
|
|
|
|
|
ServiceIdentifier::Name(name) => (name, &mut self.service_names_to_tags),
|
|
|
|
|
|
|
|
ServiceIdentifier::Key(key) => (key, &mut self.service_keys_to_tags),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(mappings) = relevant_mappings.get_mut(&service) {
|
|
|
|
mappings.push(tag.as_ref().into())
|
|
|
|
mappings.push(tag.as_ref().into())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.service_names_to_tags
|
|
|
|
relevant_mappings.insert(service, vec![tag.as_ref().into()]);
|
|
|
|
.insert(service_name.as_ref().into(), vec![tag.as_ref().into()]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds multiple tags for a given service
|
|
|
|
/// Adds multiple tags for a given service
|
|
|
|
pub fn add_tags<S1: AsRef<str>>(mut self, service_name: S1, mut tags: Vec<String>) -> Self {
|
|
|
|
pub fn add_tags(mut self, service_id: ServiceIdentifier, mut tags: Vec<String>) -> Self {
|
|
|
|
if let Some(mappings) = self.service_names_to_tags.get_mut(service_name.as_ref()) {
|
|
|
|
let (service, relevant_mappings) = match service_id {
|
|
|
|
|
|
|
|
ServiceIdentifier::Name(name) => (name, &mut self.service_names_to_tags),
|
|
|
|
|
|
|
|
ServiceIdentifier::Key(key) => (key, &mut self.service_keys_to_tags),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(mappings) = relevant_mappings.get_mut(&service) {
|
|
|
|
mappings.append(&mut tags);
|
|
|
|
mappings.append(&mut tags);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.service_names_to_tags
|
|
|
|
relevant_mappings.insert(service, tags);
|
|
|
|
.insert(service_name.as_ref().into(), tags);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds one tag for a given service with a defined action
|
|
|
|
/// Adds one tag for a given service with a defined action
|
|
|
|
pub fn add_tag_with_action<S1: AsRef<str>, S2: AsRef<str>>(
|
|
|
|
pub fn add_tag_with_action<S: AsRef<str>>(
|
|
|
|
mut self,
|
|
|
|
mut self,
|
|
|
|
service_name: S1,
|
|
|
|
service_id: ServiceIdentifier,
|
|
|
|
tag: S2,
|
|
|
|
tag: S,
|
|
|
|
action: TagAction,
|
|
|
|
action: TagAction,
|
|
|
|
) -> Self {
|
|
|
|
) -> Self {
|
|
|
|
|
|
|
|
let (service, relevant_mappings) = match service_id {
|
|
|
|
|
|
|
|
ServiceIdentifier::Name(name) => (name, &mut self.service_names_to_actions_to_tags),
|
|
|
|
|
|
|
|
ServiceIdentifier::Key(key) => (key, &mut self.service_keys_to_actions_to_tags),
|
|
|
|
|
|
|
|
};
|
|
|
|
let action_id = action.into_id();
|
|
|
|
let action_id = action.into_id();
|
|
|
|
if let Some(actions) = self
|
|
|
|
if let Some(actions) = relevant_mappings.get_mut(&service) {
|
|
|
|
.service_names_to_actions_to_tags
|
|
|
|
|
|
|
|
.get_mut(service_name.as_ref())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if let Some(tags) = actions.get_mut(&action_id.to_string()) {
|
|
|
|
if let Some(tags) = actions.get_mut(&action_id.to_string()) {
|
|
|
|
tags.push(tag.as_ref().into());
|
|
|
|
tags.push(tag.as_ref().into());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -147,8 +150,7 @@ impl AddTagsRequestBuilder {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let mut actions = HashMap::new();
|
|
|
|
let mut actions = HashMap::new();
|
|
|
|
actions.insert(action_id.to_string(), vec![tag.as_ref().into()]);
|
|
|
|
actions.insert(action_id.to_string(), vec![tag.as_ref().into()]);
|
|
|
|
self.service_names_to_actions_to_tags
|
|
|
|
relevant_mappings.insert(service, actions);
|
|
|
|
.insert(service_name.as_ref().into(), actions);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -158,7 +160,9 @@ impl AddTagsRequestBuilder {
|
|
|
|
AddTagsRequest {
|
|
|
|
AddTagsRequest {
|
|
|
|
hashes: self.hashes,
|
|
|
|
hashes: self.hashes,
|
|
|
|
service_names_to_tags: self.service_names_to_tags,
|
|
|
|
service_names_to_tags: self.service_names_to_tags,
|
|
|
|
|
|
|
|
service_keys_to_tags: self.service_keys_to_tags,
|
|
|
|
service_names_to_actions_to_tags: self.service_names_to_actions_to_tags,
|
|
|
|
service_names_to_actions_to_tags: self.service_names_to_actions_to_tags,
|
|
|
|
|
|
|
|
service_keys_to_actions_to_tags: self.service_keys_to_actions_to_tags,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|