<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Janek Fellien on Medium]]></title>
        <description><![CDATA[Stories by Janek Fellien on Medium]]></description>
        <link>https://medium.com/@janekf?source=rss-8c7639e08acd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-cqzZdRV0GjWRQpD.jpg</url>
            <title>Stories by Janek Fellien on Medium</title>
            <link>https://medium.com/@janekf?source=rss-8c7639e08acd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:50:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@janekf/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Service Integration with Project Drasi]]></title>
            <link>https://medium.com/medialesson/service-integration-with-project-drasi-844c35817ef6?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/844c35817ef6</guid>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[complex-event-processing]]></category>
            <category><![CDATA[project-drasi]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 09:50:51 GMT</pubDate>
            <atom:updated>2025-04-14T09:50:51.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NUybB_NiitraNIY5" /></figure><p>Since IT has been around for a few years, it is clear that there are systems developed in times when distributed systems were not even considered. It may also be the case that a software system was originally designed as a standalone system. But now some time has passed, and we in IT have realized that monoliths are not so cool, or a business model has changed, and it is now necessary to connect the legacy system with new services.</p><p>So far, so good. Typically, in software development, we think it’s a good idea to modernize an existing system. Unfortunately, or fortunately, depending on your perspective, it is not always possible to redo everything. I am thinking of ancient systems whose programming languages are no longer even known or systems that are so critical that the principle “never touch a somewhat running system” applies.</p><p>What do we do now? Rewriting is not an option, changing is also not feasible, but integration is mandatory.</p><p>Fortunately, a silver lining appears on the horizon that aims to address this specific use case. Project Drasi is still in a very early development phase and should definitely not be used in production yet (as of April 2025). Nevertheless, it is worth a look to decide whether it might fit into your existing system landscape.</p><p>The approach in this project is as simple as it is ingenious. Using so-called Sources, Continuous Queries, and Reactions, you can continuously query an existing system for data changes without source code. All this happens in a standalone Kubernetes cluster and with a small number of configuration files. Actually, one should say that they are descriptions. You describe which Source you want to monitor, the data that changes within it, and then describe the data sink where the changes are announced in the form of notifications.</p><p>This strongly reminds me of Complex Event Processing, which has been known since the 1950s and was integrated into various Message/Service Bus solutions in the early 2000s. Unfortunately, these solutions were so complex ;) that they are no longer found today. The concept behind CEP is simple to explain. If something changes in a data set from Service A, I would like Service B to receive a message about it to react accordingly. Now, the data sources can be diverse. How about this idea: If a new record is added to table Y in database X, and 10 minutes later a file is placed in the FTP directory with the same key as the new record, then take the data from columns Y1, Y3, and Y5 as well as the fifth line from the file in the FTP directory and send this data to Service A. Sounds complex, but it is a harsh reality. Drasi is designed for such use cases.</p><p>Unfortunately, Drasi cannot yet read from an FTP directory or detect changes there. Nevertheless, I would like to show what is possible with the current state of development.</p><h3><strong>Prerequisites</strong></h3><p>To work with Drasi, a few preparations are necessary.</p><p><strong>1.) Azure CLI</strong></p><p>You need the Azure CLI to configure everything properly. Check out <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli">here</a> to see what works best for you.</p><p><strong>2.) Installing an Azure Kubernetes Service</strong></p><p>It is sufficient to set up an Azure Kubernetes Service that will later host the Drasi pods. <a href="https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli">Here</a> you will find a good description of how to set up a cluster using the Azure CLI.</p><p><strong>3.) Installing the Drasi CLI</strong></p><p>Unfortunately, the project is still in its infancy, so there is currently (as of March 2025) no package for your package manager to install the Drasi CLI. However, this can be done quite well with a script.</p><p><strong><em>macOS</em></strong></p><pre>curl -fsSL https://raw.githubusercontent.com/drasi-project/drasi-platform/main/cli/installers/install-drasi-cli.sh | /bin/bash</pre><p><strong><em>Windows PowerShell</em></strong></p><pre>iwr -useb &quot;https://raw.githubusercontent.com/drasi-project/drasi-platform/main/cli/installers/install-drasi-cli.ps1&quot; | iex</pre><p><strong><em>Linux</em></strong></p><pre>wget -q &quot;https://raw.githubusercontent.com/drasi-project/drasi-platform/main/cli/installers/install-drasi-cli.sh&quot; -O - | /bin/bash</pre><p><strong>4.) Setting the Kubectl Context</strong></p><p>To configure Drasi correctly, it is necessary to set the context of your Kubernetes cluster with kubectl. For this, you first need the credentials of your cluster. Enter the following commands in the console or terminal. Of course, use the resource name where the cluster was set up, as well as the subscription ID. Both can be found in the portal when you view the overview page of your cluster.</p><p><strong><em>Retrieving AKS Cluster Credentials</em></strong></p><pre>az login<br>az account set - subscription &lt;your subscription id&gt;<br>az aks get-credentials - resource-group &lt;your resource group&gt; - name &lt;your cluster name&gt;</pre><p><strong><em>Setting the Kubectl Context</em></strong></p><pre>kubectl config use-context &lt;your cluster name&gt;</pre><p><strong>5.) Installing Drasi in the Cluster</strong></p><p>The drasi init command starts the setup of the environment. Feel free to watch the output. It will show you which Sources and Reactions already exist. It is quite possible that I am no longer up to date here and significantly more is now available 😉</p><p><strong>Optional: VS Code Extension</strong></p><p>You can make your life much easier by installing the Drasi and Kubernetes extensions in VS Code. With these extensions, you will have access to many features that would otherwise be somewhat cumbersome to use in the console. For example, reading the log stream is much easier, as are the steps for the next section.</p><h3><strong>Defining a Source</strong></h3><p>Sources refer to anything from which data changes can be detected. Currently, this is very limited to:</p><ul><li>PostgreSQL</li><li>SQL Server</li><li>Azure CosmosDB with Graph API (Gremlin)</li><li>Azure EventHub</li><li>Microsoft Dataverse</li><li>Kubernetes</li></ul><p>I will describe the individual configurations in further blog posts because otherwise, it would really get too long. 😂</p><p>A Source, like all other configurations, is described in a YAML file. Once this is completed, it can be applied using the following command:</p><pre>drasi apply -f &lt;configuration file name.yaml&gt; -n &lt;drasi-namespace&gt;</pre><p>Note: The drasi-namespace was created during installation. Check the list of namespaces in your cluster to see which one is currently active, and switch to the drasi-namespace if necessary. This will make further setup easier. How do you do that, you ask? I do it using the Kubernetes extension in VS Code, where I list the namespaces, select the namespace, and then choose “Use Namespace” from the context menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*qCePid7BJir_tpwRz916Uw.png" /><figcaption>Select Kubernetes Namespace</figcaption></figure><h3><strong>Defining a Query</strong></h3><p>To compare Drasi with Complex Event Processing, it requires the ability to analyze data from multiple sources on the fly and forward it if necessary. The key element here is Continuous Queries. They describe which Source is being listened to and which data is subsequently forwarded. What I find particularly exciting is that <a href="https://drasi.io/reference/query-language/">Cypher</a> from the graph database world is used for this. After some familiarization, it made sense to me to use this query language. Each data source, whether a Drasi Source or a table within a Source, represents a node that has a specific relationship to other data.</p><p>At this point, I do not want to provide an introduction to Cypher but only describe how to set up a Continuous Query.</p><p>A Query YAML contains references to all Sources used in the query. Additionally, of course, the query itself. The query describes the relationship of the data and its output. I will describe this in more detail in another blog post.</p><p>Once the YAML is created, it is also applied to Drasi:</p><pre>drasi apply -f &lt;query file name.yaml&gt; -n &lt;drasi-namespace&gt;</pre><h3><strong>Setting Up a Reaction</strong></h3><p>The final step is setting up the Reactions. In my opinion, the name is somewhat misleading because it does not react to something but rather defines a target where the query data is sent. It would be better to call it Sink or Target, but we are still at the very beginning of this project. ;)</p><p>Currently, the following Reactions are available:</p><ul><li>Azure Event Grid</li><li>Azure Storage Queue</li><li>Azure SignalR</li><li>AWS EventBridge</li><li>Debezium</li><li>Drasi Debug and Result</li><li>Gremlin Common (Azure Cosmos DB, Apache TinkerPop, and JanusGraph)</li><li>Stored Procedure (MS-SQL, PostgreSQL, MySQL)</li></ul><p>Again, this list will likely grow significantly.</p><p>A Reaction configuration describes the type as well as the query it reacts to. Depending on the type chosen, the corresponding parameters are specified, such as database credentials, etc. Once the configuration is complete, it is applied to Drasi using the `drasi apply` command.</p><pre>drasi apply -f &lt;reaction file name.yaml&gt; -n &lt;drasi-namespace&gt;</pre><h3><strong>Note on Security</strong></h3><p>In many cases, credentials for Sources or Reactions are required. These can be specified in plain text or in the `kubectl create secret` settings. The latter is, of course, much better.</p><p>Here is an example of how it can be done with a password for a database:</p><pre>kubectl create secret generic storedproc-creds - from-literal=password=&lt;db-password&gt; -n drasi-system</pre><h3><strong>Conclusion</strong></h3><p>With just a few steps, an existing system can be set up so that its changes are propagated to other systems. This allows these systems, which were not designed for distributed architectures due to their age, to be integrated into modern architectures without code changes. This secures investments and avoids the costly redevelopment of functioning applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=844c35817ef6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/service-integration-with-project-drasi-844c35817ef6">Service Integration with Project Drasi</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding an API to an Azure hosted React Static Web App]]></title>
            <link>https://medium.com/medialesson/adding-an-api-to-an-azure-hosted-react-static-web-app-f8f60477845c?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8f60477845c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 07:42:26 GMT</pubDate>
            <atom:updated>2024-07-02T07:42:26.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Handshake of two robot arms, one has an API tattoo" src="https://cdn-images-1.medium.com/max/1024/0*YTnvsF2JjFWkUWNg" /></figure><p>In previous articles, I have described how to build a React app as a Static Web App (SWA) (<a href="https://medium.com/medialesson/how-to-create-a-react-app-as-static-web-app-for-azure-40be32c7ccba">Create a React App</a>, <a href="https://medium.com/medialesson/how-to-structure-a-react-app-6dea8c260261">Give the App a Structure</a> and <a href="https://medium.com/medialesson/navigation-in-a-react-static-web-app-df89541d87f9">How to navigate in a React App</a>). So far, it has been a simple website that wouldn’t make much sense to be provided as a React app. With this post, I want to give the app a purpose and add an API behind it.</p><p>To follow along with my explanations, you will need my <a href="https://github.com/jfellien/my-react-app-sample">GitHub repository</a> for this tutorial.</p><h3><strong>Static Web App with an API</strong></h3><p>In the first part of the tutorial, I set up the development environment for the React app, including the SWA CLI and its extension in VS Code. Now, the extension finally comes into play. Using F1 in VS Code, I invoke the commands and select the command “<em>Azure Static Web App: Create HTTP Function</em>”. You may be prompted to install the Azure Functions extension in VS Code, which is a great idea. 😁</p><figure><img alt="Create HTTP Function Command" src="https://cdn-images-1.medium.com/max/1024/1*CEIi4VYlpEcZbPVUra3Fvw.png" /></figure><p>I name my function “<em>GetTickets</em>”, which will fetch all ticket types that can be displayed on the website.</p><figure><img alt="Enter function name" src="https://cdn-images-1.medium.com/max/1024/1*SFto9YNOMwb_n7esUzOc4g.png" /></figure><p>Then I choose C# as the language because, although I would have preferred to do the tutorial with JavaScript, at the time of writing this blog post, the latest version of Functions and JavaScript in Static Web Apps was not yet functional.</p><figure><img alt="Select function language" src="https://cdn-images-1.medium.com/max/1024/1*7VnA3Pzp9e9IJqb8dkC4PQ.png" /></figure><p>Finally, I enter the namespace for my function and then I am prompted to set the access rights.</p><figure><img alt="Select access rights" src="https://cdn-images-1.medium.com/max/1024/1*tq352pfQR6szHO05u2cQJw.png" /></figure><p>It should be noted that “<em>Anonymous</em>” is the best choice for access rights. Securing the API will be done at a different level. The other options, “<em>Function</em>” and “<em>Admin</em>”, do not make sense in a SWA environment and can be ignored.</p><p>The SWA extension completes its work by creating the function. It creates a new folder called ‘<em>api</em>’ in the root directory of the app and copies the function app into it. For now, I leave all the settings as they were generated.</p><p>One thing that bothers me a little about this template is that it still uses .NET version 6, whereas version 8 is much better for Function Apps.</p><p>To let my React app know that an API is available, I modify the SWA config and add the property &quot;apiLocation&quot;: &quot;/api&quot; in the <em>swa-cli.config.json</em> file. Now, the SWA CLI will check the contents of the folder and builds the API accordingly.</p><p>To test if everything has gone well so far, I start the app locally with the command:</p><pre>&gt; swa start</pre><p>The output now shows a message that a function has been found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJvIQJlijTXoiF2pQ_Xj9A.png" /></figure><p>You can open the address <a href="http://localhost:7071/">http://localhost:7071</a> in your browser. You will see that there is a function app there. And if you also want to access <a href="http://localhost:7071/api/GetTickets,">http://localhost:7071/api/GetTickets,</a> you will see that the function app has been successfully set up and is ready.</p><h3><strong>React App with an API</strong></h3><p>I have made some changes to the generated “<em>GetTickets</em>” function so that it returns two tickets that I will display on the website.</p><pre>public static class GetTickets<br>{<br>    [FunctionName(nameof(GetTickets))]<br>    public static IActionResult Run(<br>        [HttpTrigger(<br>            AuthorizationLevel.Anonymous, <br>            nameof(HttpMethods.Get), <br>            Route = &quot;tickets&quot;)] <br>        HttpRequest req,<br>        ILogger log)<br>    {<br>        log.LogInformation(&quot;C# HTTP trigger function processed a request.&quot;);<br>        List&lt;Ticket&gt; tickets = new () {<br>            new() {<br>                Name = &quot;One Day Ticket&quot;,<br>                ValidFor = &quot;one day&quot;,<br>                Price = 100<br>            },<br>            new() {<br>                Name = &quot;Two Day Ticket&quot;,<br>                ValidFor = &quot;two days&quot;,<br>                Price = 200<br>            }<br>        };<br>        <br>        return new OkObjectResult(tickets);<br>    }<br>}</pre><p>To display these tickets on the website, I call the API in my Tickets component as follows:</p><pre>// Tickets.js<br><br>...<br>const tickets = await (await fetch(`/api/tickets`)).json();<br><br>const renderTicket = (ticket) =&gt; {...}<br><br><br>function Tickets() {<br><br>    return (<br>        &lt;&gt;<br>          ...<br>          {tickets.map(renderTicket)}<br>          ...<br>        &lt;/&gt;<br>    );<br>}<br></pre><p>I use the ‘<em>tickets</em>’ object in the return value of the component and have created the `<em>renderTicket</em>` function so that I can convert a list of data into HTML with the same formatting.</p><p>Now, when I look at my website, not much has changed. The tickets are displayed correctly, but now they come from the API. Wonderful. 🚀</p><p>With that, I conclude this tutorial and wish you a lot of fun exploring further possibilities with React.</p><p>Here you can find the repository to this tutorial: <a href="https://github.com/jfellien/my-react-app-sample">GitHub</a>. Use the commits to follow the changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8f60477845c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/adding-an-api-to-an-azure-hosted-react-static-web-app-f8f60477845c">Adding an API to an Azure hosted React Static Web App</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigation in a React Static Web App]]></title>
            <link>https://medium.com/medialesson/navigation-in-a-react-static-web-app-df89541d87f9?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/df89541d87f9</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Wed, 26 Jun 2024 06:18:33 GMT</pubDate>
            <atom:updated>2024-07-01T15:05:21.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QxZ7qp7kKyv3zFzR" /></figure><p>After setting up a React app as a Static Web App (SWA) in <a href="https://medium.com/medialesson/how-to-create-a-react-app-as-static-web-app-for-azure-40be32c7ccba">part 1</a> of this tutorial and setting up the basic structure in <a href="https://medium.com/medialesson/how-to-structure-a-react-app-6dea8c260261">part 2</a>, I would like to write about navigation in a React app. I find this part quite important because I noticed in a personal project that navigation with React is not as straightforward as expected.</p><p>To follow along with my changes, you will need to clone my <a href="https://github.com/jfellien/my-react-app-sample">GitHub Repository</a> for this tutorial.</p><h3><strong>Static Web App on Azure</strong></h3><p>The mentioned personal project was hosted as a GitHub Page for a while. Moving to Azure caused a negative side effect that was quickly resolved. Unfortunately, the documentation was not clear enough for me to understand.</p><p>The problem is that a Static Web App with React is essentially a dynamic page, and a deep link, which is a link with a path, leads to nowhere because there is no actual HTML page. Okay, now I sound as complicated as the SWA documentation. Let me simplify it.</p><p>Imagine you have a website that can be found at the domain <a href="https://mypage.org./">https://myPage.org.</a> This website has a home page, an imprint page, and a GDPR notice. These are essentially three pages that can be visited through the respective paths /home, /imprint, and /gdpr on the domain <a href="https://mypage.org./">https://myPage.org.</a> In React, these pages are usually created as components and later called through a ‘Router’ in the app.</p><p>Here’s an complete example:</p><pre>import { Routes, Route } from &#39;react-router-dom&#39;;<br>import Home from &#39;../pages/Home&#39;;<br>import Imprint from &#39;../pages/Imprint&#39;;<br>import GDPR from &#39;../pages/GDPR&#39;;<br><br>function Pages() {<br>  return (<br>    &lt;Routes&gt;<br>      &lt;Route path=&quot;/&quot; exact element={&lt;Home /&gt;} /&gt;<br>      &lt;Route path=&quot;/Home&quot; exact element={&lt;Home /&gt;} /&gt;<br>      &lt;Route path=&quot;/Imprint&quot; exact element={&lt;Imprint /&gt;} /&gt;<br>      &lt;Route path=&quot;/GDPR&quot; exact element={&lt;GDPR /&gt;} /&gt;<br>    &lt;/Routes&gt;<br>  )<br>}<br><br>export default Pages;</pre><p>This ‘Pages’ component is registered in the app and loads the respective component based on the requested route. Unfortunately, the generated app doesn’t know about these routes, the underlying web server doesn’t know either, and there are no HTML pages. This leads to these deep links /home, /imprint, and /gdpr resulting in a 404 page.</p><p>This is easily solved in a SWA by placing a file named ‘staticwebapp.config.json’ in the root directory of the app and adding the following property:</p><pre>&quot;navigationFallback&quot;: {<br>        &quot;rewrite&quot;: &quot;/index.html&quot;<br>    }</pre><p>Now all the routes of the app are accessible. I find this much simpler compared to the GitHub Pages solution.</p><blockquote>By the way, it’s worth checking out the <a href="https://learn.microsoft.com/en-us/azure/static-web-apps/configuration">documentation</a> for more configuration options for this SWA config.</blockquote><h3><strong>Adding App Navigation</strong></h3><p>In addition to the page navigation, my sample app will have sections on the main page that can be jumped to. Here’s how it looks in the concept:</p><p>Home -&gt; Page (Footer, NavigationBar)<br>GDPR -&gt; Page (Footer)<br>Tickets -&gt; Section (NavigationBar)</p><p>The navigation is done through links, but they have different types. When it comes to sections, they are called hash links, otherwise, they are classic links. For the app, this means that additional packages are required. I install them with:</p><pre>&gt; npm install --save react-router-dom<br>&gt; npm install --save react-router-hash-link</pre><p>Now I have access to the <em>BrowserRouter</em> component from React. I need to use this component in my <em>Pages</em> and <em>App</em> components. I will update the <em>App</em> component as follows:</p><pre>...<br>import { BrowserRouter as Router } from &#39;react-router-dom&#39;;<br>...<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Router&gt;<br>        &lt;NavigationBar /&gt;<br>        &lt;Hero /&gt;<br>        &lt;Tickets /&gt;<br>        &lt;Footer /&gt;<br>      &lt;/Router&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Please do not apply these changes yet, as I am not finished with the App.js file. The <em>NavigationBar</em>, <em>Hero</em>, <em>Tickets</em>, and <em>Footer</em> components are still included here. I will rearrange the components to create a better structure.</p><p>The <em>Router</em> now takes care of understanding the path in the URL or the hash link and then routing correctly.</p><p><strong>Page Navigation</strong></p><p>First, I will set up the page navigation. This means that in the <em>Footer</em>, there will be two links to subpages, and on the subpages, I want the menu to navigate back to the main page.</p><p>Footer -&gt; Imprint<br>Footer -&gt; GDPR<br>Imprint -&gt; Home<br>GDPR -&gt; Home</p><blockquote>I have added tailwindcss to the project to easily apply styling. 😊<br>Here is the guide for set up: <a href="https://tailwindcss.com/docs/guides/create-react-app">Install Tailwind CSS with Create React App</a>.</blockquote><p>As seen in the example above, I create a Pages component to manage the routes for the subpages.</p><pre>import { Routes, Route } from &#39;react-router-dom&#39;;<br>import Home from &#39;../pages/Home&#39;;<br>import Imprint from &#39;../pages/Imprint&#39;;<br>import GDPR from &#39;../pages/GDPR&#39;;<br><br>function Pages() {<br>  return (<br>    &lt;Routes&gt;<br>      &lt;Route path=&quot;/&quot; exact element={&lt;Home /&gt;} /&gt;<br>      &lt;Route path=&quot;/Home&quot; exact element={&lt;Home /&gt;} /&gt;<br>      &lt;Route path=&quot;/Imprint&quot; exact element={&lt;Imprint /&gt;} /&gt;<br>      &lt;Route path=&quot;/GDPR&quot; exact element={&lt;GDPR /&gt;} /&gt;<br>    &lt;/Routes&gt;<br>  )<br>}<br><br>export default Pages;</pre><p>As you can see, a <em>Home</em> page is called when someone visits the website or the /Home path. This Home page now takes over the role of the <em>App</em> component and looks like this:</p><pre>import Hero from &quot;../components/Hero&quot;;<br>import NavigationBar from &quot;../components/NavigationBar&quot;;<br>import Tickets from &quot;../components/Tickets&quot;;<br><br>function Home() {<br>  return (<br>    &lt;&gt;<br>      &lt;NavigationBar /&gt;<br>      &lt;Hero /&gt;<br>      &lt;Tickets /&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Home;</pre><p>And the <em>App</em> component now looks like this:</p><pre>import &#39;./App.css&#39;;<br>import { BrowserRouter as Router } from &#39;react-router-dom&#39;;<br>import Footer from &#39;./components/Footer&#39;;<br>import Pages from &#39;./components/Pages&#39;;<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Router&gt;<br>        &lt;Pages /&gt;<br>        &lt;Footer /&gt;<br>      &lt;/Router&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default App;</pre><p>The <em>App</em> component now displays Pages and the Footer. The Pages can be <em>Home</em>, <em>GDPR</em>, or <em>Imprint</em>.</p><p><strong>Hash Navigation</strong></p><p>If I only want to navigate between sections on a single page, I set up a hash navigation that refers to elements with a matching ID. For the <em>Home</em> page, the menu items <em>Home</em> and <em>Tickets</em> are involved.</p><p>In the <em>NavigationBar</em>, I have a <em>div</em> tag with the ID ‘#top’. I refer to it with a HashLink:</p><pre>&lt;HashLink smooth to=&quot;#top&quot;&gt;<br>  &lt;div id=&quot;mnu-home&quot; className=&quot;...&quot;&gt;<br>    Home<br>  &lt;/div&gt;<br>&lt;/HashLink&gt;</pre><p>Thanks to the <em>BrowserRouter</em>, the app now knows that I want to navigate to the ‘top’ element on the same page, and it does it smoothly. 😉 I do the same for the <em>Ticket</em> section.</p><pre>&lt;HashLink id=&quot;mnu-tickets&quot; smooth to=&quot;#tickets&quot; className=&quot;...&quot;&gt;<br>  Tickets<br>&lt;/HashLink&gt;</pre><p>The ID for this section is, of course, in the <em>Tickets</em> component.</p><pre>...<br>  &lt;section id=&quot;tickets&quot; className=&quot;bg-gray-300&quot;&gt;<br>...</pre><p>But what doesn’t work is using the same <em>NavigationBar</em> in the Pages as in the <em>Home</em> page. The reason is simple. Hash links don’t work across pages, so I need a different <em>NavigationBar</em> for the Pages. For this, I create a copy of <em>NavigationBar</em> call it <em>PageNavigationBar</em> and convert the <em>HashLink</em> to the <em>Home</em> page into a Link, and removed the <em>Ticket</em> item from the <em>NavigationBar</em>.</p><p>Finally, I add the <em>PageNavigationBar</em> to my Pages.</p><pre>// Imprint.js:<br>import PageNavigationBar from &quot;../components/PageNavigationBar&quot;;<br><br>function Imprint() {<br>  return (<br>    &lt;&gt;<br>      &lt;PageNavigationBar /&gt;<br>      ...<br>}<br><br>---<br><br>// GDPR.js:<br>import PageNavigationBar from &quot;../components/PageNavigationBar&quot;;<br><br>function GDPR() {<br>  return (<br>    &lt;&gt;<br>      &lt;PageNavigationBar /&gt;<br>        ...<br>}</pre><p>I hope you enjoyed this tutorial. In the next and final part, I will cover connecting an API to my Static Web App.</p><p>Here you can find the repository to this tutorial: <a href="https://github.com/jfellien/my-react-app-sample">GitHub</a>. Use the commits to follow the changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df89541d87f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/navigation-in-a-react-static-web-app-df89541d87f9">Navigation in a React Static Web App</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to structure a React app]]></title>
            <link>https://medium.com/medialesson/how-to-structure-a-react-app-6dea8c260261?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dea8c260261</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 09:03:02 GMT</pubDate>
            <atom:updated>2024-06-26T06:17:20.265Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FZSgm-DXUgMGe-Vw" /></figure><p>In <a href="https://medium.com/medialesson/how-to-create-a-react-app-as-static-web-app-for-azure-40be32c7ccba">part 1</a> of my tutorial, I started lifting a React app as a Static Web App into the Azure Cloud. This app doesn’t have any functionality or design yet. In this part of my tutorial, I will structure my app. A later following tutorial will add an API to the app.</p><h3><strong>Website structure</strong></h3><p>I have chosen a classic structure for a website, with a navigation, a hero section, an area where products can be selected, and a footer. The navigation will always be visible, while the other sections can be scrolled out of the screen.</p><figure><img alt="Application structure in Navigation, Hero, Tickets and Footer, gray highlighted" src="https://cdn-images-1.medium.com/max/1024/1*_kCjCEnsBiP1zXB_J1JzUw.png" /></figure><p>The navigation allows navigating directly to different sections of the webpage. The <em>Hero</em> section displays a welcome message and possibly a claim. The <em>Tickets</em> section displays products linked to an ordering system. The <em>Footer</em> contains some static information.</p><p>First, let’s examine the structure and derive the initial components.</p><h3><strong>React components</strong></h3><p>React uses components for better structuring and reusability. They are defined as JavaScript functions and allow for custom logic. I see a clear advantage in using components, as they allow me to build the website in a clean way.</p><p>This construct serves as the basis for all my components. While it’s not mandatory to write the code exactly like this, it’s the easiest way for me.</p><pre>function MySampleComponent() {<br>  return (<br>    &lt;&gt;<br>      … add your HTML stuff here …<br>    &lt;/&gt;<br>  );<br>}<br>export default MySampleComponent;</pre><p>A component always starts with a capital letter. Although this contradicts JavaScript conventions, it’s acceptable. You can start the filename with a lowercase letter if you prefer. 😉</p><p>The function always returns a piece of HTML, and since React expects JSX (a syntax extension for JavaScript), we wrap the return value in an empty HTML tag (`&lt;&gt;&lt;/&gt;`). JSX ensures that only one HTML tag is returned. The empty tag guarantees that.</p><p>To use this component, I reference it in the corresponding file.</p><pre>import MySampleComponent from &quot;./components/MySampleComponent&quot;</pre><p>And in the code, I use the component like an HTML element.</p><pre>&lt;MySampleComponent /&gt;</pre><p>At this point, the content of my component will be rendered.</p><h3><strong>Website development</strong></h3><p>The entry point for our website is `index.js`. This file sets up the framework for the entire application. It starts by finding the root element of the `index.html` page and then renders all our components inside it. The first component to be rendered here is the `App`. This is where I will add my components and build the website. However, you can also do this directly in `index.js`.</p><p>To show quick results, I create the four components of the planned structure in the `components` folder. These are <em>NavigationBar</em>, <em>Hero</em>, <em>Tickets</em>, and <em>Footer</em>. All components follow the same pattern. (Note: <em>NavigationBar </em>will change later)</p><pre>function Hero() {<br>  return (<br>    &lt;&gt;<br>      &lt;section id=&quot;hero&quot;&gt;<br>        This is the Hero section<br>      &lt;/section&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Hero;</pre><p>Now I replace the template code in `App.js` and add the components.</p><pre>import &#39;./App.css&#39;;<br>import NavigationBar from &#39;./components/NavigationBar&#39;;<br>import Hero from &#39;./components/Hero&#39;;<br>import Tickets from &#39;./components/Tickets&#39;;<br>import Footer from &#39;./components/Footer&#39;;<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;NavigationBar /&gt;<br>      &lt;Hero /&gt;<br>      &lt;Tickets /&gt;<br>      &lt;Footer /&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default App;</pre><p>After starting the SWA Emulator with</p><pre>&gt; swa start</pre><p>in the application folder, I see the following result in the browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*aZIWzTU2F1g55Hc2_Jc53A.png" /></figure><p>With this, the overall structure of the application is created. In next posts, I will continue building this page and adding <a href="https://medium.com/medialesson/navigation-in-a-react-static-web-app-df89541d87f9">navigation</a>, an API, and some logic.</p><p>Here you can find the repository to this tutorial: <a href="https://github.com/jfellien/my-react-app-sample">GitHub</a>. Use the commits to follow the changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dea8c260261" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/how-to-structure-a-react-app-6dea8c260261">How to structure a React app</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a React App as Static Web App for Azure]]></title>
            <link>https://medium.com/medialesson/how-to-create-a-react-app-as-static-web-app-for-azure-40be32c7ccba?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/40be32c7ccba</guid>
            <category><![CDATA[azure-static-web-app]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Thu, 20 Jun 2024 07:34:00 GMT</pubDate>
            <atom:updated>2024-06-24T08:32:09.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WKiad1Xuc2XqUGzI" /></figure><p>Why is this article necessary instead of just referring to the documentation at Microsoft? Quite simply, when I tried it with the documentation, I unfortunately found that not everything worked as desired.</p><h3>Preparation</h3><p>To develop an Azure Static Web App, it is useful to install the swa-cli. But not only that, there are other preparations to be done. Here is my setup, with which I developed this example:</p><ul><li>Visual Studio Code (VSCode)</li><li>Azure Static Web Apps Extension for Visual Studio Code (SWA Extension)</li><li>Node.js 18x</li></ul><p>Using the SWA Extension, the SWA CLI can be installed. To do this, simply run the command in VSCode:</p><figure><img alt="Install or Update Static Web Apps" src="https://cdn-images-1.medium.com/max/804/1*aP45kZhJyFjnsBEKzCyuDA.png" /></figure><h3>Project Setup</h3><p>Usually, as Microsoft offers, you can clone a SWA from an existing GitHub repository. However, since it seems that the developers are not interested in maintenance, you would be copying a pretty old version and then doing a lot of post-processing. That’s why I want to manually set up the project here.</p><p>First, I set up the packages I need for the React app. To do this, I run the following commands in the terminal in the root directory of my project:</p><pre>&gt; npx create-react-app my-sample</pre><p>It may ask to installcreate-react-appfirst. You can confirm that.</p><p>After a while, the project is set up in the my-sample directory and I can start setting it up as a SWA. To do this, I navigate to the my-sample directory and run the command in the terminal:</p><pre>&gt; swa init</pre><p>I simply confirm the questions in the console with Enter, because the initial configuration is sufficient for me.</p><p>To see the result, I run the command:</p><pre>&gt; swa start</pre><p>This starts the Static Web App Emulator and allows me to test the web app locally. I can now start and see the generated React app in the browser at the URL http://localhost:4280.</p><h3>App Deployment</h3><p>As the final step of this tutorial, I want to deploy the app to the cloud.</p><p>There are several ways available for deployment. One option is to directly perform a swa deploy from the SWA CLI. That is theoretically good, but not in the DevOps mindset. Therefore, I will not do that. My approach is not strictly DevOps either, but at least I have an automatic deployment in the end.</p><p>The first step is to push the code to a GitHub repository. You can find my code here: <a href="https://github.com/jfellien/my-react-app-sample">my-sample</a>. Now I switch to the <a href="https://portal.azure.com/">Azure Portal</a> and manually set up a Static Web App here. Normally, I would do this using a pipeline and the Bicep Language, but that goes beyond the scope of this tutorial.</p><p>In the <a href="https://portal.azure.com/">Azure Portal</a>, I set up a resource group and then add a Static Web App here. (I hope you have already created resources in the portal, because I don’t want to show these steps here either). I give the SWA resource the name ‘web-my-react-sample’. Choose a name that you like 🙂. I use the <strong>Free plan</strong> type because it is okay-ish for this example.</p><p>For the deployment details, I choose GitHub as the source, but as you can see, other repositories are also supported. In the case of GitHub and Azure DevOps, the portal is able to create a working pipeline by itself, which is fantastic.</p><p>I use the same account that I used to push the source code. Finally, I select my organization, repository, and branch from which the deployment will be done.</p><p>The wizard is now able to determine what type of SWA it is. In my case, all configuration data was set correctly. However, they can still be changed later.</p><figure><img alt="Create Static Web App screen" src="https://cdn-images-1.medium.com/max/788/1*ZE_R9m80iFWJ8-0BzxkJQA.png" /></figure><p>I confirm my details with ‘Review + create’ and now let the resource be set up. Once the resource is set up, the deployment process begins. A deployment pipeline was automatically created and added to the repository. In this case, using GitHub Actions.</p><p>In the overview of my Static Web App, I can either click on ‘Visit your site’ or the generated URL. And behold, my app is deployed. Fantastic.</p><figure><img alt="Deployed ReactJs Web App in Browser Window" src="https://cdn-images-1.medium.com/max/1024/1*IInn5JFBEwnVZ5cAXhdfRg.png" /></figure><p>I hope this tutorial is helpful for you. In a <a href="https://medium.com/@janekf/how-to-structure-a-react-app-6dea8c260261">second part</a>, I want to talk about the React App Development itself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40be32c7ccba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/how-to-create-a-react-app-as-static-web-app-for-azure-40be32c7ccba">How to create a React App as Static Web App for Azure</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditional Values in Azure Pipelines]]></title>
            <link>https://medium.com/medialesson/conditional-values-in-azure-pipelines-db5cebb84875?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/db5cebb84875</guid>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[azure-pipelines]]></category>
            <category><![CDATA[condition]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Wed, 27 Mar 2024 08:55:24 GMT</pubDate>
            <atom:updated>2024-03-27T08:55:24.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="An artificial pipeline in a wood with a valve and dividers" src="https://cdn-images-1.medium.com/max/1024/0*DiNA5hrVxP3oxYF1" /></figure><p>In some cases, you may want to change the value of an Azure Pipeline variable depending on the environment data. When I was looking for a way to do this, I couldn’t find many examples, so I’ll describe my solution here, maybe it will help you too.</p><p>Normally, a condition is prepared as follows.</p><pre>  variables:<br>    - name: AZ_IS_MAIN_DEPLOYMENT<br>      value: $[eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;)]</pre><p>Here, the Variable AZ_IS_MAIN_DEPLOYMENT gets a true or false, depending on the branch. In later steps you use the variable to control tasks, steps and so on by set the conditionvalue. But in my underlying use case, I needed a condition where the value of my variable gets an production or dev value (Btw, it was for the deployment slot of a Static Web App 😉)</p><p>My solution is to set a variable value by use the key word if in a kind of attribute on top of the variable value.</p><pre>variables:<br>  - name: AZ_DEPLOYMENT_ENV_NAME<br>    ${{ if eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;) }}:<br>      value: production<br>    ${{ else }}:<br>      value: dev</pre><p>Very important is the indentation of value here. It will not work, if it’s not set.</p><p>I’ve not tested a else if condition yet. Feel free to do so and let me know if it works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db5cebb84875" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/conditional-values-in-azure-pipelines-db5cebb84875">Conditional Values in Azure Pipelines</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Role Assignment with Azure Resource SDK]]></title>
            <link>https://medium.com/medialesson/role-assignment-with-azure-resource-sdk-0cb273164d23?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/0cb273164d23</guid>
            <category><![CDATA[bicep]]></category>
            <category><![CDATA[azure-resource-manager]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 13:13:46 GMT</pubDate>
            <atom:updated>2024-03-21T13:13:46.029Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMHXHnp0ZQo4HRXYd_JOcw.png" /></figure><p>I love <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep">bicep</a>. I really love <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep">bicep</a>. I love it to deploy resources in the Azure Cloud. It’s simple to read and also simple to manage. <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep">Bicep </a>takes the JavaScript-JSON-styled files and transforms it into ARM templates, which is needed to get things up and running in the Cloud. It works fine for almost all cases. But sometimes it’s necessary to switch to another way for deployment.</p><h3><a href="https://learn.microsoft.com/en-us/dotnet/api/overview/azure/resourcemanager.resources-readme?view=azure-dotnet">Azure Resource SDK</a></h3><p>Actually as a developer, if you want to deploy infrastructure into the Azure Cloud, you can go different ways. There is <a href="https://www.pulumi.com/b/?utm_campaign=Competitive-IaC&amp;utm_term=pulumi&amp;utm_medium=cpc&amp;utm_source=google&amp;hsa_grp=164192522628&amp;hsa_cam=20775470768&amp;hsa_mt=e&amp;hsa_net=adwords&amp;hsa_ver=3&amp;hsa_acc=1926559913&amp;hsa_ad=680872926398&amp;hsa_src=g&amp;hsa_tgt=kwd-1177947170384&amp;hsa_kw=pulumi&amp;gad_source=1&amp;gclid=EAIaIQobChMIudG5ypqFhQMVsGdBAh2J1ACZEAAYASAAEgKSKfD_BwE">Pulumi</a>. <a href="https://www.terraform.io/">Terraform</a>, <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/overview">ARM templates</a> or bicep and more IaC solutions. In case of Azure, you can go the <a href="https://learn.microsoft.com/en-us/dotnet/api/overview/azure/resourcemanager.resources-readme?view=azure-dotnet">SDK </a>way too. This <a href="https://learn.microsoft.com/en-us/dotnet/api/overview/azure/resourcemanager.resources-readme?view=azure-dotnet">SDK </a>sits on top of the public <a href="https://learn.microsoft.com/en-us/rest/api/resources/">REST API of Azure Resource Management</a>. The last version I used is a result of a long hard way, when I look into the old documentation. In the beginning of the SDK, Microsoft tried to design all the resources in a Domain specific language, which is cool to read and use, but the target system is too dynamic, so the SDK became senseless after a while.</p><p>Now it is completely redesigned, and actually the behavior is close to the bicep style, which I love. (Did I mentioned it already? 😄)</p><p>Okay, the intention of this post is not to describe how the SDK works.</p><h3>Role Assignment</h3><p>Many times, when you want to deploy an infrastructure, you want to set up rights for the resource who works together. For example, a Web App wants to get data from a database, so the Web App needs the right for it. You might ask, isn&#39;t it not solved by using a connection string. Well, in the good old time it was the way, but for a way better security it’s not anymore. Now we work with managed identities. Which means, described in a very simple way: any resource is a kind of user and gets rights to do things, or not.</p><p>Microsoft did not the best job in this topic. I mean, when I set up a role for a resource with bicep, it looks like:</p><pre>param storageAccountName string<br>param principalId string<br>param roleId string<br><br>var roleAssignmentName = guid(subscription().subscriptionId, storageAccountName, roleId, principalId)<br><br>resource storageAccount &#39;Microsoft.Storage/storageAccounts@2022-09-01&#39; existing = {<br>  name: storageAccountName<br>}<br><br>resource blobRoleAssignment &#39;Microsoft.Authorization/roleAssignments@2022-04-01&#39; = {<br>  name: roleAssignmentName<br>  scope: storageAccount<br>  properties: {<br>    roleDefinitionId: subscriptionResourceId(&#39;Microsoft.Authorization/roleDefinitions&#39;, roleId)<br>    principalId: principalId<br>    principalType: &#39;ServicePrincipal&#39;<br>  }<br>}</pre><p>Here I set up a role for a resource, referenced by its principalId, to allow access to a storage account. The resource blobRoleAssignment needs a role definition ID, which is somehow organized by the subscription. That’s why I have to transform the roleId into a roleDefinitionId. Nobody knows why it is so, because the roleId is a unique ID all over the Azure Cloud. Why I have to transform it then? 🤷‍♂️</p><p>Now I want to do the same but different thing by using the Azure SDK. Here I assign the role “KeyVault Secret Reader” to a KeyVault</p><p>Step 1: Get role definition</p><pre>using Azure;<br>using Azure.ResourceManager;<br>using Azure.ResourceManager.Authorization;<br>using Azure.ResourceManager.Authorization.Models;<br>using Azure.ResourceManager.KeyVault;<br><br>...<br><br>ResourceIdentifier kvSecretReader = <br>  new (&quot;4633458b-17de-408a-b874-0445c86b69e6&quot;);<br><br>Response&lt;AuthorizationRoleDefinitionResource&gt; kvSecretReaderDefinition =<br>  await subscription.GetAuthorizationRoleDefinitionAsync(kvSecretReader);<br><br>...</pre><p>A magic GUID transformed into a magic role definition.</p><p>Step 2: Get the KeyVault where I want to set up the role assignment</p><pre>...<br><br>Response&lt;KeyVaultResource&gt; getKeyVaultResponse = <br>  await resourceGroup.GetKeyVaultAsync(keyVaultName);<br><br>KeyVaultResource keyVault = getKeyVaultResponse.Value;<br><br>...</pre><p>All resources can be grabbed from the resourceGroup component.</p><p>Step 3: Create a role assignment content. It’s the definition what we want to do soon.</p><pre>...<br><br>RoleAssignmentCreateOrUpdateContent roleAssignment = <br>  new(kvSecretReaderDefinition.Value.Id, principalId)<br>  {<br>    PrincipalType = RoleManagementPrincipalType.ServicePrincipal<br>  };<br><br>string roleAssignmentName = Guid.NewGuid().ToString();<br><br>...</pre><p>Here we have the definition that we want to assign a role (kvSecretReaderDefinition) for a resource (principalId) with a special name (roleAssignmentName) — yes a GUID is not a nice name, but it’s better to do so. 😉</p><p>Step 4: The final step. Bring it all together.</p><pre>...<br><br>ArmOperation&lt;RoleAssignmentResource&gt;? createRoleAssignmentOperation = <br>  await keyVault<br>  .GetRoleAssignments()<br>  .CreateOrUpdateAsync(WaitUntil.Completed,roleAssignmentName,roleAssignment);<br><br>...</pre><p>Disclaimer: All my lines of code have more infrastructure than just this few lines. In the original I have try-catches, checks and exception handling, of course. 😄</p><h3>What I’ve realized</h3><p>Firstly, bicep is less code than using the SDK. But the SDK have its right to exist. I used it to create resources on demand in an Application which had no access to a build pipeline system. Actually I’ve planned to prepare a build pipeline to trigger a custom build for my use case, but then I found out, I can’t do it. So the SDK was my solution.</p><p>Secondly, the SDK way is quite similar to bicep. Get a resource, grab its sub resources, add or update the resource… done. I like the strong typed way very much but also the dynamic parts of it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0cb273164d23" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/role-assignment-with-azure-resource-sdk-0cb273164d23">Role Assignment with Azure Resource SDK</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invalid SKU Code “Free” — A Solution]]></title>
            <link>https://medium.com/medialesson/invalid-sku-code-free-a-solution-8bc8f4851916?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bc8f4851916</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 14:22:51 GMT</pubDate>
            <atom:updated>2024-03-01T15:18:47.354Z</atom:updated>
            <content:encoded><![CDATA[<h3>Invalid SKU Code “Free” — A Solution</h3><figure><img alt="A mostly green picture of a monitor with a big exclamation mark." src="https://cdn-images-1.medium.com/max/1024/1*anvG4BlCZAkKBtBtWmCrLQ.png" /></figure><p>Sometimes it will happen that people wil publish static WebApps to an Azure Static WebApp Resource. Also the people think about to do this</p><ol><li>On a free SKU plan, because they don’t expect much traffic or its just for a dev test which needs not many features.</li><li>By deploying it with <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/">bicep</a>, just because its very simple and state of the art for software development.</li><li>By using an <a href="https://azure.microsoft.com/en-us/products/key-vault">Azure Key Vault</a> for security reasons when an API needs secret values.</li></ol><p>That’s a simple setup which should work very well.</p><h3>But it’s not working?</h3><p>When you setup a bicep script for your static web app it looks like:</p><pre>...<br><br>resource staticWebApp &#39;Microsoft.Web/staticSites@2022-03-01&#39; = {<br>  name: name<br>  location: location<br>  sku: {<br>    name: &quot;Free&quot;<br>    tier: &quot;Free&quot;<br>  }<br>  identity: {<br>    type: &quot;SystemAssigned&quot;<br>  }<br>  properties: {<br>    stagingEnvironmentPolicy: &quot;Enabled&quot;<br>    allowConfigFileUpdates: true<br>    provider: &quot;Custom&quot;<br>    enterpriseGradeCdnStatus: &quot;Disabled&quot;<br>  }<br>  tags: tags<br>}<br><br>...</pre><p>or quite similar.</p><p>In my case it did not work. I’ve got an exception while deploying:</p><pre>...<br><br>{<br>  &quot;ErrorEntity&quot;: {<br>    &quot;ExtendedCode&quot;: &quot;55925&quot;,<br>    &quot;MessageTemplate&quot;: &quot;SkuCode &#39;{0}&#39; is invalid.&quot;,<br>    &quot;Parameters&quot;: [<br>      &quot;Free&quot;<br>    ],<br>    &quot;Code&quot;: &quot;BadRequest&quot;,<br>    &quot;Message&quot;: &quot;SkuCode &#39;Free&#39; is invalid.&quot;<br>  }<br>}<br><br>...</pre><p>Thats really annoying. I’m absolutely sure the SKU Code ‘Free’ exists. I can set up this value in the Azure Portal and by generating the <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/overview">ARM template,</a> I get exactly this code. So what is the problem?</p><h3>The Solution</h3><p>After investigating a while I found out that a ‘Free’ Azure Static WebApp Resource can’t set up an ‘SystemAssigned’ identity. If you want to set up a Managed Identity to use it for a Key Vault you need to select a SKU ‘Standard’ (BTW, it’s the same for “Bring your own Function”-feature).</p><p>My problem is the error message. If the SKU wrong because of Identity, “Bring your own Function” or something else, so make it clear.</p><p>Now you know why you’ve got that error and my post was helpful for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bc8f4851916" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/invalid-sku-code-free-a-solution-8bc8f4851916">Invalid SKU Code “Free” — A Solution</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to resolve the Azure LinuxDynamicWorkersNotAllowedInResourceGroup Error]]></title>
            <link>https://medium.com/medialesson/how-to-resolve-the-azure-linuxdynamicworkersnotallowedinresourcegroup-error-d44d76be6674?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d44d76be6674</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[azure-app-service]]></category>
            <category><![CDATA[bicep]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Sun, 12 Mar 2023 14:37:49 GMT</pubDate>
            <atom:updated>2023-03-12T14:37:49.474Z</atom:updated>
            <content:encoded><![CDATA[<p>A few weeks ago I started to fix some issues on an existing Azure pipeline for deploying cloud resources. It’s an enterprise system which was running since a year without problems. After some changes I decided to redeploy the infrastructure. What can happen? Nothing has bee changed except of a naming. But then I ran in an error</p><blockquote>”code”: “LinuxDynamicWorkersNotAllowedInResourceGroup”, “message”: “Linux dynamic workers are not available in resource group [name of our resource group].”</blockquote><p>Why is this happen? We did not changed much in the infrastructure. The deployment script was running very well. But now one year later this error appears suddenly.</p><p>After googeling I found <a href="https://github.com/Azure/Azure-Functions/issues/1952">this gitHub issue</a>. Which actually just redirects to a long <a href="https://github.com/Azure/app-service-announcements/issues">list of announcements</a> of the Azure App Service. Okay, but this is not a solution. I need one.</p><p>A short discussion with my colleagues and the dev community, I learned that error is more or less a glitch and can be fixed by some workarounds. But I don’t like workarounds I need a fix for my deployment script.</p><h3>What does it mean, this error?</h3><p>At the moment it’s not possible to deploy a Y1 Dynamic App Service Plan type Linux in a resource group where already an App Service Plan was deployed. I did not tested any configuration, maybe with a Windows Plan anything works well. But in my case, I tried to create an <strong>App Service Plan S1 Standard Linux</strong> and an <strong>Azure Function App, hosted in a consumption (Y1 Dynamic) Linux plan</strong>, into one resource group.</p><p>The deployment is developed as a Infrastructure as Code (IaC) solution in <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep">Bicep</a>. Here I set up the resources I need in a very simple way. I describe and list the resources and at execution the resources will be created in a specific order. In my case I found out the order of App Service Plan creation is important. Usually it is not.</p><p>So my solution now is to set the App Service Plans in dependency. First the Y1 Dynamic Plan needs to be created and then the S1 Plan. In Bicep it is very simple.</p><p>The keyword in Bicep is dependsOn.</p><figure><img alt="module s1AppService… dependsOn: [function App]" src="https://cdn-images-1.medium.com/max/1024/1*MdDi5OjrEjuHtJX0CHDaZg.png" /><figcaption>Bicep module dependsOn functionApp</figcaption></figure><p>A Bicep module provides a parameter, a list of resources on what this module depends. First the depended resource needs to be created, then the module will be created.</p><p>After this small change in my deployment script the Linux… Error disappeared.</p><p>I hope it helps you too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d44d76be6674" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/how-to-resolve-the-azure-linuxdynamicworkersnotallowedinresourcegroup-error-d44d76be6674">How to resolve the Azure LinuxDynamicWorkersNotAllowedInResourceGroup Error</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raspberry Pi as LED-Strip Controller]]></title>
            <link>https://medium.com/medialesson/raspberry-pi-as-led-strip-controller-d8227da488bc?source=rss-8c7639e08acd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8227da488bc</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[ws2812]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Janek Fellien]]></dc:creator>
            <pubDate>Wed, 04 Jan 2023 20:39:32 GMT</pubDate>
            <atom:updated>2023-01-04T20:39:32.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*J8djMbCIiiq8o-kPz1Tprw.png" /><figcaption>Picture from Unsplash+ in collaboration with <a href="https://unsplash.com/@osarugue">Osarugue Igbinoba</a></figcaption></figure><p>Last year (2022) the company I’m working for, was requested to create a sample for an IIoT (Industrial Internet of Things) use case. We’ve built a LEGO® model with a few houses. The light was controlled by an application which took weather data to simulate wind and solar power. The light controller was, just as prototype, a Raspberry Pi connected with a WS2812b LED-Strip.</p><figure><img alt="A light strip in rainbow colors." src="https://cdn-images-1.medium.com/max/800/0*f9DTsz0C4KvSmksO.jpg" /><figcaption>WS2812b addressable LED-Strip</figcaption></figure><p>These LEDs are controllable by software, so we were able to set up the light in any LEGO® building different. Why should we do this? Simple answer: not any household uses the same light, so why should we do this in a model of a small town? 😄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eZ0tYJo-SkhWmeb690-v4w.png" /><figcaption>LEGO® model with white light</figcaption></figure><p>This project got me thinking about to use LED lights instead of fireworks for the New Year’s Eve party 2023. This post will describe what I did and what my main issues were.</p><h3>Prerequisites</h3><p>Firstly, we need the hardware</p><ul><li>A Raspberry Pi (I use a Pi 2 Model B v1.1)</li><li>For a better handling, a GPIO Hat</li><li>A W2812b Led-Strip</li><li>And a power supply 5V, 2500mA output</li></ul><p>(The Pi 2 needs a Wifi module if you like to control it wireless. 😉)</p><p>Secondly, the software</p><ul><li>The OS for the RPi is Linux 10 (Buster)</li><li>Application is developed in C# (.NET 6.0.402)</li></ul><h3>Wiring</h3><p>In the past, I’ve learned in a RPi project to describe the wiring. The most interesting part in this project here, actually all documented wirings were wrong. For example, this documentation <a href="https://www.thegeekpub.com/15990/wiring-ws2812b-addressable-leds-to-the-raspbery-pi/">here</a> uses pin 18. The same pin is used in many other documentations, but in my case, pin 18 is wrong. If I use it, nothing will happen.</p><p>Why is it so?</p><p>I think the reason is the program language. All the samples are developed in Python and uses the lib neopixel, which is different in C#.</p><figure><img alt="A code snipped in Python which imports the neopixel library and uses it on pin 18" src="https://cdn-images-1.medium.com/max/910/1*OJwk3FND_9k2foNzYLam9Q.png" /><figcaption>Use neopixel in Python on pin 18</figcaption></figure><p>In C# I use a SpiDevice. So I have to look for a different pin, related to the SPI pins. Luckily, I found a very helpful description of any pin <a href="https://pinout.xyz/">here</a> and after reading a lot about SPI, I found out I need to take the pin 21, which is the GPIO 9, which is the SPI0 (zero), which is the MISO (master in slave out) pin. 😱</p><p>So many different names. It was absolute horrible for someone who wants just turn on some light.</p><p>Finally, the wiring result is:</p><ul><li>Pin 4: 5V</li><li>Pin 6: Ground</li><li>Pin 21: Signal (called Din on the strip)</li></ul><p>Because I used the GPIO Hat, it was way simpler to connect the wire.</p><h3>Software</h3><p>After putting all the thing together I started to develop the application. My first version was a command line application, starting a sequence of effects. But now it is a web application to control the light via WebAPI.</p><p>I don&#39;t want to describe how to set up a WebAPI project in .NET. Also, I don’t want to describe how to develop an API Controller. The interesting part is the LED Service aka LED Strip.</p><p>To control the light, you need four namespaces:</p><figure><img alt="using Iot.Device.Graphics;
 using Iot.Device.Ws28xx;
 using System.Device.Spi;
 using System.Drawing;" src="https://cdn-images-1.medium.com/max/1024/1*A29UE2TwQhoM3jrLoqo8DQ.png" /><figcaption>The namespaces</figcaption></figure><p>You get it by referencing the NuGet packages <em>Iot.Device.Bindings</em> and <em>System.Device.Gpio</em>.</p><p>To set up a SPI device, you need to know which busId is connected and which chipSelectLine is in use. 🤔Yes I had the same questions, what is a busId and chipSelectLine. To be honest I don’t know, but luckily I used Linux for a while and after a few error messages from the SpiDevice I remembered me where to find out the SPI device settings. Actually not exactly the SPI device settings but the connected devices. You can enter ls /dev/ in your Raspberry Pi terminal, and you will get the whole list of connected devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nb7ElBK7ie6Uqjd-biGHAg.png" /><figcaption>List of connected devices</figcaption></figure><p>In the screenshot, you can see all my connected devices, also the spidev0.0 and spidev0.1. After testing a lot, I found out that the numbers are the busId (0) and the chipSelectionLine (1) for the MISO pin. Crazy, isn’t it?</p><p>All that experiments led me to get the right setting for the SpiDevice.</p><pre>SpiConnectionSettings spiSettings = new (0, 1)<br>{<br>    ClockFrequency = 2_400_000,<br>    Mode = SpiMode.Mode0,<br>    DataBitLength = 8<br>};</pre><p>The setting <em>ClockFrequency</em>, <em>Mode </em>and <em>DataBitLength </em>values are just a copy by a sample developed in Python, but it works. 😉</p><p>To initialize a Ws2812b LED strip, we need the <em>SpiConnectionSettings </em>and the length of the strip, which means the number of LEDs the strip have. In my case, I have 60 LEDs to control, one meter. If you want to control more than one meter, count the LEDs.</p><blockquote>BTW, the power (5V) of the RPi is good enough for one or two meter, but if you need longer strips you need more power. The Ws2812b strip provides for any part a red and white cable. Here you can connect a power supply to support the LEDs.</blockquote><p>The constructor of my <em>LedStrip </em>class expects the <em>SpiConnectionSetting </em>and the number of LEDs. Here the SpiDevice will be created and assigned to an internal variable _ledStrip which is type of <em>Ws2812b</em>.</p><pre>using Iot.Device.Graphics;<br>using Iot.Device.Ws28xx;<br>using System.Device.Spi;<br>using System.Drawing;<br><br>namespace LedStripControllerApi.Services;<br><br>internal class LedStrip : ILedStrip<br>{<br>  private int _numberOfLeds;<br>  private Ws2812b _ledStrip;<br><br>  public LedStrip(SpiConnectionSettings spiSettings, int numberOfLeds)<br>  {<br>    SpiDevice spiDevice = SpiDevice.Create(spiSettings);<br><br>    _numberOfLeds = numberOfLeds;<br><br>    _ledStrip = new (spiDevice, numberOfLeds);<br>  }<br><br>...<br>}</pre><p>So, the biggest part of magic is happened. The LED strip is connected and the SPI device is initialized. Now we can take a short look into one effect, just turn on the light.</p><pre>public void TurnOn(Color color)<br>{<br>  // turn off all led<br>  Clear();<br><br>  // get the image of strip<br>  BitmapImage image = _ledStrip.Image;<br><br>  // iterate through led and set the color of the pixel<br>  for(int i = 0; i &lt;= _numberOfLeds; i++){<br>      image.SetPixel(i, 0, color);<br>  }<br><br>  // update the data<br>  _ledStrip.Update();<br>}</pre><p>In the snipped, you can see that a LED strip will be controlled by an image and its pixel. Any pixel represents a LED. Because we have just a single line strip, the <em>SetPixel </em>method uses 0 as y-coordinate.</p><p>To control the image, you have to put the image in a variable before changing. I tried it to change it directly but without any result, so don’t wonder, just do it the same way. 😄</p><p>Finally, after set all pixel, aka LED, of the strip, you need to update the Ws2812b instance. You don’t need to reassign the image, it is still referenced.</p><p>Good news: <a href="https://github.com/jfellien/raspi-led-controller">Here</a> you will find the whole <a href="https://github.com/jfellien/raspi-led-controller">project</a>. Clone it, fork it, use it.</p><p>~janekf</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8227da488bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/medialesson/raspberry-pi-as-led-strip-controller-d8227da488bc">Raspberry Pi as LED-Strip Controller</a> was originally published in <a href="https://medium.com/medialesson">Medialesson</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>