<?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 Where on Medium]]></title>
        <description><![CDATA[Stories by Where on Medium]]></description>
        <link>https://medium.com/@huier23?source=rss-dce085443094------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K5QkwUakVfz3EOSh54rYCQ@2x.jpeg</url>
            <title>Stories by Where on Medium</title>
            <link>https://medium.com/@huier23?source=rss-dce085443094------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:23:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@huier23/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[Use AAD and OAuth 2.0 to access the API managed by Azure API Management]]></title>
            <link>https://huier23.medium.com/use-aad-and-oauth-2-0-to-access-the-api-managed-by-azure-api-management-17a330d3dea0?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a330d3dea0</guid>
            <category><![CDATA[azure-api-management]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Thu, 22 Apr 2021 08:41:59 GMT</pubDate>
            <atom:updated>2021-04-22T08:41:59.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*HmorTVaPN7ZVpUoNCSAQiQ.png" /><figcaption><a href="https://olcay.dev/2020/01/10/architect-azure-api-management-service/">Architect Azure API Management service | A Clockwork Engineer (olcay.dev)</a></figcaption></figure><p>Here is the completed official document : <a href="https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-protect-backend-with-aad">Protect a web API backend in Azure API Management by using OAuth 2.0 authorization with Azure AD</a></p><h3>What is AAD?</h3><p>Azure Active Directory (Azure AD) is Microsoft’s cloud-based identity and access management service, which helps your employees sign in and access resources in external resource like Microsoft 365, Azure or another SaaS and internal resource such as apps on your corporate network and intranet, along with any cloud apps developed by your own organization which enable AAD authentication.</p><h3>What is OAuth?</h3><p>The OAuth authorization framework enables a third-party<br> application to obtain limited access to an HTTP service and describe the authentication mechanism.</p><p>OAuth defines four roles, include resource owner, resource server, client<br>and authorization server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*HdzZvWYxwAI69oQ88FQl8g.png" /><figcaption><a href="https://tools.ietf.org/html/rfc6749#page-4">RFC 6749 — The OAuth 2.0 Authorization Framework (ietf.org)</a></figcaption></figure><p>The client requests access to resources controlled by the resource owner and hosted by the resource server. In OAuth,<strong> </strong>Instead of using the resource owner’s credentials to access protected resources, the client obtains an <strong>access token from authorization server</strong> with the approval of the resource owner to access the protected resource hosted by the resource server.</p><p>Methods to get access tokens from the authorization server are called <strong>grants</strong>. The same method used to request a token is also used by the resource server to validate a token.</p><p>The four basic grant types are <strong>Authorization Code</strong>, <strong>Implicit</strong>, <strong>Resource Owner Credentials</strong> and <strong>Client Credentials</strong>.</p><h3>Let’s do it!</h3><h4>Set up App Registration</h4><p>Through register an app in AAD so the Microsoft identity platform can provide authentication and authorization services for your application and its users.</p><ul><li>New an app in AAD, In Azure portal, browse to your Azure Active Director and select <strong>New Registration</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvZZZ8eZLx93qJ16lKugHQ.png" /></figure><ul><li>Leave the URL field empty for now</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*SCXGSuTlrZPt_toUPIycXw.png" /></figure><ul><li>Note the <strong>Client ID</strong> on <strong>Overview</strong> and new the <strong>Client Secret</strong> on <strong>Certificate &amp; secrets</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*nNcN-wrP7egTH1YZqmTAAw.png" /></figure><ul><li>Navigate to <strong>Expose an API</strong> to <strong>Add a scope</strong></li></ul><p>(Scope setting would be required at using v2 endpoint)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*mba360CkaM9Vpp6iHNi2eQ.png" /></figure><ul><li>Remember the Scopes for later used</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LFVnWVcbt4gAqeNn.png" /></figure><ul><li>Get <strong>Endpoints</strong> from <strong>Overview</strong> section</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOGt8_SnUZVGYZET5afiIQ.png" /></figure><h4>Enable OAuth 2.0 in APIM</h4><p>In your APIM resource and click OAuth 2.0 + OpenID Connect under Developer portal section to create a OAuth2 service.</p><ul><li>Specify <strong>OAuth 2.0 authorization endpoint (v2)</strong>, O<strong>Auth 2.0 token endpoint (v2)</strong>, <strong>Client ID</strong> and <strong>Client Secret </strong>you noted form previous step.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Id6Oy79i1Z-uJc7Qada2EQ.png" /></figure><ul><li>For the <strong>Client registration page URL</strong>, enter a placeholder value, such as <a href="http://localhost./">http://localhost</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XuNapDZZ2VarS-AzA1wvJw.png" /></figure><ul><li>Select <strong><em>POST</em></strong> under <strong>Authorization request method</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lj3HB68lSEwKLGpO1oqOyw.png" /></figure><ul><li>Add default scope got from app registration</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UogWyBBgHcDuKgm32lcG9g.png" /></figure><ul><li>Note the <strong>Authorization code grant </strong>under<strong> Redirect URI</strong> section</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gGVIQTUQxtPcOMGW.png" /></figure><h4><strong>Set Redirect URI for App Registration</strong></h4><ul><li>Navigate to <strong>Authentication</strong> and set the <strong>Redirect URIs</strong><br>(Redirect to APIM developer portal when access success)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMYobSvwo11iqqO0uHzt7g.png" /></figure><ul><li>Fill in the Redirect URI you get last step.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URDRnecy-pRG_rWgdk5fxQ.png" /></figure><p>If forget, you also can get the <strong>Redirect URI</strong> from <strong>APIM &gt; OAuth2.0 + OpenID connect &gt; OAuth 2.0 &gt; {OAuth name} &gt; Redirect URI</strong></p><ul><li>Finished</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z_2EpxNkx_v12OO0.png" /></figure><ul><li>Remember to enable <strong>Access tokens (used for implicit flows)</strong> from <strong>Authentication</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5buTLCzZ1KKtDv0g.png" /></figure><ul><li>Navigate to <strong>Mainfest</strong> and modify “accessTokenAcceptedVersion” from “null” to “2”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FYnKEOBlkh4NfROX.png" /></figure><h4>Setting APIs policy</h4><p><a href="https://docs.microsoft.com/en-us/azure/api-management/set-edit-policies">https://docs.microsoft.com/en-us/azure/api-management/set-edit-policies</a></p><ul><li>Use OAuth Server</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i_-t6Jeeu8POZOPvX_iu5g.png" /></figure><ul><li>Add code as below to policy inbound section</li></ul><pre>&lt;validate-jwt header-name=&quot;Authorization&quot; failed-validation-httpcode=&quot;401&quot; failed-validation-error-message=&quot;Unauthorized. Access token is missing or invalid.&quot;&gt;<br>        &lt;openid-config url=&quot;https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration&quot; /&gt;<br>        &lt;required-claims&gt;<br>            &lt;claim name=&quot;aud&quot;&gt;<br>                &lt;value&gt;{client-id}&lt;/value&gt;<br>            &lt;/claim&gt;<br>        &lt;/required-claims&gt;<br>&lt;/validate-jwt&gt;</pre><h3>Summary</h3><p>Now that the OAuth 2.0 user authorization is enabled on your API.</p><ul><li>Browse to any operation under the API in the developer portal, and select Try it. Select Authorization code from the authorization drop-down list, and you are prompted to sign in to the Azure AD tenant.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ENR9GdowpcnADoH6oyWcA.png" /></figure><ul><li>After successful sign-in, an Authorization header is added to the request (Base64 encoded), with an access token from Azure AD</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F5iLdLMG5OtLGfqoNduITA.png" /></figure><h3>Reference</h3><ul><li><a href="https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-protect-backend-with-aad">Protect API backend in API Management using OAuth 2.0 and Azure AD — Azure API Management | Microsoft Docs</a></li><li><a href="https://docs.microsoft.com/en-us/azure/active-directory/fundamentals/active-directory-whatis">What is Azure Active Directory? — Azure Active Directory | Microsoft Docs</a></li><li><a href="https://stackoverflow.com/questions/59826328/aadsts900144-the-request-body-must-contain-the-following-parameter-scope-whe">AADSTS900144: The request body must contain the following parameter: ‘scope’ when using legacy Developer Portal</a></li><li><a href="https://docs.microsoft.com/en-us/answers/questions/39799/redirect-url-error-while-authecating-api-with-oaut.html">Redirect URl error while authecating API with Oauth 2.0 in APIM developer portal:AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application: ‘APP reg ID’.</a></li><li><a href="https://docs.microsoft.com/en-us/azure/api-management/api-management-access-restriction-policies#ValidateJWT">API Management access restriction policies</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a330d3dea0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.NET 新手村 — 打什麼打，要打去練舞室打]]></title>
            <link>https://huier23.medium.com/net-%E6%96%B0%E6%89%8B%E6%9D%91-%E6%89%93%E4%BB%80%E9%BA%BC%E6%89%93-%E8%A6%81%E6%89%93%E5%8E%BB%E7%B7%B4%E8%88%9E%E5%AE%A4%E6%89%93-6da64ae1d61a?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/6da64ae1d61a</guid>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[dotnet-5]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Fri, 16 Apr 2021 18:45:06 GMT</pubDate>
            <atom:updated>2021-04-16T18:46:22.601Z</atom:updated>
            <content:encoded><![CDATA[<h3>.NET 新手村 — 打什麼打，要打去練舞室打</h3><p>本篇會先簡單描述 .NET 的介紹，以及整理一些基本知識，不會有太深入的技術探討而是觀念上的釐清整理，並對去年參加的 .NET Conf 做個紀錄。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxOHacyUtlYND95jSsSbsw.png" /><figcaption>[問卦] .NET Conf 2020 day1 — ptt 八卦版</figcaption></figure><p>先簡單看個圖示，比較容易理解。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ybg0L17XPnH2JZJx0E-_gQ.png" /></figure><ul><li><strong>.NET Framework</strong>：最早釋出的框架，.NET Framework 1.0 於 2002 年發行，支援運行在 Windows 上</li><li><strong>.NET Core</strong>：於 2014 年發佈的跨平台框架</li><li><strong>Xamarin</strong>：通過 C# 可編寫原生的 <a href="https://zh.wikipedia.org/wiki/Android">Android</a>、<a href="https://zh.wikipedia.org/wiki/IOS">iOS</a> 和Windows 應用程式</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obs7edyphF8qxVnxPozFaw.png" /></figure><p>.NET Standard 是為了提供 .NET 跨平臺基礎函式庫，讓開發者撰寫可運行於任何平臺執行的函式庫，但 .NET Standard 也存在許多問題。</p><h3>Web 框架</h3><ul><li><strong>ASP .NET</strong>：免費的 web 架構，可用於使用 HTML、CSS 和 JavaScript 建立網站和 web 應用程式，ASP.NET 支援三種開發模式，Web Pages、 MVC (Model View Controller)、Web Forms，基本上需於 IIS (Internet Information Server) 上執行</li><li><strong>ASP .NET Core</strong>：開放原始碼、跨平台架構，用於在 Windows 、macOS 或 Linux 上建置 Web 應用程式，並且可裝載於 <a href="https://docs.microsoft.com/zh-tw/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-5.0">Kestrel</a> 、<a href="https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/iis/?view=aspnetcore-5.0">IIS</a> 、<a href="https://docs.microsoft.com/zh-tw/aspnet/core/fundamentals/servers/httpsys?view=aspnetcore-5.0">HTTP.sys</a> 、 <a href="https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0">Nginx</a>、 <a href="https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-5.0">Apache</a>、 <a href="https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/docker/?view=aspnetcore-5.0">Docker</a></li></ul><p>透過官方要要進行安裝的話，會發現到有兩個可以裝，一個是 Runtime (run app)，一個是 SDK (build app)，runtime 可以讓你執行程式而 SDK 則可以開發 .NET 的專案</p><p><a href="https://dotnet.microsoft.com/download">Download .NET (Linux, macOS, and Windows)</a></p><p>如果選擇 runtime 並是 Windows 的話，會發現有一個 Download Hosting Bundle</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*Pj1Ts4SSyzec3ZeD-TNqKQ.png" /></figure><p>如果想要讓 ASP.NET Core 在 IIS 上執行，IIS 會去觸發 ASP .NET Core ，讓它run 起來，但沒裝 ASP.NET Core Hosting bundle，IIS 就不會執行觸發 ASP .NET Core，便會發生起不來的狀況，因此會需要安裝 Hosting Bundle，而在安裝 Hosting bundle 的時候，會去設定 IIS，所以如果這時 IIS 還沒裝的話，會沒辦法去設定。</p><p>因此根據這頁的描述便會下載：</p><ol><li>.NET Core</li><li>ASP.NET Core Runtime</li><li>也就是 Hosting Bundle</li></ol><p>而 ASP .NET Core runtime 裡面主要包含了 ASP.NET Core 相關 dll，但不包含 Hosting Bundle</p><blockquote>​那，為什麼有那麼複雜的選項？</blockquote><p>因為，ASP .NET Core 是可以 <strong>不用 </strong>放在 IIS 上跑的 (Self-hosting)，也因此，如果需要運行於 IIS 上，請裝完整東西，包含 Hosting Bundle + .NET Core + ASP.NET Core Runtime，不想放在 IIS 上，則安裝 .NET Core + ASP.NET Core runtime</p><p>如果想自己處理 asp.net core dll , 又不想跑在 iis 上 只需要裝 .NET Core Runtime</p><blockquote>那，為什麼要可以選擇使用 IIS 或不用 IIS 呢？</blockquote><p>透過 IIS 可以輕鬆的達到一些效果，例如 AD 驗證、簡單設定 SSL 或 Log 等機制，不過 IIS 本身也很肥大，效能相對來說也較差</p><h3>.NET 5 (2020/11 release)</h3><p>隨著時代進步，微服務、容器化崛起，微軟開始搶占 Linux 等跨平台市場，所以推出了 .NET Core，而目前便以 .NET Core 為核心。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijUYk6KKxr8zNI44vDMCzw.png" /></figure><p>不再更新 .NET Standard 函式庫，而 .NET 5 將成為取代.NET Standard 定位的產品，但之後的版本將會繼續支援 .NET Standard 2.1 和更之前的版本。</p><p>.NET Framework 4.8 為最後的版本，只會保留於 Windows 上</p><p>同時，支援C# 9.0 新語法，並增添了在容器化技術、API、雲端服務方面上的功能、效能提升，接下來每年都會釋出新版本，而雙數版本為長期支援(LTS)版本。</p><p>透過此篇整理一下在 .NET 世界裡各種名詞雷同迷失的你，如果有寫得不完整或有誤的地方，歡迎提出！</p><h3>Reference</h3><p><a href="https://devblogs.microsoft.com/dotnet/the-future-of-net-standard/">The future of .NET Standard | .NET Blog (microsoft.com)</a></p><p><a href="https://docs.microsoft.com/zh-tw/dotnet/core/compatibility/5.0">.NET 5 中的重大變更 — .NET | Microsoft Docs</a></p><p><a href="https://docs.microsoft.com/zh-tw/aspnet/core/fundamentals/choose-aspnet-framework?view=aspnetcore-5.0">在 ASP.NET 4.x 和 ASP.NET Core 之間進行選擇 | Microsoft Docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6da64ae1d61a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure DevOps Service 中 Azure Resource Manager 手動設定]]></title>
            <link>https://huier23.medium.com/azure-devops-service-%E4%B8%AD-azure-resource-manager-%E6%89%8B%E5%8B%95%E8%A8%AD%E5%AE%9A-f9db72c23574?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9db72c23574</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-resource-manager]]></category>
            <category><![CDATA[azure-devops]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 07:47:31 GMT</pubDate>
            <atom:updated>2021-04-14T07:48:50.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Qn5h9hHy8fTx9n9uwtQ1w.png" /></figure><p>在透過 Azure DevOps Service 部屬/管理 Azure 上的資源時，會需要授權 Azure DevOps Service Azure 上的存取權限，此篇描述如何透過手動的方式進行設定，適用於當管理 Azure 的 admin 及 Azure DevOps Service 為不同人時之場景。</p><h3>設定 App Registration</h3><ul><li>先搜尋 Azure Active Directory (AAD)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*gUA8YEfYbr9m3JNeXQBwyQ.png" /></figure><ul><li>在 AAD &gt; App Registry 選擇 New registration</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9ZktDF6qqlMv_t8jHvzQg.png" /></figure><p>這個動作就有點像是，透過新增一個虛擬的 account 出來，賦予這個 account 一些特定權限，再指派這個 account 給 Azure DevOps Service 來使用，如果需要在自行開發的 app 上使用 Azure Active Directory 的驗證服務也是透過此來做設定</p><ul><li>在 App registration 的頁面填選資料，目前給 Azure DevOps Service 使用的話不需要填寫 redirect URI</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fBjL7v35tYMye07IDBAuEw.png" /></figure><h3>指派權限</h3><p>接下來，我們要將這組 account 指派給 access 資源的 subscription</p><ul><li>搜尋你的 subscription，點選它進去</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41aGlVXzduSrM2PyKxAH1g.png" /></figure><ul><li>先記下 Subscription ID 和 Subscription Name，最後設定 Azure DevOps Service 時會使用到</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSEBZAy1sifUsoAcBFuXuA.png" /></figure><ul><li>找到左邊欄位 Settings 中的 My permission，點選 &quot; Click here to view complete access details for this subscription. &quot;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*RaxQrT4bAhIn2Cvc2a-MKg.png" /></figure><ul><li>點選 Add &gt; Add role assignment，這裡我先將 Role 指派為 Contributor，當然你可以根據你的 Azure DevOps Service 所需要的權限去做更進一步的權限管理設定，Select 的地方搜尋你剛建立的 App registration 的名字並點選，即可指派完成</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*_i1ts05d96BMa59-QmlAsg.png" /></figure><h3>Azure DevOps Service connection 設定</h3><ul><li>回到 AAD，在 Manage 的欄位中找到 App registrations，搜尋剛剛建立的 app 並點選進去</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MoBEP7m_c9ojfnpZUC6SNQ.png" /></figure><p>將 Application (client) ID、Directory (tenant) ID 記下</p><ul><li>在 Manage 欄位中的 Certificates &amp; secrets 新增一個 client secret，可以自行設定到期時間，並將這組 client secret 記下</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*47sPLIoOfE0NEs020Ma-cQ.png" /></figure><p>到 Azure DevOps Service 你的組織中，選擇你要使用到 Azure 的 Project 中選擇 Project Setting &gt; Service Connections &gt; New Service Connection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dYN9Ukll0i2dY0WvhmI0fQ.png" /></figure><ul><li>類型選擇 Azure Resource Manager，驗證方法選擇 Service Principle (manual)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dOH_3Gae2ltzJEhBPo9JyA.png" /></figure><p>填入剛剛取得的 Subscription ID、 Subscription Name、Client ID、Client Secret，並自行設定你的 Service connection name，可以先進行 Verify 確認可以 access 到 Azure 上的資源，最後點選 Verify and Save 便設定完成</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*h3ithZolZ_k144sCGgjEdA.png" /></figure><p>接著回到你要設定資源的 Pipeline 裡面，便可以找到此 Connection 使用</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMQsnOHJ1wfFsq2WZIx80Q.png" /></figure><p>透過此方法，可以讓即使 Azure DevOps Service 的使用者沒有 Azure 上足夠的存取權限，也能透過先由 Azure admin (或擁有足夠權限的人員)先行設定Azure DevOps Service 上面的connection，讓 Azure DevOps Service 的user可以進行後續的操作行為</p><h3>Reference</h3><ul><li><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&amp;tabs=yaml#sep-azure-rm">Service connections in Azure Pipelines — Azure Pipelines | Microsoft Docs</a></li><li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal">Create an Azure AD app &amp; service principal in the portal — Microsoft identity platform | Microsoft Docs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9db72c23574" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在 Visual Studio 中使用 Azure DevOps  Service 的開發體驗]]></title>
            <link>https://huier23.medium.com/%E5%9C%A8-visual-studio-%E4%B8%AD%E4%BD%BF%E7%94%A8-azure-devops-service-%E7%9A%84%E9%96%8B%E7%99%BC%E9%AB%94%E9%A9%97-5a28ebfebc74?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a28ebfebc74</guid>
            <category><![CDATA[visual-studio-2019]]></category>
            <category><![CDATA[source-control]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Thu, 01 Apr 2021 05:54:11 GMT</pubDate>
            <atom:updated>2021-04-01T05:54:11.627Z</atom:updated>
            <content:encoded><![CDATA[<h3>在 Visual Studio 中使用 Azure DevOps Service 的開發體驗</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BeNfZEw8RYTEOYpuFHjltw.png" /><figcaption><a href="https://techidaily.com/visual-studio-2019-banner/">Visual-Studio-2019–banner | TechiDaily</a></figcaption></figure><p>一般來說，自己是比較習慣使用 Command 的方式在 local 端實行版控直接推上 Azure DevOps Repo，然而 git 的指令入門容易，深入亦可以很複雜， Visual Studio 出了相對應的工具，能讓你透過 GUI 對Azure DevOps 有更多的操作，在完成程式碼的同時，讓你實做版控、嵌入工單。</p><h4>將專案推到遠端版控庫</h4><p>將要 push 到 Repo 的 sln 專案開啟，開啟專案後會如下圖所示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKxdO15W36vpe6Mmqd9s9w.png" /></figure><p>接著，要將專案加入使用 Git 來作為 Source Control，方式有兩種</p><ul><li>在右下角的地方有一個 Add Source Control 的地方，選擇 Git</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*x94T15rox7YdyErekDSS2A.png" /></figure><ul><li>在 sln 專案項目的地方選擇 右鍵 &gt; Add Solution to Source Control</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3a34UtHo9zrgWwMXwJvKg.png" /></figure><p>之後，你就可以看到專案已經被加入使用 Git 來作為Source Control，這邊的步驟就如同你在終端機下的指令 git init .，會幫你在專案的根目錄底下建立一個 .git 和 .gitignore 的檔案，然後進行 add和 commit 的動作，因此這時候只需要把遠端的 repository 加入就可以囉！</p><p>在上方工具欄找到 View &gt; Team Explorer 可以把 Visual Studio 中對於小組專案管理的工具列叫出，在這裡你可以將目前的專案與 Azure DevOps Service 的 Repo、GitHub 或其他你自有的 Local Repository（當然也包含 Azure DevOps Service）做連結。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_8EO9koNdTYhSrt5twX_w.png" /><figcaption>選擇 Publish Git Repo 和遠端的 Azure DevOps Service Repo 連結</figcaption></figure><p>在 Azure DevOps Service 上建立專案時，系統會自動建立一個新的 Repository，因此我們在 Repository Name 旁邊的 Advanced 裡面可以選擇到目前現有的版控庫，選擇完成後點選 Publish Repository 的動作就會開始幫你上傳到Remote Repository上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uCsiCqag_YVX_GwUVyXkw.png" /><figcaption>選擇要上傳的 Project 名稱和 Repository Name，你也可以直接在這邊新增一個 Repository。</figcaption></figure><p>回到 Azure DevOps Service 的頁面，可以看到剛剛的 Source Code 已經上傳到雲端了！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bUenbQ7JHqCZN0RlSk_EUQ.png" /></figure><h4>嵌入 Azure DevOps Work Item</h4><p>在上方的工具欄找到 Team &gt; Team Explorer 後點選會跳出 Team Explorer 的視窗，在這邊可以設定對於 Azure DevOps Service 的連線。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*6Cj483dvwznnfIK5l6Z33g.png" /></figure><p>接著選擇你的帳戶、Azure DevOps Service 上的組織及專案進行連結或是Clone 現有的 repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1uC7M0f759uJmBwN-EC5w.png" /></figure><p>或是亦可透過 Connect 的地方對現有的 project 進行連結</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTy7aIznZaykxvGlxLXvKA.png" /></figure><p>Visual Studio 的 Team Explorer 可用來對已經連接到的 Azure DevOps Service Project 來做像是程式碼的簽入簽出、新增分支、合併分支、發 PR、上 Tag、新增 Work Item 等設定，而不需要透過自行下 git 指令。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uw90ZYqZc0EfkFBq8w7iPA.png" /></figure><h4>Reference</h4><ul><li><a href="https://docs.microsoft.com/en-us/azure/devops/user-guide/work-team-explorer?view=azure-devops#:~:text=If%20you%20open%20Visual%20Studio,different%20project%20and%20or%20repository.">Microsoft Doc | Navigate in Visual Studio Team Explorer</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a28ebfebc74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Databricks — 分析及視覺化資料]]></title>
            <link>https://huier23.medium.com/azure-databricks-%E5%88%86%E6%9E%90%E5%8F%8A%E8%A6%96%E8%A6%BA%E5%8C%96%E8%B3%87%E6%96%99-81e9d39b277b?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/81e9d39b277b</guid>
            <category><![CDATA[azure-databricks]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[databricks]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Sat, 14 Nov 2020 15:12:53 GMT</pubDate>
            <atom:updated>2020-11-14T15:12:53.967Z</atom:updated>
            <content:encoded><![CDATA[<h3>Azure Databricks — 分析及視覺化資料</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPVwcx4Ly9R8hduNARirzQ.jpeg" /></figure><p>如果對於 Azure Databricks 不熟悉的朋友，可以先閱讀這篇：<a href="https://medium.com/@huier23/azure-databricks-%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%B4%B9%E5%8F%8A%E7%92%B0%E5%A2%83%E6%BA%96%E5%82%99-b81dad814586">Azure Databricks — 基本介紹及環境準備</a></p><p>本篇教學程式碼參考 <a href="https://github.com/neaorin/databricks-workshop#setup4">Hands-on Workshop: using Apache Spark &amp; Azure Databricks</a>，此份程式碼包含了原始資料集和 notebook 檔案，可以直接匯入做練習。</p><h3>資料存放</h3><p>這次的練習，會將資料集存放在 Azure 的 Blob Storage 中，想練習的朋友們，可以到 <a href="https://github.com/neaorin/databricks-workshop#setup4">Hands-on Workshop: using Apache Spark &amp; Azure Databricks</a> 下載範例資料 data / ml-latest-small.zip 裡的 csv 檔案上傳到 Blob Storage 中， Blob Storage 資源建立和檔案上傳方式，應該不需要我再撰寫，應該都 google 的到吧？</p><p>此資料集使用到的是 <a href="https://grouplens.org/datasets/movielens/">MovieLens</a> 的資料集，Small MovieLens 資料集描述了電影推薦服務 MovieLens 的 5 星等評分和在網站上的 tag 資料。它包含 9125部電影、100004則評分資料和1296 tag 數據，日期從 1995年1月9日至2016年10月16日之間並由大約 671位使用者創建，此資料集於 2016 年 10 月 17日建立</p><h3>資料讀取</h3><p>在進行建立模型、模型訓練等，第一步驟是先了解你手上的資料型態、分析資料的分佈，透過視覺化的方式，可以更好的掌握其中的 insight。</p><p>首先，先建立一個新的 Notbook，在首頁中選擇 New Notebook，並選擇要使用的語言和先前已建立好了 Cluster，接下來的範例會使用 Python。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZfkBrg4Ik21UXkFtk0zkQ.png" /></figure><p>Notebook建立好後，就可以開始進行coding的部分</p><p>先引用會使用到的 library，</p><pre>from pyspark.sql.functions import split, explode, col, udf<br>from pyspark.sql.types import *</pre><p>因為資料集是存在 Blob Storage，資料來源要從 Blob Storage 而來，先設定 Blob Storage 的相關連線設定。</p><pre># Setting storage account connection</pre><pre>container_name = &quot;YOUR_CONTAINER_NAME&quot;<br>storage_account_name = &quot;YOUR_STORAGE_NAME&quot;<br>storage_account_access_key = &quot;YOUR_SAS_KEY&quot;<br>spark.conf.set(&quot;fs.azure.account.key.&quot; + storage_account_name +&quot;.blob.core.windows.net&quot;,storage_account_access_key)</pre><p>如果你不知道SAS key 在哪裡取得，回到 Azure Portal 中 Blob Storage 的頁面，找到 Access Key 可以找到 Key1 或 Key2，即是此處要填的 SAS Key。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-gXwjjq_kxhA_dBak0JAMw.png" /></figure><p>下一步，便是取得資料的位置和資料內容</p><pre># Get stroage data location<br>ratingsLocation = &quot;wasbs://&quot; + container_name +&quot;@&quot; + storage_account_name + &quot;.blob.core.windows.net/ratings.csv&quot;<br>moviesLocation = &quot;wasbs://&quot; + container_name +&quot;@&quot; + storage_account_name +&quot;.blob.core.windows.net/movies.csv&quot;</pre><pre># Get ratings and movies data<br>ratings = spark.read.format(&quot;csv&quot;) \<br>  .option(&quot;inferSchema&quot;, &quot;true&quot;) \<br>  .option(&quot;header&quot;, &quot;true&quot;) \<br>  .load(ratingsLocation)</pre><pre>movies = spark.read.format(&quot;csv&quot;) \<br>  .option(&quot;inferSchema&quot;, &quot;true&quot;) \<br>  .option(&quot;header&quot;, &quot;true&quot;) \<br>  .load(moviesLocation)</pre><p>這裡，我們使用到了 Spark API 和 Databricks APIs 來取得 storage 的位置和對 spark 做資料來源的設定</p><p>資料來源設定完成後，就是把 ratings 和 資料顯示出來</p><pre>display(ratings)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mxtty8BuAjIYHj9pnKMkvQ.png" /></figure><pre>display(movies)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQ-a2C1N2lmBKifmuNMx8g.png" /></figure><p>透過 display() 的方式可以很輕易的將讀取到的資料顯示出來</p><h3>資料整理及分析</h3><p>很多時候， raw data 的資料並不能直接拿來進行分析，會需要做資料清理、整理的動作，比如說轉換格式、資料的合併或整理成可以供訓練的資料集等</p><p>如本篇的練習範例，我們可以觀察到 ratings 這個資料表的 timestamp 欄位資料與我們一般常用的格式不相同，因此需要將其轉換成我們常用的 ”西元年-月-日” 這種格式</p><pre># transform the timestamp data column to a date column<br># first we cast the int column to Timestamp<br>ratingsTemp = ratings \<br>  .withColumn(&quot;ts&quot;, ratings.timestamp.cast(&quot;Timestamp&quot;)) <br>  <br># then, we cast Timestamp to Date<br>ratings = ratingsTemp \<br>  .withColumn(&quot;reviewDate&quot;, ratingsTemp.ts.cast(&quot;Date&quot;)) \<br>  .drop(&quot;ts&quot;, &quot;timestamp&quot;)</pre><pre>display(ratings)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gnt9bB9q7UdG1LIKk8sVSg.png" /></figure><p>同時，我們也觀察到手邊現在有 user 對於電影的評分的資料表(ratings)以及電影的ID、名稱和類型，如果我想將 rating 的資料和 movie 的資料做整合，從一張表中得知使用者是對哪部電影、該電影的類型、電影上映日期以及使用者對於影片的評等</p><pre># use a Spark UDF(user-defined function) to get the year a movie was made, from the title<br><br>def titleToYear(title):<br>  try:<br>    return int(title[title.rfind(&quot;(&quot;)+1:title.rfind(&quot;)&quot;)])<br>  except:<br>    return None</pre><pre># register the above Spark function as UDF<br>titleToYearUdf = udf(titleToYear, IntegerType())</pre><pre># add the movieYear column<br>movies = movies.withColumn(&quot;movieYear&quot;, titleToYearUdf(movies.title))</pre><pre># explode the &#39;movies&#39;.&#39;genres&#39; values into separate rows<br>movies_denorm = movies.withColumn(&quot;genre&quot;, explode(split(&quot;genres&quot;, &quot;\|&quot;))).drop(&quot;genres&quot;)</pre><pre># join movies and ratings datasets on movieId<br>ratings_denorm = ratings.alias(&#39;a&#39;).join(movies_denorm.alias(&#39;b&#39;), &#39;movieId&#39;, &#39;inner&#39;)</pre><pre># Show merged data table<br>display(ratings_denorm)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQTBinsHUEt03Xh0913mng.png" /></figure><h4>使用 SQL</h4><p>在 Azure Databricks 中你也可以使用 SQL 的語法對資料表進行查詢</p><p>從 ratings 的表格中撈出 movieID、userID、rating 和 reviewDate 欄位的資料</p><pre>%sql</pre><pre>SELECT movieId, userId, rating, reviewDate<br>FROM ratings</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iFeUjE_BqiYniJHqDYv5aw.png" /></figure><p>當然，你也可以透過 spark.sql() 的方式以 Python 來呼叫執行 SQL 語法，結果也會是一樣的</p><pre># This would be equivalent to using the spark.sql() function call in Python:<br>result = spark.sql(&quot;SELECT movieId, userId, rating, reviewDate FROM ratings&quot;)<br>display(result)</pre><p>除了選取表格之外，也可以做運算、排序，這邊用到的是前面整合過的 rating_denorm 資料表</p><pre>%sql</pre><pre>SELECT genre, COUNT(rating) as total_ratings, AVG(rating) AS average_rating <br>FROM ratings_denorm<br>GROUP BY genre<br>ORDER BY average_rating DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0HCrboAB29ep3q58VgLSQ.png" /></figure><h4>儲存資料表</h4><p>如果要將重新 merge 或整理過的新資料表做儲存供之後使用，可以透過write.saveAsTable() 的方法來做儲存，而這邊的範例是將資料儲存成 parquet，相較於儲存成 csv，parquet 相對來說更佳的輕量</p><pre>ratings_denorm.write.saveAsTable(&#39;ratings_denorm&#39;, format=&#39;parquet&#39;, mode=&#39;overwrite&#39;)</pre><p>在 Data 的地方便可以看到以儲存的資料表，當然你也可以直接透過 Add Data 添加既有的資料</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5kfV_w39zSk-9A0916Eyw.png" /></figure><h3>視覺化資料</h3><p>用表格的形式呈現，可能不好了解整個資料的散佈情形，以範例資料來說，如果我想知道大眾對於各類型電影的平均評分分佈情況，我可以先透過 SQL 將這些我需要的資料撈出來</p><pre>%sql</pre><pre>SELECT genre, COUNT(rating) as total_ratings, AVG(rating) AS average_rating <br>FROM ratings_denorm<br>GROUP BY genre<br>ORDER BY average_rating DESC;</pre><p>接著，在 result 的地方選擇以 Bar 的形式呈現</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*jvZxiQ2MUIP3Yd3tPTDeVg.png" /></figure><p>從表格的形式轉換成條狀圖呈現資料分布的情形，可以得知使用者對於恐怖類型的電影的平均評分是最低的</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qyRd2GKXSX2LCoiomUmVKw.png" /></figure><h3>總結</h3><p>先立 flag，下篇將會講解如何透過此資料集透過 Azure Databricks 實作電影的推薦系統</p><h3>Reference</h3><ul><li>Github | <a href="https://github.com/neaorin/databricks-workshop">Hands-on Workshop: using Apache Spark &amp; Azure Databricks</a></li><li>Databricks Doc | <a href="https://docs.databricks.com/data/data-sources/azure/azure-storage.html#access-azure-blob-storage-directly">Access Azure Blob Storage directly</a></li><li>Databrics Doc | <a href="https://databricks.com/glossary/what-is-parquet">What is parquet ?</a></li><li>Apache Parquet | <a href="https://parquet.apache.org/documentation/latest/">Apache Parquet</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81e9d39b277b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Databricks — 基本介紹及環境準備]]></title>
            <link>https://huier23.medium.com/azure-databricks-%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%B4%B9%E5%8F%8A%E7%92%B0%E5%A2%83%E6%BA%96%E5%82%99-b81dad814586?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/b81dad814586</guid>
            <category><![CDATA[azure-databricks]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[databricks]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Sat, 14 Nov 2020 14:06:20 GMT</pubDate>
            <atom:updated>2020-11-16T07:51:22.903Z</atom:updated>
            <content:encoded><![CDATA[<h3>Azure Databricks — 基本介紹及環境準備</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPVwcx4Ly9R8hduNARirzQ.jpeg" /></figure><p>Apache Spark 是用於 cluster computing 的 open source framework，如果需要構建分散式計算的系統，就會使用到 Apache Spark ，其繼承了 MapReduce 的架構，為此提供更有效率的資料查詢、檢索和複雜的運算，也因其可以在內存中運行，而大幅提升了整體的處理效能，Azure Databricks 便是一款基於 Apache Spark 為基礎的資料分析平台</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*Rwt9PdGflbpS9VkXgyDdiw.png" /></figure><p>Azure Databricks 由 Microsoft 與 Apache Spark 的創辦人共同設計，並建構於 Azure 雲端平台上，使用者可以直接地透過 Azure portal 啟動 Azure Databricks 的服務。Azure Databricks 支援從 Azure Blob Storage、Azure Data Lake Store、Apache Kafka 或 Hadoop Storgae 等的資料來源，處理包含透過 Azure Data Factory 進行批次工作或透過 Kafka 進行即時的資料串流；後續也支援和其他視覺化工具整合或其他串接服務做為資料的中繼站；Azure Databricks 也提供共同協作，不管你是資料科學家、資料工程師或是其他需要實作商業分析的人員都可以透過 Azure Databricks 的工作區來進行互動</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxGieMZPx8wNWpW_jhDzFg.png" /></figure><h3>重點整理</h3><p>好的，前面都是些廢話，以下就幫大家稍微重點整理一下，幾個使用 Azure Databricks 的好處：</p><ul><li>fully managed 的雲端服務，無需自行管理 server，而是透過雲端代理商託管</li><li>可自行設定 auto scale 機制自動縮放底層的 cluster</li><li>如果原先便熟悉使用 Apache Spark，你可以很輕易地就上手 Azure Databricks，他包含了在 Apache Spark 生態系中既有的服務</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*TM5N4T5t5r4OBcRCu45P7A.png" /></figure><ul><li>支援 R、SQL、Python、Scala 和 Java</li><li>與 Azure 的 RBAC (Role-Based Access Control)整合，在權限的控管上能有更好的體驗 (有好的權限控管機制真的非常重要啊！)</li><li>與 AAD (Azure Active Directory) 整合，並支援 SSO (Single Sign On)，使用既有的帳戶直接進行操作</li><li>(如果我還有想到再補充)</li></ul><h3>環境準備</h3><h4>在 Azure 上建立 Azure Databricks 資源</h4><p>在 Azure portal 搜尋欄搜尋 Databricks 就可以找到 Azure Databricks 的服務，點選並建立</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXL5X2L-w3uV6Xb2ZP5GLw.png" /></figure><p>Azure Databricks 的 pricing tier 有三種，分別可以使用到不同的服務，你可以根據你的需求選擇，這邊我選擇的是 Standard 的 sku</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9yZQcsFogo3Uzz6KwlCCg.png" /></figure><p>如果需要更加 secure 的選擇，你可以將 Azure Databricks 的工作區建立在既有的 virtual network 中，如果是練習用的話可以先選擇 No</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLMOyEivvh-xci2ECESFqQ.png" /></figure><p>完成建立後，到 Azure Databricks 的頁面點選 Launch Workspace 便可以啟動你的工作區</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PYm0kxMPa46PZr4SwvT0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v6VroPhXIMtxz86-l8YRYQ.png" /></figure><h4>建立 Cluster</h4><p>選擇 Clusters 並點選 Create Cluster 可以開始建立新的叢集</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*5K6Pd6QYU2-1UfcmzTh2-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ruH0UAvFEy7iJ8LGjFaNyQ.png" /></figure><p>Cluster 中 Node 類型基本上分成 Worker Node 和 Driver Node。</p><p>Cluster 由一個 Driver Node 和一到數個不等的 Worker Node 所組成，針對 Driver Node 和 Worker Node 可以分別選擇不同效能的機器，Driver Node 會負責維護及編譯 Notebook 上的命令列和 Apache Spark 主機的協調，並交由 Worker Node 進行 process 的處理</p><p><strong>Worker Type / Driver Type</strong></p><p>你可以選擇 Worker Node 和 Driver Node 的類型，包括 General、Compute Optimized 或是 GPU 等類型的機器都可以選擇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*RGWqyg0DtFxldBpy1eX5fw.png" /></figure><p><strong>Cluster Mode</strong></p><p>Azure Databricks 支援三種叢集模式：Standard、High Concurrency 和 Single Node</p><ol><li>Standard (預設)：使用此種模式即表示會配給你一台(到多台)機器，相較於 High Concurrency 的模式較不會有冷啟動的問題，但機器閒置時依仍會收取費用，也因此你可以設定閒置超過一定時間便進行 terminate，支援Python、R、Scala 和 SQL</li><li>High Concurrency：為雲端託管資源的模式，僅在執行期間向使用者收取費用，主要優勢在於，但僅適用於 SQL、Python 和 R，並不支援 Scala</li><li>Single Node：此模式如字面僅有一個節點，不會有 Worker Node，執行Spark 的工作時會在 Driver Node執行 (也因此你會發現選擇 Standard 時他會要求你至少需要一個 Worker Node)</li></ol><p>除了 UI 的方式之外，也可以透過 <a href="https://docs.microsoft.com/en-us/azure/databricks/dev-tools/cli/clusters-cli">Clusters CLI </a>或 <a href="https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/clusters">Clusters API</a> 來對 cluster 進行操作</p><p>建立完成後，便能在 Cluster 的頁面中看到你建立的叢集的相關資訊及狀態</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mxghvkm4vtmMAag1Hv_CA.png" /></figure><h3>總結</h3><p>在 Azure 上其實還有許多進行 Machine Learning 你可以使用到的多項服務，希望能有機會在多寫幾篇介紹一下，另外，下一篇文章將會介紹到<a href="https://medium.com/@huier23/azure-databricks-%E5%88%86%E6%9E%90%E5%8F%8A%E8%A6%96%E8%A6%BA%E5%8C%96%E8%B3%87%E6%96%99-81e9d39b277b">如何使用 Azure Databrick 來實作資料的分析和視覺化</a>，歡迎對 Azure Databricks 有興趣的朋友，也可以藉由下篇文章，輕鬆上手看看囉！</p><h3>Reference</h3><ul><li>Wiki|<a href="https://zh.wikipedia.org/zh-tw/MapReduce">MapReduce</a></li><li>Microsoft Doc | <a href="https://docs.microsoft.com/en-us/azure/databricks/scenarios/what-is-azure-databricks">What is Azure Databricks</a></li><li>Microsoft Doc | <a href="https://docs.microsoft.com/en-us/azure/databricks/clusters/configure">Configure Clusters</a></li><li>Microsoft Doc | <a href="https://docs.microsoft.com/en-us/answers/questions/26097/can-anyone-please-post-the-differences-between-azu.html">Differences between HD Insight and Azure Data bricks?</a></li><li>Microsoft Doc | <a href="https://azure.microsoft.com/en-ca/blog/analytics-in-azure-remains-unmatched-with-new-innovations/">Analytics in Azure remains unmatched with new innovations</a></li><li>Databricks Doc | <a href="https://databricks.com/blog/2019/11/04/new-microsoft-azure-data-warehouse-service-and-azure-databricks-combine-analytics-bi-and-data-science.html">New Microsoft Azure Data Warehouse Service and Azure Databricks Combine Analytics, BI, and Data Science</a></li><li>element61 | <a href="https://www.element61.be/en/resource/when-use-azure-synapse-analytics-andor-azure-databricks">When to use Azure Synapse Analytics and/or Azure Databricks ?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b81dad814586" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[開始使用 Windows Terminal 吧]]></title>
            <link>https://huier23.medium.com/%E9%96%8B%E5%A7%8B%E4%BD%BF%E7%94%A8-windows-terminal-%E5%90%A7-cdc771678ed1?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdc771678ed1</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[cmder]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Sat, 07 Mar 2020 09:48:14 GMT</pubDate>
            <atom:updated>2021-04-16T19:17:56.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0-8TUVZBWUI7eHxQh_ODA.png" /></figure><p>改成開始使用 Windows 的時候最讓我不習慣的就是 command line tool，雖然有試用了 WSL (Windows Subsystem for Linux)，但還是不甚喜歡，後來在同事的介紹下幸運的認識了 Cmder，簡直是獲得救贖！</p><p>而 Microsoft 在 2019 Build 大會上宣佈推出一款全新的 Windows 終端機，名稱是 Windows Terminal，把目前 Windows上的<a href="https://zh.wikipedia.org/wiki/Windows_PowerShell">PowerShell</a>、<a href="https://zh.wikipedia.org/wiki/%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E5%AD%97%E5%85%83">CMD</a> 以及<a href="https://zh.wikipedia.org/wiki/Windows_Linux%E5%AD%90%E7%B3%BB%E7%BB%9F">Windows Linux 子系統</a>（WSL）三大環境實現了統一。</p><p>最令我驚豔的是，他的 icon 有夠可愛。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/86/1*YdrAwaF699DPDcju8KaJyQ.png" /><figcaption>Microsoft Terminal Icon</figcaption></figure><p>開玩笑的。</p><h3>基本使用介紹</h3><p>簡單來說，你可以在 Microsoft Terminal 的視窗裡面開啟 Powershell、cmd、Azure Cloud Shell ，甚至是你自己平常習慣使用的其他工具（當然還是要根據你所使用的工具是否可以有效與 Microsoft Terminal 整合）。像我自己就常常會使用到 Azure Cloud Shell，偶爾也會用到 Powershell，每次都要在到各自的地方去開視窗，有了 Microsoft Terminal 我就可以在一個視窗，不同分業中分別去開啟這些工具，對於懶惰的人，是不是超棒！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x70jMlVBseV8wABi7VXwmw.png" /><figcaption>Powershell 使用畫面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mPgAr3gCDeZgz-6rmkOaQ.png" /><figcaption>CMD 使用畫面</figcaption></figure><p>如果要開始下載 Windows Terminal，在 <a href="https://www.microsoft.com/zh-tw/p/windows-terminal-preview/9n0dx20hk701?activetab=pivot:overviewtab">Microsoft Store</a> 裡面就可以下在到囉，不過安裝前請注意已先將你的 Windows 系統升級到 Windows 10 1903 以上才可進行安裝。</p><h4>在 Terminal 中使用 Azure Cloud Shell</h4><p>新增一個 Azure Cloud Shell 的分頁，畫面會指示你去登入你的 Azure 帳戶。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTn7cBe7MpcsIeNKMywpMA.png" /></figure><p>按照指示行動直到出現以下畫面，就表示登入成功囉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZ0uo7AfRxM34JFs6HQfSA.png" /></figure><p>如果你有多個 tenant，會讓你先選擇你目前要使用的 tenant</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6HtjQ-WGUOlgTce2opp0w.png" /></figure><p>選擇完成後就可以開始使用囉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gexQZD7t1zL0fSHFDf3dwg.png" /></figure><h3>在 Windows Terminal 中整合 Cmder</h3><p>像我自己有習慣使用的工具，但我想要整合到 Windows Terminal，該怎麼做？每個工具的實作方式可能會有點不同，這邊僅介紹我常使用的 Cmder 整合方式。</p><p>Cmder 的整合方式其實跟你將 Cmder 整合進 VS code 的終端機中的方式滿大同小異的。</p><p>首先，如果你沒有在安裝 Cmder 時設定過環境變數，請先依據 Cmder 的offical doc 來設定相關的環境變數</p><p><a href="https://github.com/cmderdev/cmder/wiki/Setting-up-Environment-Variables">cmderdev/cmder</a></p><p>接著，在你的 Windows Terminal 中點選 Settings，會開啟一個 profile.json 的檔案。在 list 的這個欄位裡面多將以下貼上：</p><pre>{</pre><pre>&quot;guid&quot;: &quot;{5b4ef9a8-4506-4ac9-930a-5eb1fd0ebf20}&quot;,</pre><pre>&quot;name&quot;: &quot;Cmder&quot;,</pre><pre>&quot;commandline&quot;: &quot;cmd.exe /k %CMDER_ROOT%/vendor/init.bat&quot;,</pre><pre>&quot;icon&quot; : &quot;%CMDER_ROOT%/icons/cmder.ico&quot;,</pre><pre>&quot;hidden&quot;: false,</pre><pre>&quot;startingDirectory&quot; : &quot;%USERPROFILE%&quot;,</pre><pre>&quot;fontSize&quot;: 11,</pre><pre>&quot;background&quot;: &quot;#272822&quot;,</pre><pre>&quot;useAcrylic&quot; : true,</pre><pre>&quot;acrylicOpacity&quot; : 0.9</pre><pre>}</pre><ul><li><em>guid</em> ：每個項目的會有獨一的 guild，可自行設定，不須和我的範例一樣。</li><li><em>name</em>：在新增時所顯示的名稱</li><li><em>startingDirectory</em>：開啟時的目錄位置</li><li><em>fontSize</em>：字體大小</li><li><em>background</em>：背景顏色可以自行設定，我這裡選擇的顏色是跟我原本使用 cmder 的顏色一致的</li><li><em>useAcrylic</em>：這個項目我有點不太知道該如何解釋，有點類似是否要讓背景有透明模糊感，大概像是我以下截圖的感覺，可以透過 acrylicOpacity 來設定這樣的效果大概要多少</li></ul><p>同時，你可以在 defaultProfile 中設定預設要用哪一個 terminal。</p><pre>&quot;defaultProfile&quot;: &quot;{5b4ef9a8-4506-4ac9-930a-5eb1fd0ebf20}&quot;,</pre><h3>後記</h3><p>目前使用上來說，我現在都改成使用 Windows Terminal，尤其是需要不斷用 command 切換各個 server 的時候，可以開分頁的體驗真的很不錯，不得不說，這次的 Windows Terminal 超滿意！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiK-Im_rSeXzGz2zJbiW6A.png" /><figcaption>分頁可以自己改名字，就知道這個頁籤是連結到哪台 Server 不會搞混</figcaption></figure><h3>Reference</h3><ul><li><a href="https://github.com/microsoft/terminal">GitHub|Windows Terminal</a></li><li><a href="https://github.com/cmderdev/cmder/issues/2121">GitHub|Support new windows 10 1903 Terminal</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdc771678ed1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Azure App Service to deploy your static web]]></title>
            <link>https://huier23.medium.com/using-azure-app-service-to-deploy-your-static-web-3b6bf2945850?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b6bf2945850</guid>
            <category><![CDATA[static-websites]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[app-service]]></category>
            <category><![CDATA[web-app-development]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 08:01:33 GMT</pubDate>
            <atom:updated>2020-03-06T09:16:38.758Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UiGvB-O79Qm6je3FXMY4Hw.png" /></figure><p>If I have a static web and want to deploy to cloud service. How to do it with a simple way?</p><p>First, I search Azure App Service which is a PaaS (Platform as a service) provided by Microsoft. However, when I create the App Service in Azure portal, I need to choose run time for my resource. Even though I only need to publish a static web.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFKxsNcsuUvo3GNOS485sQ.png" /></figure><p>I find that there are a service called “Static Apps” in Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RGOb9hz2j9aAZv18Gh4CA.png" /></figure><p>But I can’t find any button or place I could add this resource. (☉д⊙)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPX7OBzN14lA0XGVHsC6hw.png" /></figure><p>Through a hour searching, there is a way to create a static app service in Azure is to use Azure CLI.</p><p>The Azure CLI is available to install in Windows, maxOS and Linux environments. It can also be run in a Docker container and Azure Cloud Shell. You can follow this <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">official document</a> to install or update Azure CLI.</p><h4>Create Resource in Azure</h4><p>You should be careful that your Azure CLI version is up-to-date with 2.1.0. I have used older version of 2.0.x and it would cause some problem when I create a html web app via Azure CLI.</p><p>All requirement was be equipped, go to the roots of project which you want to deploy and use the command as blow to create a static web app service.</p><p>&gt; az webapp up -n &lt;AppServiceName&gt; -g &lt;ResourceGroupName&gt; -l southeastasia --html</p><p>This command would help you to deploy your static web project to cloud. If you ignore resource group here, it would auto generate a resource group for you. Or you can also use cli to create one before launching the web app.</p><p>&gt; az group create -n &lt;ResourceGroupName&gt; -l southeastasia</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clK7olRmbiWS3rmJHN_B_Q.png" /></figure><p>After job finished, you can go to check the resource from Azure portal. Here is your static web app service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uFMMNeMXFjZ2r0RJCoR3A.png" /></figure><h4>Re-Deploy Your Project</h4><p>Next, When I edit my project and need to re-deploy to my web app service. Without using Azure CLI, you can utilize<strong> </strong>Visual Studio Code to re-deploy static website to existing web app service on Azure.</p><p>Before publishing project to cloud, you should install Azure App Service extension from VS code marketplace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*yT0fjDwtp8p-SB0wH-VQlQ.png" /></figure><p>Azure icon would be shown on navigation bar at left after you install and login azure account. This tool can help you to manage App Service on Azure such as restart, stop, delete or edit application settings, what’s more, managing related slots of App Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*5kOFFjKGWzaby3jzd0t2qQ.png" /></figure><p>And then, you only need to right click the resource you want to deploy and choose <em>Deploy to Web App</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*THWhwwdY2kQwwaZqywi-2A.png" /></figure><p>During deployment process, you can see the detail log message from output window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_NgpLJZ90I_NfDrqLFFxQ.png" /></figure><p>After receiving message <em>Deployment to “AppSerivceName” completed</em>. which means you have published your project successfully. Check the website, here you are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VePKzmHt0mYftoXruXmEw.png" /></figure><p>The sample code I used is from Microsoft. You can find the code from the official website.</p><h4>Reference</h4><ul><li><a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-html">Microsoft Doc | Create a static HTML web app in Azure</a></li><li><a href="https://docs.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-up">Microsoft Doc | az webapp Command</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b6bf2945850" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Security 學習筆記]]></title>
            <link>https://huier23.medium.com/continuous-security-%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-1a04c95e4f18?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a04c95e4f18</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[learning-notes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[continuous-security]]></category>
            <category><![CDATA[azure-devops]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 07:00:37 GMT</pubDate>
            <atom:updated>2021-04-16T19:12:29.415Z</atom:updated>
            <content:encoded><![CDATA[<p>除了怎麼寫程式、設計商業邏輯、怎麼部屬開發好的應用程式一直到去把整個開發的流程拉成一條條的管線做到自動化，在整個 DevOps 中，其實還有很重要的一環，也就是 Security 的部分，我們可能常常忽略它的重要性，但卻也是開發中最重要的一個環節（同時也非常的複雜），今年參加的 DevOps Day 關於 Security 的 Session 也不少，可見其日趨重要，但是關於在學習這塊上面，自己一直不能很上手，對於資訊安權這塊的了解真的甚少，於是想說那就先從基礎學起吧！</p><blockquote>Continuous security validation should be added at each step from development through production to help ensure the application is always secure. The goal of this approach is to switch the conversation with the security team from approving each release to approving the CI/CD process and having the ability to monitor and audit the process at any time.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*CaHbItOF8Y-QhwfEZSVm_w.png" /><figcaption>Source : <a href="https://docs.microsoft.com/en-us/azure/devops/migrate/security-validation-cicd-pipeline?view=azure-devops&amp;viewFallbackFrom=vsts">https://docs.microsoft.com/en-us/azure/devops/migrate/security-validation-cicd-pipeline?view=azure-devops&amp;viewFallbackFrom=vsts</a></figcaption></figure><p>在各個不同的軟體開發週期中，所需要做的 Security 把關也各有不同，要使用的工具也大有相異，以下針對上圖來做個比較詳細的介紹吧！</p><h3><strong>IDE / Pull Request</strong></h3><p>從工程師 commit code，對於程式碼品質的把關就此開始，而在這個階段可以透過引入以下項目來確保你的程式碼。</p><h4><strong>Static Code Analysis 靜態程式碼分析</strong></h4><p>IDE 中的靜態程式碼分析為首要關卡，以卻保在後續 CI/CD 的環節中不會有惡意漏洞產生。</p><h4><strong>Pull Request</strong></h4><p>通過 branch policy 機制的啟動，需要提交拉取請求（pull request, PR）才能啟動合併，而 PR 應要求進行代碼審查（code review），儘管這是一項手動操作，但卻十分重要，可用來提前找出程式碼中隱含的問題，及早發現及早修正。</p><h4><strong>Work item linking</strong></h4><p>在提交程式碼並進行合併的同時，要求團隊成員需連接到相對應的 work item，以利審核進行程式碼修改的原因</p><h3><strong>Continuous Integration 持續集成</strong></h3><p>CI 應作為先前討論的拉取請求（PR-CI）流程的一部分執行。 通常，兩次運行之間的主要區別在於 PR-CI 中不需要執行 CI 中建構程式碼及打包的步驟，而是運行靜態程式碼分析測試，以確保程式碼遵循安全性的所有規則。</p><p><strong>Static Code Analysis 靜態程式碼分析 及 OSS Vulnerability Scan</strong></p><p>以下幾項工具可在此階段使用：</p><ul><li>Visual Studio Code Analysis and the Roslyn Security Analyzers</li><li>Checkmarx</li><li>BinSkim：可針對二進位的檔案做分析而不需要原始碼</li><li>Fortify</li><li>White Source</li></ul><p>以上的許多工具都可以整合到 Azure DevOps 的 pipeline 中，請至 Visual Studio Market Place 查看。</p><p>而關於各個工具的細節，可以參考底下連結： <a href="https://devblogs.microsoft.com/devops/team-services-october-extensions-roundup-rugged-devops/">https://devblogs.microsoft.com/devops/team-services-october-extensions-roundup-rugged-devops/</a></p><h4><strong>Unit Test</strong></h4><p>工程師在完成新的功能更新後便同時也完成相對應的單元測試腳本，在CI的同時自動的去執行單元測試腳本，更能有效的確保開發團隊間在開發不同新功能時不會導致其他團的已開發完成的項目失效。</p><h3>部屬至 Dev、Test 環境</h3><p>驗證程式碼質量並將應用程式部署到開發測試後，該過程應驗證正在運行的系統是否含有安全漏洞。</p><h4><strong>Penetration test 滲透測試</strong></h4><p>針對駭客有可能的攻擊手法對於應用程式做測試，根據等級的不同可主要分為主動測試（Active Penetration Test）及被動測試（Passive Penetration Test）。</p><p>被動測試並不直接與目標應用程式接觸，從旁來發掘應用程式本身的漏洞，其可以快速的被執行。 而主動測試則是用於模擬駭客常用來攻擊網站的技術，使用大量不同的組合，以查看目標應用程式如何反應， 主動測試需要較長的執行時間，通常建議在半夜運行。使用的工具：</p><ul><li>OWASP ZAP</li></ul><p>OWASP 是一個全球性的非營利組織，提供免費的滲透測試工具，其提供 API或 docker image 的服務，可以將此工具與部屬的環境整合。OWASP ZAP 可以安裝在任何機器上，或將 image 整合至 Azure Container Services 中使用，以達到 image 的自動更新、同時啟動多個 instance 來掃描企業內的多個應用程式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Ucx3OyPnwbwCXITCYS5T9Q.png" /><figcaption>Application CI / CD pipeline 和運行時間較長的 Nightly OWASP ZAP pipeline 步驟</figcaption></figure><p>通常，在白天運行的 CI/CD Pipeline 建議在幾分鐘內變運行完成。並可透過在夜間執行較細部掃描的功能。如 OWASP ZAP 可以搜索網站並運行完整的Active Scan，以評估可能的漏洞。</p><h4><strong>Infrastructure Scan</strong></h4><p>除了驗證應用程式本身之外，還應驗證基礎結構以檢查是否存在任何漏洞。 若使用如同 Azure 等的公有雲服務，都有提供相對應的工具來協助你的基礎結構。如 Azure 中就有提供像是 Azure Security Center 或是 Azure Policy 等等。</p><h3>Reference</h3><p><a href="https://docs.microsoft.com/en-us/azure/devops/migrate/security-validation-cicd-pipeline?view=azure-devops&amp;viewFallbackFrom=vsts">Learn how to add continuous security validation to your CI/CD pipeline | Microsoft Doc</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a04c95e4f18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python 實作 Azure Cosmos (二) — CosmosClient]]></title>
            <link>https://huier23.medium.com/python-%E5%AF%A6%E4%BD%9C-azure-cosmos-%E4%BA%8C-cosmosclient-938d9c650ce5?source=rss-dce085443094------2</link>
            <guid isPermaLink="false">https://medium.com/p/938d9c650ce5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[cosmosdb]]></category>
            <category><![CDATA[cosmos-sdk]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Where]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 13:20:13 GMT</pubDate>
            <atom:updated>2019-10-22T16:53:49.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python 實作 Azure Cosmos DB (二) — CosmosClient</h3><p>開始之前，還沒有看過（一）的，記得先看了解環境如何設置喔！</p><p><a href="https://medium.com/@huier23/python-%E5%AF%A6%E4%BD%9C-azure-cosmos-db-%E4%B8%80-%E7%92%B0%E5%A2%83%E5%BB%BA%E7%BD%AE-7d6efe2ae1cb">Python 實作 Azure Cosmos DB (一) — 環境建置</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lca2ZeTeqmeIN_f959q5dQ.png" /></figure><p>在 Azure 上建立好 Cosmos 資源後，接著就會需要新增 Database、Collection 及資料等，透過使用 CosmosClient 這個 class，你可以對 Cosmos 發送 request ，進行像是新增、刪除、更新、取代等的操作行為。查看文件是一個好習慣，這裡整理的 CosmosClient 可操作的動作。</p><p><a href="https://docs.microsoft.com/zh-tw/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python#definition">azure.cosmos.cosmos_client.CosmosClient class</a></p><h4>初始化建立連線</h4><p>首先，透過以下方法建立 CosmosClient，其中會需要使用到 Cosmos 的 endpoint 和 key。</p><pre>CosmosClient(url_connection, auth, connection_policy=None, consistency_level=&#39;Session&#39;)</pre><p>將 ENDPONIT 及 PRIMARYKEY 改成上一篇記錄下來的 URI 和 Primary key。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3166ff80838fe6c987f8d1286fb0c98/href">https://medium.com/media/c3166ff80838fe6c987f8d1286fb0c98/href</a></iframe><p>一般來說，會比較建議把這些連線字串寫在 config 檔裡面，而非寫死在程式碼當中。</p><h4>建立 Database、Container 及資料</h4><p>使用 CreateDatbase 的方法來建立一個資料庫。</p><pre>CreateDatabase(database, options=None)</pre><p>使用 CreateContainer 來建立 Container。</p><pre>CreateContainer(database_link, collection, options=None)</pre><p>最後，透過 CreateItem 來新增一筆資料。</p><pre>CreateItem(database_or_Container_link, document, options=None)</pre><p>你可以參考以下的程式碼來完成從建立 Database、Container 到添加資料一整個流程，而我這邊是設定以 region 為 partition key。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9fd8ac76ed379c485596c253be75972/href">https://medium.com/media/d9fd8ac76ed379c485596c253be75972/href</a></iframe><h4>搜索資料</h4><p>資料庫最重要的，就是如何去撈取資料。因為我們使用的是 Cosmos SQL API，因此可以使用 SQL 的語法去做資料庫資料的篩選動作。使用 QueryItems 的方法可以進行資料的搜索。</p><pre>QueryItems(database_or_Container_link, query, options=None, partition_key=None)</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72177a967755395b95fdaff42d014d0f/href">https://medium.com/media/72177a967755395b95fdaff42d014d0f/href</a></iframe><h4>項目更新 / 取代</h4><p>在處理 Database 資料的同時，我們可能會遇到需要去更新資料的問題。</p><p><strong>Upsert</strong></p><p>根據官方的說明，UpsertItem 的方法解釋為 Upserts a document in a collection，很棒很棒，完全不懂！</p><pre><a href="https://docs.microsoft.com/zh-tw/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python#upsertitem-database-or-container-link--document--options-none-">UpsertItem(database_or_Container_link, document, options=None)</a></pre><p>利用 Document ID 或 Database ID 來搜尋符合給定 Item ID 的項目，如有相同 ID 則取代；若沒有則新增一筆。若你不希望沒有找到 ID 時直接新增一筆，你可以將 option = true。</p><pre>options[&#39;disableAutomaticIdGeneration&#39;] <a href="https://docs.python.org/3/library/functions.html#bool">bool</a></pre><pre>Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned.</pre><p><strong>當你需要更新你 Document 裡的資料時，你比較適合使用 Upsert 這個方法。</strong></p><p><strong>Replace</strong></p><p>利用 Item link 來搜尋並取代一整個項目。所以使用這個方法是直接去找你要取代的 document 項目，它不會去管你的 ID 是否相同，直接取代。</p><pre>ReplaceItem(document_link, new_document, options=None)</pre><blockquote>關於 Item link 你可以在把一整筆資料撈出來的同時，發現除了當初建立資料的欄位，系統自動也幫你新增了其他欄位供 Cosmos DB 使用，你可以透過系統建立的 [_self] 欄位來撈取 Item link。</blockquote><p><strong>當你需要取代特定一筆資料時，建議使用 Replace 這個方法。</strong></p><p>兩個的 link 連結可能會有點不同。如果是 Replace 的話，會先用 query 的方式把 item 撈出來，在用 _self 這個欄位取得連結。</p><pre>client.ReplaceItem(item[&#39;_self&#39;],newcontent)</pre><p>而如果是使用 Upsert 的話，則可直接使用 Container 的 link。</p><pre>client.UpsertItem(container_link,newcontent,True)</pre><h4>刪除資料</h4><p>這邊很簡單的你可以選擇要刪除 Database、Container 或 Item。</p><pre>DeleteDatabase(database_link, options=None)</pre><pre>DeleteContainer(collection_link, options=None)</pre><pre>DeleteItem(document_link, options=None)</pre><h4>後記</h4><p>今天先簡單的教大家快速的上手 Azure Cosmos DB Pyhton SDK，如果還有機會的話，希望還可以更深入的寫教學。</p><p>只是，總感覺遙遙無期呢！⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄</p><h4>Reference</h4><ul><li><a href="https://docs.microsoft.com/zh-tw/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python#definition">Microsoft Doc｜CosmosClient Class</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938d9c650ce5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>