pub struct UnifiClient { /* private fields */ }Expand description
UniFi DNS-policy client.
site holds the user-configured value — typically the human-readable site
name (e.g. "Default"), but a UUID is also accepted. The first DNS call
resolves that label to the controller’s actual site UUID via
GET /v1/sites and caches it for the lifetime of the client.
Implementations§
Source§impl UnifiClient
impl UnifiClient
Sourcepub fn new(base_url: String, token: ApiToken, site: String) -> Result<Self>
pub fn new(base_url: String, token: ApiToken, site: String) -> Result<Self>
Build a new client. Uses a 30-second timeout to match the rest of the vendor clients in this crate.
pub fn base_url(&self) -> &str
Sourcepub fn site(&self) -> &str
pub fn site(&self) -> &str
The configured site identifier as supplied via config or env vars. This is what the user typed and may be either a name or a UUID.
Sourcepub async fn resolve_site_id(&self) -> Result<&str>
pub async fn resolve_site_id(&self) -> Result<&str>
Resolve the configured site (name or UUID) to the canonical UniFi
site UUID.
On first call this performs GET /v1/sites and matches the
configured value against each site’s id, name, and
internalReference (case-insensitively). The resolved UUID is cached
for the lifetime of the client so subsequent DNS calls don’t pay the
site-list cost.
If no site matches the configured value, returns Error::Api whose
message lists every valid human-readable site name so the user can
fix their config without leaving the CLI.
Sourcepub async fn list_sites_page(
&self,
offset: u32,
limit: u32,
) -> Result<UnifiSitePage>
pub async fn list_sites_page( &self, offset: u32, limit: u32, ) -> Result<UnifiSitePage>
GET /v1/sites — single page of sites accessible to this API key.
Sourcepub async fn list_all_sites(&self) -> Result<Vec<UnifiSite>>
pub async fn list_all_sites(&self) -> Result<Vec<UnifiSite>>
Fetch every site by paginating until exhausted.
Same termination logic as list_all_dns_policies: stops on empty page,
known totalCount, or short page; capped at 1000 pages.
Sourcepub async fn list_dns_policies_page(
&self,
offset: u32,
limit: u32,
filter: Option<&str>,
) -> Result<UnifiDnsPolicyPage>
pub async fn list_dns_policies_page( &self, offset: u32, limit: u32, filter: Option<&str>, ) -> Result<UnifiDnsPolicyPage>
GET /sites/{siteId}/dns/policies — single page.
Caller controls pagination through offset and limit. limit is
clamped to the documented maximum of 200.
Sourcepub async fn list_all_dns_policies(
&self,
filter: Option<&str>,
) -> Result<Vec<UnifiDnsPolicy>>
pub async fn list_all_dns_policies( &self, filter: Option<&str>, ) -> Result<Vec<UnifiDnsPolicy>>
Fetch every DNS policy by paginating until exhausted.
Termination: stops when an empty page is returned, or when totalCount
(if present) has been reached. Hard cap of 1000 pages guards against
pathological controller responses.
Sourcepub async fn create_dns_policy(&self, body: &Value) -> Result<UnifiDnsPolicy>
pub async fn create_dns_policy(&self, body: &Value) -> Result<UnifiDnsPolicy>
POST /sites/{siteId}/dns/policies
Sourcepub async fn get_dns_policy(&self, policy_id: &str) -> Result<UnifiDnsPolicy>
pub async fn get_dns_policy(&self, policy_id: &str) -> Result<UnifiDnsPolicy>
GET /sites/{siteId}/dns/policies/{dnsPolicyId}
Sourcepub async fn update_dns_policy(
&self,
policy_id: &str,
body: &Value,
) -> Result<UnifiDnsPolicy>
pub async fn update_dns_policy( &self, policy_id: &str, body: &Value, ) -> Result<UnifiDnsPolicy>
PUT /sites/{siteId}/dns/policies/{dnsPolicyId}
UniFi requires the full create/update payload — partial updates are not supported. Caller is responsible for sending all fields.
Sourcepub async fn delete_dns_policy(&self, policy_id: &str) -> Result<()>
pub async fn delete_dns_policy(&self, policy_id: &str) -> Result<()>
DELETE /sites/{siteId}/dns/policies/{dnsPolicyId}
Trait Implementations§
Source§impl AccessListRead for UnifiClient
impl AccessListRead for UnifiClient
async fn list_blocked(&self) -> Result<Value>
async fn list_allowed(&self) -> Result<Value>
Source§impl AccessListWrite for UnifiClient
impl AccessListWrite for UnifiClient
async fn add_blocked<'a>(&'a self, _domain: &'a str) -> Result<Value>
async fn delete_blocked<'a>(&'a self, _domain: &'a str) -> Result<Value>
async fn add_allowed<'a>(&'a self, _domain: &'a str) -> Result<Value>
async fn delete_allowed<'a>(&'a self, _domain: &'a str) -> Result<Value>
Source§impl CacheRead for UnifiClient
impl CacheRead for UnifiClient
Source§impl CacheWrite for UnifiClient
impl CacheWrite for UnifiClient
Source§impl Clone for UnifiClient
impl Clone for UnifiClient
Source§fn clone(&self) -> UnifiClient
fn clone(&self) -> UnifiClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnifiClient
impl Debug for UnifiClient
Source§impl DnsVendor for UnifiClient
impl DnsVendor for UnifiClient
fn kind(&self) -> VendorKind
fn capabilities(&self) -> VendorCapabilities
Source§impl LogsRead for UnifiClient
impl LogsRead for UnifiClient
Source§impl RecordWrite for UnifiClient
impl RecordWrite for UnifiClient
Source§impl SettingsRead for UnifiClient
impl SettingsRead for UnifiClient
Source§async fn get_settings(&self) -> Result<Value>
async fn get_settings(&self) -> Result<Value>
Returns the list of UniFi sites accessible to this API key, plus the
configured site label and whether it resolves to a known site. Use
this to discover the human-readable site name to put in org_id.
Source§impl StatsRead for UnifiClient
impl StatsRead for UnifiClient
Source§impl ZoneExport for UnifiClient
impl ZoneExport for UnifiClient
Source§impl ZoneImport for UnifiClient
impl ZoneImport for UnifiClient
Source§impl ZoneRead for UnifiClient
impl ZoneRead for UnifiClient
Source§async fn list_zones(&self, _page: u32, _per_page: u32) -> Result<Value>
async fn list_zones(&self, _page: u32, _per_page: u32) -> Result<Value>
UniFi exposes no zone abstraction — there is nothing to list. Returning
unsupported lets the trait surface that clearly rather than faking a
synthetic zone list.
async fn list_records<'a>( &'a self, domain: &'a str, zone: Option<&'a str>, _options: ListRecordsOptions, ) -> Result<ListRecordsResponse>
Source§impl ZoneWrite for UnifiClient
impl ZoneWrite for UnifiClient
async fn create_zone<'a>( &'a self, _zone: &'a str, _zone_type: &'a str, ) -> Result<Value>
async fn delete_zone<'a>(&'a self, _zone: &'a str) -> Result<Value>
async fn enable_zone<'a>(&'a self, _zone: &'a str) -> Result<Value>
async fn disable_zone<'a>(&'a self, _zone: &'a str) -> Result<Value>
Auto Trait Implementations§
impl Freeze for UnifiClient
impl !RefUnwindSafe for UnifiClient
impl Send for UnifiClient
impl Sync for UnifiClient
impl Unpin for UnifiClient
impl UnsafeUnpin for UnifiClient
impl !UnwindSafe for UnifiClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more