Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always treat attributes as text. #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/debian/.devcontainer/base.Dockerfile

# [Choice] Debian version: bullseye, buster, stretch
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

# ** [Optional] Uncomment this section to install additional packages. **
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends build-essential
28 changes: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/debian
{
"name": "Debian",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian version: bullseye, buster, stretch
"args": { "VARIANT": "buster" }
},

// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
70 changes: 70 additions & 0 deletions .github/workflows/sosicon-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
name: Sosicon CI

on:
push:
branches-ignore:
- master
paths:
- '**'
- '.github/workflows/sosicon-ci.yaml'

jobs:

pre_job:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
today: ${{ steps.today.outputs.today }}
steps:
- name: Extract branch name
id: extract_branch
shell: bash
run: echo "##[set-output name=branch;]$(BRANCH=${GITHUB_REF#refs/heads/}; echo ${BRANCH//\//-})"
- name: Current date as tag
id: today
shell: bash
run: echo "::set-output name=today::$(date -I)"

main:
runs-on: ubuntu-latest
needs: pre_job
env:
DOCKER_BUILDKIT: 1
FQ_IMAGE: ${{ format('ghcr.io/arkivverket/sosicon:{0}-{1}', needs.pre_job.outputs.branch, github.sha) }}
ACR: ${{ format('arkivverket.azurecr.io/da-ssrsak-visning') }}
IMAGE: ${{ github.event.repository.name }}
TAG: ${{ needs.pre_job.outputs.today }}
steps:
- uses: actions/[email protected]
- name: Login to GitHub Package Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.FQ_IMAGE }}
- name: Container scan
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.FQ_IMAGE }}
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Tag to ACR
run: docker tag ${{ env.FQ_IMAGE }} ${ACR}/${IMAGE}:${TAG}
- name: Login to ACR
uses: Azure/docker-login@v1
with:
username: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_PASSWORD }}
login-server: https://arkivverket.azurecr.io
- name: Publish to ACR
run: docker push ${ACR}/${IMAGE}:${TAG}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM amd64/debian:buster-slim AS builder

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends build-essential

WORKDIR /sosicon

COPY src src

RUN pwd && mkdir -p bin/cmd/linux64

RUN make -C src

FROM amd64/debian:buster-slim

COPY --from=builder /sosicon/bin/cmd/linux64/sosicon /usr/bin/sosicon

ENTRYPOINT ["/usr/bin/sosicon"]

CMD ["-help"]
Binary file modified bin/cmd/linux64/sosicon
Binary file not shown.
18 changes: 2 additions & 16 deletions src/converter_sosi2psql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,8 @@ buildCreateStatement( Wkt wktGeom,
for( itrFields = f->begin(); itrFields != f->end(); itrFields++ ) {
std::string field = itrFields->first;
std::string::size_type len = itrFields->second.length();
bool isNumeric = itrFields->second.isNumeric();
if( field != geomField ) {
if( isNumeric && len < 10 ) {
ss << ","
<< field
<< " INTEGER";
}
else if( isNumeric && len < 19 ) {
ss << ","
<< field
<< " BIGINT";
}
else if( len > 255 ) {
if( len > 255 ) {
ss << ","
<< field
<< " TEXT";
Expand Down Expand Up @@ -202,14 +191,11 @@ buildInsertStatement( Wkt wktGeom,
}
std::string val = utils::trim( ( *row )[ key ] );
if( val.empty() ) {
sqlValues += itrFields->second.isNumeric() ? "NULL," : "'',";
sqlValues += "'',";
}
else if( key == geomField ) {
sqlValues += val + ",";
}
else if( itrFields->second.isNumeric() ) {
sqlValues += utils::sqlNormalize( val ) + ",";
}
else {
sqlValues += "'" + utils::sqlNormalize( val ) + "',";
}
Expand Down
19 changes: 2 additions & 17 deletions src/converter_sosi2psql.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,14 @@ namespace sosicon {
class Field {
std::string::size_type mMaxLength;
std::string::size_type mMinLength;
bool mIsNumeric;
public:
bool isNumeric() {
if( mMaxLength == mMinLength ) {
// Treat fixed-length numerical data as character field, since they
// are in fact non-arithmetic types types like dates, phone numbers
// or serial numbers.
mIsNumeric = false;
}
return mIsNumeric;
}
std::string::size_type length() {
return mMaxLength;
}
Field() {
mIsNumeric = true;
mMaxLength = 0;
}
Field( std::string& str ) {
mIsNumeric = true;
mMaxLength = 0;
mMinLength = std::numeric_limits<std::string::size_type>::max();
expand( str );
Expand All @@ -82,9 +70,6 @@ namespace sosicon {
std::string::size_type len = str.length();
mMinLength = std::min( mMinLength, len );
mMaxLength = std::max( mMaxLength, len );
if( mIsNumeric ) {
mIsNumeric = utils::isNumeric( str );
}
return mMaxLength;
}
};
Expand Down Expand Up @@ -307,7 +292,7 @@ namespace sosicon {

//! Constructor
ConverterSosi2psql() : mCmd( 0 ) { }

//! Destructor
virtual ~ConverterSosi2psql() { }

Expand All @@ -328,7 +313,7 @@ namespace sosicon {

}; // class ConverterSosi2tsv
/*! @} end group converters */

}; // namespace sosi2tsv

#endif