-<p>A change to write a relation in the FGA provider.</p><p>This change expects some opts keys to build the tuple</p><p>{ destination_type:destination_id_field(value), relationship, source_type:source_id(value) }</p><ul><li><p><code class="inline">destination_type</code> :: (optional) is the fga type in the model</p></li><li><p><code class="inline">destination_id</code> :: is the realtaionship's destination field to query to get the id of the tuple</p></li><li><p><code class="inline">relationship</code> :: is the ash relationship to query to get the destination fields</p></li><li><p><code class="inline">relationship_type</code> :: (optional) is the actual fga type of the relationship (defaults to the name of the ash relationship)</p></li><li><p><code class="inline">source_type</code> :: is the fga type of the source resource</p></li><li><p><code class="inline">source_id</code> :: is the field to query to get the correct id to set in the FGA provider.</p></li></ul><p>A lot ! Let's see an example. Suppose we want to set the device <-> realm relationship:</p><ul><li><p>relationship : realm (it's called <code class="inline">realm</code> in the ash resource spec)</p></li><li><p>relationship<em>type : realm. It's realm _also</em> in the fga model! No need to set it twice</p></li><li><p>destination_type : realm, which is the same as the relationship name, no need to set it twice</p></li><li><p>destination_id : the name of the realm (our id is not astarte compatible)</p></li><li><p>source_type : device</p></li><li><p>source_id : device_id (the astarte device id, not our internal id)</p></li></ul><p>Hence:</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="n">change</span><span class="w"> </span><span class="p" data-group-id="4881085279-1">{</span><span class="nc">Edgehog.Auth.Changes.WriteRelation</span><span class="w"> </span><span class="ss">destination_id</span><span class="p">:</span><span class="w"> </span><span class="ss">:name</span><span class="p">,</span><span class="w"> </span><span class="ss">relationship</span><span class="p">:</span><span class="w"> </span><span class="ss">:realm</span><span class="p">,</span><span class="w"> </span><span class="ss">source_type</span><span class="p">:</span><span class="w"> </span><span class="ss">:device</span><span class="p">,</span><span class="w"> </span><span class="ss">source_id</span><span class="p">:</span><span class="w"> </span><span class="ss">:device_id</span><span class="p" data-group-id="4881085279-1">}</span></code></pre><p>With realm "test" and device_id "Simpl3D3vice1d" will write the tuple</p><pre><code class="fga"> {realm:test, realm, device:Simpl3D3vice1d}</code></pre>
0 commit comments