Monday, March 14, 2022

Sitecore Developer Blog Entry #0x01

My day job involves working for a company that uses Sitecore 9 for a CMS. This is used to run a news and continuing education site for medical professionals.

Today I'm working on three tasks. One is for the publish pipeline, when a user tries to access a page for an old item that we usually redirect to a third party site. If the Sitecore item is missing a piece of information in a field used to form the redirect link to the proper 3rd party site page, the user should get a 404. The third task is wrapping up an Extract Transform Load (ETL) project.

I wasn't too familiar with the pipelining process in Sitecore as we have it implemented, so I worked with a more experienced developer, basically pair programming our way though the task.

For the redirect to 404 task, I also worked with a more experienced developer, though instead of pair programming we were both debugging the changes, making different edits, and sharing progress when one of us made it past a particular stumbling block.

My last task of the day was lower priority, but after I finished up the high priority tasks, I wanted to wrap up a project. This is a long-running project, performing an ETL workflow. Basically, it takes survey responses for online and in-person activities which we get in reports as Excel workbooks or CSVs. Some of the Excel workbooks contain only one table, and others contains several. Furthermore, there are variations on where each type of report stores certain pieces of information. I wrote the utility originally in Dot Net Core 2, but have recently upgraded it to Dot Net Framework 6. The program scans the various input files, and collates them into one unified data structure for storing the information we want. Then, the ETL process finishes by loading this data into our Google Big Query data warehouse.

Today was a pretty productive day, and my JIRA lanes are clear. That's a good thing, since the production build for the sprint is tomorrow morning.

Sunday, March 13, 2022

Server-Side Swift Developer Blog Entry #0x01: Hello World in Plot with Vapor

You are going to learn how to use Plot, a DSL for writing HTML from John Sundell, with the Vapor framework.

This Hello World tutorial requires that you have Swift and Vapor installed. This code was written on macOS using Xcode, but should work on Linux as well.

Use the command line to create a new Vapor app:

devdir $: vapor new HelloVaporPlot

With the editor of your choice, pop open ./HelloVaporPlot/Package.swift, and add the following package into your dependencies:

    url: "https://github.com/johnsundell/plot.git

    from: "0.10.0"

Additionally, add the following product to your App .target dependencies

    name: "Plot"

    package: "plot"

Your Package.swift should look something like the code below:

// swift-tools-version:5.5

import PackageDescription


let package = Package(

    name: "HelloPlot",

    platforms: [

       .macOS(.v12)

    ],

    dependencies: [

        // 💧 A server-side Swift web framework.

        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),

        .package(url: "https://github.com/johnsundell/plot.git", from: "0.10.0"),

    ],

    targets: [

        .target(

            name: "App",

            dependencies: [

                .product(name: "Vapor", package: "vapor"), .product(name: "Plot" ,package: "plot" )

            ],

            swiftSettings: [

                // Enable better optimizations when building in Release configuration. Despite the use of

                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release

                // builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.

                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))

            ]

        ),

        .executableTarget(name: "Run", dependencies: [.target(name: "App")]),

        .testTarget(name: "AppTests", dependencies: [

            .target(name: "App"),

            .product(name: "XCTVapor", package: "vapor"),

        ])

    ]

)

Now, we are going to head over to ./HelloVaporPlot/Sources/App/routes.swift
At the bottom of the file, add an extension to HTML so that it conforms to ResponseEncodable. There is probably a more responsible place to stash the extension, but it works here.

extension HTML : ResponseEncodable {

    public func encodeResponse(for request: Request) -> EventLoopFuture<Response> {

        let res = Response(headers: ["content-type": "text/html; charset=utf-8"], body: .init(string: self.render()))

        return res.encodeResponse(for: request)

    }

}

The last step is to add the route with the Plot code to the bottom of the routes function:

app.get("helloplot") { req -> HTML in

        HTML(

            .head(

                .title("Plot on Vapor")

            ),

            .body(

                .div(

                    .h1("Hello Swift Developer!")

                )

            )

        )

    }

Now, build and run, and hit the endpoint http://127.0.0.1:8080/helloplot to see your work in action!

Citations:

I got some help from the following pages:

    • https://inuk.blog/posts/plot-and-vapor/
    • https://medium.com/@andreabellotto88/how-to-use-plot-in-vapor-3-0-404316ce24c0
    • https://github.com/johnsundell/plot 

Wednesday, March 2, 2022

Homelab Hacker Blog Entry #0x11: Nextcloud plugin on TrueNAS

 Maybe this works out of the box for you if you leave it configured for NAT instead of switching it to DHCP.

I get this error when navigating to the IP address for Nextcloud:

Access through untrusted domain

Please contact your administrator. If you are an administrator, edit the "trusted_domains" setting in config/config.php like the example in config.sample.php.

That means we need to break into the jail and modify some config.

open a shell into the jail

vi /usr/local/www/netcloud/config/config.php

move down to the section where 'localhost' and the IP address of the truenas box are listed, and change the list to include the proper IP address and any hostnames that might be mapped to it.

How to exit Vi: press escape, then type colon (:) then wq enter (write to file, quit)