// ĠCopyright Ġ( c ) ĠCos mo ĠTech . Ċ // ĠLicensed Ġunder Ġthe ĠMIT Ġlicense . Ċ package Ġcom . cosm ote ch . connector . azure Ċ Ċ import Ġcom . azure . cosmos . models . Cos mos Container Properties Ċ import Ġcom . cosm ote ch . api . azure . C sm Azure Service Ċ import Ġcom . cosm ote ch . api . azure . findAll Ċ import Ġcom . cosm ote ch . api . azure . findById OrThrow Ċ import Ġcom . cosm ote ch . api . events . Connector Removed Ċ import Ġcom . cosm ote ch . api . exceptions . C sm Access Forbidden Exception Ċ import Ġcom . cosm ote ch . api . utils . getCurrent Authenticated UserName Ċ import Ġcom . cosm ote ch . connector . api . Connector ApiService Ċ import Ġcom . cosm ote ch . connector . domain . Connector Ċ import Ġjavax . annotation . Post Construct Ċ import Ġorg . springframework . boot . autoconfigure . condition . Conditional On Property Ċ import Ġorg . springframework . stereotype . Service Ċ Ċ @ Service Ċ @ Conditional On Property ( name Ġ= Ġ[" cs m . platform . vendor "], Ġhaving Value Ġ= Ġ" azure ", Ġmatch If Missing Ġ= Ġtrue ) Ċ internal Ġclass ĠConnector ServiceImpl Ġ: ĠC sm Azure Service (), ĠConnector ApiService Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġcore Connector Container : ĠString ĊĊĠ Ġ@ Post Construct ĊĠ Ġfun Ġinit Service () Ġ{ ĊĠĠĠ Ġthis . core Connector Container Ġ= ĊĠĠĠĠĠĠĠ Ġc sm Platform Properties . azure !!. cosmos . core Database . connectors . container ĊĠĠĠ Ġcos mos Core Database . create Container IfNot Exists ( ĊĠĠĠĠĠĠĠ ĠCosmos Container Properties ( core Connector Container , Ġ"/ id ")) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠfindAll Connectors () Ġ= Ġcos mos Template . findAll < Connector >( core Connector Container ) ĊĊĠ Ġoverride Ġfun Ġfind Connector ById ( connector Id : ĠString ): ĠConnector Ġ= ĊĠĠĠĠĠ Ġcos mos Template . findById OrThrow ( core Connector Container , Ġconnector Id ) ĊĊĠ Ġoverride Ġfun Ġregister Connector ( connector : ĠConnector ): ĠConnector Ġ{ ĊĠĠĠ Ġif Ġ( connector . azure Managed Identity Ġ== Ġtrue Ġ&& ĊĠĠĠĠĠĠĠ Ġconnector . azure Authentication With Customer App Registration Ġ== Ġtrue ) Ġ{ ĊĠĠĠĠĠ Ġthrow ĠIllegalArgumentException ( ĊĠĠĠĠĠĠĠĠĠ Ġ" Don 't Ġknow Ġwhich Ġauthentication Ġmechanism Ġto Ġuse Ġto Ġconnect Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" again st ĠAzure Ġservices . Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Both Ġazure Managed Identity Ġand Ġazure Authentication With Customer App Registration Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" cannot Ġbe Ġset Ġto Ġtrue ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġcos mos Template . insert ( ĊĠĠĠĠĠĠĠ Ġcore Connector Container , ĊĠĠĠĠĠĠĠ Ġconnector . copy ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġid Generator . generate (" connector "), Ġowner Id Ġ= ĠgetCurrent Authenticated UserName ())) ĊĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠIllegalStateException (" No Ġconnector Ġreturned Ġin Ġresponse : Ġ$ connector ") ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġunregister Connector ( connector Id : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġconnector Ġ= Ġthis . find Connector ById ( connector Id ) ĊĠĠĠ Ġif Ġ( connector . owner Id Ġ!= ĠgetCurrent Authenticated UserName ()) Ġ{ ĊĠĠĠĠĠ Ġ// ĠTODO ĠOnly Ġthe Ġowner Ġor Ġan Ġadmin Ġshould Ġbe Ġable Ġto Ġperform Ġthis Ġoperation ĊĠĠĠĠĠ Ġthrow ĠC sm Access Forbidden Exception (" You Ġare Ġnot Ġallowed Ġto Ġdelete Ġthis ĠResource ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġcos mos Template . delete Entity ( core Connector Container , Ġconnector ) ĊĠĠĠ Ġthis . event Publisher . publish Event ( Connector Removed ( this , Ġconnector Id )) ĊĠ Ġ} Ċ } Ċ