diff --git a/.env b/.env index cf2b1bed25..1f4049bf50 100644 --- a/.env +++ b/.env @@ -47,3 +47,6 @@ RECOMMENDATION_SERVICE_ADDR=recommendationservice:${RECOMMENDATION_SERVICE_PORT} SHIPPING_SERVICE_PORT=50051 SHIPPING_SERVICE_ADDR=shippingservice:${SHIPPING_SERVICE_PORT} + +FEATURE_FLAG_SERVICE_PORT=50052 +FEATURE_FLAG_GRPC_SERVICE_PORT=50053 diff --git a/CHANGELOG.md b/CHANGELOG.md index dbfd016e99..0884c0df1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,3 +17,5 @@ release. ([#26](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/26)) * Added span attributes to frontend service ([#82](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/82)) +* Added feature flag service implementation + ([#141](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/141)) diff --git a/docker-compose.yml b/docker-compose.yml index 7077f7f346..84db8dc268 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ services: - ./src/otelcollector/otelcol-config.yml:/etc/otelcol-config.yml ports: - "4317" + - "4318" depends_on: - jaeger @@ -198,6 +199,29 @@ services: - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - OTEL_RESOURCE_ATTRIBUTES=service.name=shippingservice + # FeatureFlagService + featureflagservice: + build: + context: ./src/featureflagservice + ports: + - "${FEATURE_FLAG_SERVICE_PORT}" + - "${FEATURE_FLAG_GRPC_SERVICE_PORT}" + environment: + - PORT=${FEATURE_FLAG_SERVICE_PORT} + - GRPC_PORT=${FEATURE_FLAG_GRPC_SERVICE_PORT} + - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + - OTEL_RESOURCE_ATTRIBUTES=service.name=featureflagservice + - DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs + depends_on: + - ffs_postgres + + ffs_postgres: + image: cimg/postgres:14.2 + environment: + - POSTGRES_USER=ffs + - POSTGRES_DB=ffs + - POSTGRES_PASSWORD=ffs + # LoadGenerator loadgenerator: image: ${IMAGE_NAME}:${IMAGE_VERSION}-loadgenerator diff --git a/src/featureflagservice/.dockerignore b/src/featureflagservice/.dockerignore new file mode 100644 index 0000000000..61a73933c8 --- /dev/null +++ b/src/featureflagservice/.dockerignore @@ -0,0 +1,45 @@ +# This file excludes paths from the Docker build context. +# +# By default, Docker's build context includes all files (and folders) in the +# current directory. Even if a file isn't copied into the container it is still sent to +# the Docker daemon. +# +# There are multiple reasons to exclude files from the build context: +# +# 1. Prevent nested folders from being copied into the container (ex: exclude +# /assets/node_modules when copying /assets) +# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc) +# 3. Avoid sending files containing sensitive information +# +# More information on using .dockerignore is available here: +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +.dockerignore + +# Ignore git, but keep git HEAD and refs to access current commit hash if needed: +# +# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat +# d0b8727759e1e0e7aa3d41707d12376e373d5ecc +.git +!.git/HEAD +!.git/refs + +# Common development/test artifacts +/cover/ +/doc/ +/test/ +/tmp/ +.elixir_ls + +# Mix artifacts +/_build/ +/deps/ +*.ez + +# Generated on crash by the VM +erl_crash.dump + +# Static artifacts - These should be fetched and built inside the Docker image +/assets/node_modules/ +/priv/static/assets/ +/priv/static/cache_manifest.json diff --git a/src/featureflagservice/.formatter.exs b/src/featureflagservice/.formatter.exs new file mode 100644 index 0000000000..8a6391c6a6 --- /dev/null +++ b/src/featureflagservice/.formatter.exs @@ -0,0 +1,5 @@ +[ + import_deps: [:ecto, :phoenix], + inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], + subdirectories: ["priv/*/migrations"] +] diff --git a/src/featureflagservice/.gitignore b/src/featureflagservice/.gitignore new file mode 100644 index 0000000000..b76e6cf3af --- /dev/null +++ b/src/featureflagservice/.gitignore @@ -0,0 +1,35 @@ +# The directory Mix will write compiled artifacts to. +/_build/ +ffs_grpc/_build/ +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +featureflagservice-*.tar + +# Ignore assets that are produced by build tools. +/priv/static/assets/ + +# Ignore digested assets cache. +/priv/static/cache_manifest.json + +# In case you use Node.js/npm, you want to ignore these. +npm-debug.log +/assets/node_modules/ + +/assets/vendor/ diff --git a/src/featureflagservice/Dockerfile b/src/featureflagservice/Dockerfile new file mode 100644 index 0000000000..66ea291ea1 --- /dev/null +++ b/src/featureflagservice/Dockerfile @@ -0,0 +1,93 @@ +# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of +# Alpine to avoid DNS resolution issues in production. +# +# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu +# https://hub.docker.com/_/ubuntu?tab=tags +# +# +# This file is based on these images: +# +# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image +# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image +# - https://pkgs.org/ - resource for finding needed packages +# - Ex: hexpm/elixir:1.13.3-erlang-25.0-debian-bullseye-20210902-slim +# +ARG ELIXIR_VERSION=1.13.3 +ARG OTP_VERSION=25.0 +ARG DEBIAN_VERSION=bullseye-20210902-slim + +ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" +ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" + +FROM ${BUILDER_IMAGE} as builder + +# install build dependencies +RUN apt-get update -y && apt-get install -y build-essential git \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* + +# prepare build dir +WORKDIR /app + +# install hex + rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# set build ENV +ENV MIX_ENV="prod" + +# install mix dependencies +COPY mix.exs mix.lock ./ +RUN mix deps.get --only $MIX_ENV +RUN mkdir config + +# copy compile-time config files before we compile dependencies +# to ensure any relevant config change will trigger the dependencies +# to be re-compiled. +COPY config/config.exs config/${MIX_ENV}.exs config/ +RUN mix deps.compile + +COPY priv priv + +COPY lib lib + +COPY assets assets + +# compile assets +RUN mix assets.deploy + +# Compile the release +RUN mix compile + +# Changes to config/runtime.exs don't require recompiling the code +COPY config/runtime.exs config/ + +COPY rel rel +RUN mix release + +# start a new build stage so that the final image will only contain +# the compiled release and other runtime necessities +FROM ${RUNNER_IMAGE} + +RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* + +# Set the locale +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen + +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +WORKDIR "/app" +RUN chown nobody /app + +# set runner ENV +ENV MIX_ENV="prod" +ENV SECRET_KEY_BASE="mNhoOKKxgyvBIwbtw0P23waQcvUOmusb2U1moG2I7JQ3Bt6+MlGb5ZTrHwqbqy7j" + +# Only copy the final release from the build stage +COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/featureflagservice ./ + +USER nobody + +CMD ["/app/bin/server"] diff --git a/src/featureflagservice/README.md b/src/featureflagservice/README.md new file mode 100644 index 0000000000..9503485ea1 --- /dev/null +++ b/src/featureflagservice/README.md @@ -0,0 +1,45 @@ +# Feature Flag Service + +This project provides an web interface for creating and updating feature flags +and a GRPC service for fetching the status of flags by their name. Each runs on +their own port but are in the same Release. + +## Running + +To run individually and not part of the demo the Release can be built with +`mix`: + +``` shell +$ MIX_ENV=prod mix release +``` + +Then start Postgres with `docker compose` + +``` shell +$ docker compose up +``` + +And run the Release: + +``` shell +$ PHX_SERVER=1 PORT=4000 GRPC_PORT=4001 _build/prod/rel/featureflagservice/bin/featureflagservice start_iex +``` + +## Instrumentation + +Traces of interaction with the web interface is provided by the OpenTelemetry +[Phoenix +instrumentation](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_phoenix) +with Spans for database queries added through the [Ecto +instrumentation](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_ecto). + +The GRPC service uses [grpcbox](https://github.com/tsloughter/grpcbox) and uses +the [grpcbox +interceptor](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_grpcbox) +for instrumentation. + +## Building Protos + +A copy of the `FeatureFlagService` protos from `demo.proto` are kept in +`proto/featureflag.proto` and `rebar3 grpc gen` will update the corresponding +Erlang module `src/ffs_featureflag_pb.erl`. diff --git a/src/featureflagservice/assets/css/app.css b/src/featureflagservice/assets/css/app.css new file mode 100644 index 0000000000..19c2e51edc --- /dev/null +++ b/src/featureflagservice/assets/css/app.css @@ -0,0 +1,120 @@ +/* This file is for your main application CSS */ +@import "./phoenix.css"; + +/* Alerts and form errors used by phx.new */ +.alert { + padding: 15px; + margin-bottom: 20px; + border: 1px solid transparent; + border-radius: 4px; +} +.alert-info { + color: #31708f; + background-color: #d9edf7; + border-color: #bce8f1; +} +.alert-warning { + color: #8a6d3b; + background-color: #fcf8e3; + border-color: #faebcc; +} +.alert-danger { + color: #a94442; + background-color: #f2dede; + border-color: #ebccd1; +} +.alert p { + margin-bottom: 0; +} +.alert:empty { + display: none; +} +.invalid-feedback { + color: #a94442; + display: block; + margin: -1rem 0 2rem; +} + +/* LiveView specific classes for your customization */ +.phx-no-feedback.invalid-feedback, +.phx-no-feedback .invalid-feedback { + display: none; +} + +.phx-click-loading { + opacity: 0.5; + transition: opacity 1s ease-out; +} + +.phx-loading{ + cursor: wait; +} + +.phx-modal { + opacity: 1!important; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.4); +} + +.phx-modal-content { + background-color: #fefefe; + margin: 15vh auto; + padding: 20px; + border: 1px solid #888; + width: 80%; +} + +.phx-modal-close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.phx-modal-close:hover, +.phx-modal-close:focus { + color: black; + text-decoration: none; + cursor: pointer; +} + +.fade-in-scale { + animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys; +} + +.fade-out-scale { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys; +} + +.fade-in { + animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys; +} +.fade-out { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys; +} + +@keyframes fade-in-scale-keys{ + 0% { scale: 0.95; opacity: 0; } + 100% { scale: 1.0; opacity: 1; } +} + +@keyframes fade-out-scale-keys{ + 0% { scale: 1.0; opacity: 1; } + 100% { scale: 0.95; opacity: 0; } +} + +@keyframes fade-in-keys{ + 0% { opacity: 0; } + 100% { opacity: 1; } +} + +@keyframes fade-out-keys{ + 0% { opacity: 1; } + 100% { opacity: 0; } +} diff --git a/src/featureflagservice/assets/css/phoenix.css b/src/featureflagservice/assets/css/phoenix.css new file mode 100644 index 0000000000..0d59050f89 --- /dev/null +++ b/src/featureflagservice/assets/css/phoenix.css @@ -0,0 +1,101 @@ +/* Includes some default style for the starter application. + * This can be safely deleted to start fresh. + */ + +/* Milligram v1.4.1 https://milligram.github.io + * Copyright (c) 2020 CJ Patoilo Licensed under the MIT license + */ + +*,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;letter-spacing:.01em;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='color'],input[type='date'],input[type='datetime'],input[type='datetime-local'],input[type='email'],input[type='month'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],input[type='week'],input:not([type]),textarea,select{-webkit-appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem .7rem;width:100%}input[type='color']:focus,input[type='date']:focus,input[type='datetime']:focus,input[type='datetime-local']:focus,input[type='email']:focus,input[type='month']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,input[type='week']:focus,input:not([type]):focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}select[multiple]{background:none;height:auto}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.container{margin:0 auto;max-width:112.0rem;padding:0 2.0rem;position:relative;width:100%}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-40{margin-left:40%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-60{margin-left:60%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;display:block;overflow-x:auto;text-align:left;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}@media (min-width: 40rem){table{display:table;overflow-x:initial}}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right} + +/* General style */ +h1{font-size: 3.6rem; line-height: 1.25} +h2{font-size: 2.8rem; line-height: 1.3} +h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35} +h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5} +h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4} +h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2} +pre{padding: 1em;} + +.container{ + margin: 0 auto; + max-width: 80.0rem; + padding: 0 2.0rem; + position: relative; + width: 100% +} +select { + width: auto; +} + +/* Phoenix promo and logo */ +.phx-hero { + text-align: center; + border-bottom: 1px solid #e3e3e3; + background: #eee; + border-radius: 6px; + padding: 3em 3em 1em; + margin-bottom: 3rem; + font-weight: 200; + font-size: 120%; +} +.phx-hero input { + background: #ffffff; +} +.phx-logo { + min-width: 300px; + margin: 1rem; + display: block; +} +.phx-logo img { + width: auto; + display: block; +} + +/* Headers */ +header { + width: 100%; + background: #fdfdfd; + border-bottom: 1px solid #eaeaea; + margin-bottom: 2rem; +} +header section { + align-items: center; + display: flex; + flex-direction: column; + justify-content: space-between; +} +header section :first-child { + order: 2; +} +header section :last-child { + order: 1; +} +header nav ul, +header nav li { + margin: 0; + padding: 0; + display: block; + text-align: right; + white-space: nowrap; +} +header nav ul { + margin: 1rem; + margin-top: 0; +} +header nav a { + display: block; +} + +@media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */ + header section { + flex-direction: row; + } + header nav ul { + margin: 1rem; + } + .phx-logo { + flex-basis: 527px; + margin: 2rem 1rem; + } +} diff --git a/src/featureflagservice/assets/js/app.js b/src/featureflagservice/assets/js/app.js new file mode 100644 index 0000000000..2ca06a5664 --- /dev/null +++ b/src/featureflagservice/assets/js/app.js @@ -0,0 +1,45 @@ +// We import the CSS which is extracted to its own file by esbuild. +// Remove this line if you add a your own CSS build pipeline (e.g postcss). +import "../css/app.css" + +// If you want to use Phoenix channels, run `mix help phx.gen.channel` +// to get started and then uncomment the line below. +// import "./user_socket.js" + +// You can include dependencies in two ways. +// +// The simplest option is to put them in assets/vendor and +// import them using relative paths: +// +// import "../vendor/some-package.js" +// +// Alternatively, you can `npm install some-package --prefix assets` and import +// them using a path starting with the package name: +// +// import "some-package" +// + +// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. +import "phoenix_html" +// Establish Phoenix Socket and LiveView configuration. +import {Socket} from "phoenix" +import {LiveSocket} from "phoenix_live_view" +import topbar from "../vendor/topbar" + +let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) + +// Show progress bar on live navigation and form submits +topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) +window.addEventListener("phx:page-loading-start", info => topbar.show()) +window.addEventListener("phx:page-loading-stop", info => topbar.hide()) + +// connect if there are any LiveViews on the page +liveSocket.connect() + +// expose liveSocket on window for web console debug logs and latency simulation: +// >> liveSocket.enableDebug() +// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session +// >> liveSocket.disableLatencySim() +window.liveSocket = liveSocket + diff --git a/src/featureflagservice/config/config.exs b/src/featureflagservice/config/config.exs new file mode 100644 index 0000000000..24a34818ca --- /dev/null +++ b/src/featureflagservice/config/config.exs @@ -0,0 +1,55 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Config module. +# +# This configuration file is loaded before any dependency and +# is restricted to this project. + +# General application configuration +import Config + +config :featureflagservice, + ecto_repos: [Featureflagservice.Repo] + +# Configures the endpoint +config :featureflagservice, FeatureflagserviceWeb.Endpoint, + url: [host: "localhost"], + render_errors: [view: FeatureflagserviceWeb.ErrorView, accepts: ~w(html json), layout: false], + pubsub_server: Featureflagservice.PubSub, + live_view: [signing_salt: "T88WPl/Q"] + +# Configures the mailer +# +# By default it uses the "Local" adapter which stores the emails +# locally. You can see the emails in your browser, at "/dev/mailbox". +# +# For production it's recommended to configure a different adapter +# at the `config/runtime.exs`. +config :featureflagservice, Featureflagservice.Mailer, adapter: Swoosh.Adapters.Local + +# Swoosh API client is needed for adapters other than SMTP. +config :swoosh, :api_client, false + +# Configure esbuild (the version is required) +config :esbuild, + version: "0.14.29", + default: [ + args: + ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + cd: Path.expand("../assets", __DIR__), + env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} + ] + +# Configures Elixir's Logger +config :logger, :console, + format: "$time $metadata[$level] $message\n", + metadata: [:request_id] + +config :logger, + level: :debug + +# Use Jason for JSON parsing in Phoenix +config :phoenix, :json_library, Jason + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{config_env()}.exs" diff --git a/src/featureflagservice/config/dev.exs b/src/featureflagservice/config/dev.exs new file mode 100644 index 0000000000..6312e977fa --- /dev/null +++ b/src/featureflagservice/config/dev.exs @@ -0,0 +1,76 @@ +import Config + +# Configure your database +config :featureflagservice, Featureflagservice.Repo, + username: "postgres", + password: "postgres", + hostname: "localhost", + database: "featureflagservice_dev", + stacktrace: true, + show_sensitive_data_on_connection_error: true, + pool_size: 10 + +# For development, we disable any cache and enable +# debugging and code reloading. +# +# The watchers configuration can be used to run external +# watchers to your application. For example, we use it +# with esbuild to bundle .js and .css sources. +config :featureflagservice, FeatureflagserviceWeb.Endpoint, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {127, 0, 0, 1}, port: 4000], + check_origin: false, + code_reloader: true, + debug_errors: true, + secret_key_base: "GH1AJrEOJEVmzyUE+5kgz2cfBEOg5qPBlTYVive++6s/QS0BE3xjNoRCd7xI3zSv", + watchers: [ + # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) + esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]} + ] + +# ## SSL Support +# +# In order to use HTTPS in development, a self-signed +# certificate can be generated by running the following +# Mix task: +# +# mix phx.gen.cert +# +# Note that this task requires Erlang/OTP 20 or later. +# Run `mix help phx.gen.cert` for more information. +# +# The `http:` config above can be replaced with: +# +# https: [ +# port: 4001, +# cipher_suite: :strong, +# keyfile: "priv/cert/selfsigned_key.pem", +# certfile: "priv/cert/selfsigned.pem" +# ], +# +# If desired, both `http:` and `https:` keys can be +# configured to run both http and https servers on +# different ports. + +# Watch static and templates for browser reloading. +config :featureflagservice, FeatureflagserviceWeb.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/featureflagservice_web/(live|views)/.*(ex)$", + ~r"lib/featureflagservice_web/templates/.*(eex)$" + ] + ] + +# Do not include metadata nor timestamps in development logs +config :logger, :console, format: "[$level] $message\n" +config :logger, level: :debug + +# Set a higher stacktrace during development. Avoid configuring such +# in production as building large stacktraces may be expensive. +config :phoenix, :stacktrace_depth, 20 + +# Initialize plugs at runtime for faster development compilation +config :phoenix, :plug_init_mode, :runtime diff --git a/src/featureflagservice/config/prod.exs b/src/featureflagservice/config/prod.exs new file mode 100644 index 0000000000..b14f480d67 --- /dev/null +++ b/src/featureflagservice/config/prod.exs @@ -0,0 +1,49 @@ +import Config + +# For production, don't forget to configure the url host +# to something meaningful, Phoenix uses this information +# when generating URLs. +# +# Note we also include the path to a cache manifest +# containing the digested version of static files. This +# manifest is generated by the `mix phx.digest` task, +# which you should run after static files are built and +# before starting your production server. +config :featureflagservice, FeatureflagserviceWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" + +# Do not print debug messages in production +config :logger, level: :info + +# ## SSL Support +# +# To get SSL working, you will need to add the `https` key +# to the previous section and set your `:url` port to 443: +# +# config :featureflagservice, FeatureflagserviceWeb.Endpoint, +# ..., +# url: [host: "example.com", port: 443], +# https: [ +# ..., +# port: 443, +# cipher_suite: :strong, +# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), +# certfile: System.get_env("SOME_APP_SSL_CERT_PATH") +# ] +# +# The `cipher_suite` is set to `:strong` to support only the +# latest and more secure SSL ciphers. This means old browsers +# and clients may not be supported. You can set it to +# `:compatible` for wider support. +# +# `:keyfile` and `:certfile` expect an absolute path to the key +# and cert in disk or a relative path inside priv, for example +# "priv/ssl/server.key". For all supported SSL configuration +# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 +# +# We also recommend setting `force_ssl` in your endpoint, ensuring +# no data is ever sent via http, always redirecting to https: +# +# config :featureflagservice, FeatureflagserviceWeb.Endpoint, +# force_ssl: [hsts: true] +# +# Check `Plug.SSL` for all available options in `force_ssl`. diff --git a/src/featureflagservice/config/runtime.exs b/src/featureflagservice/config/runtime.exs new file mode 100644 index 0000000000..407ab5e01b --- /dev/null +++ b/src/featureflagservice/config/runtime.exs @@ -0,0 +1,61 @@ +import Config + +if System.get_env("PHX_SERVER") do + config :featureflagservice, FeatureflagserviceWeb.Endpoint, server: true +end + +grpc_port = String.to_integer(System.get_env("GRPC_PORT") || "4001") + +config :grpcbox, + servers: [%{:grpc_opts => %{:service_protos => [:ffs_featureflag_pb], + :unary_interceptor => {:otel_grpcbox_interceptor, :unary}, + :services => %{:FeatureFlagService => :ffs_service}}, + :listen_opts => %{:port => grpc_port}}] + +if config_env() == :prod do + config :opentelemetry_exporter, + otlp_endpoint: "http://otelcol:4317", + otlp_protocol: :grpc + + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + + maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: [] + + config :featureflagservice, Featureflagservice.Repo, + # ssl: true, + url: database_url, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + socket_options: maybe_ipv6 + + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ + + host = System.get_env("PHX_HOST") || "localhost" + port = String.to_integer(System.get_env("PORT") || "4000") + + config :featureflagservice, FeatureflagserviceWeb.Endpoint, + url: [host: host, port: 443, scheme: "https"], + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html + # for details about using IPv6 vs IPv4 and loopback vs public addresses. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: port + ], + secret_key_base: secret_key_base +end diff --git a/src/featureflagservice/config/test.exs b/src/featureflagservice/config/test.exs new file mode 100644 index 0000000000..73df68955f --- /dev/null +++ b/src/featureflagservice/config/test.exs @@ -0,0 +1,30 @@ +import Config + +# Configure your database +# +# The MIX_TEST_PARTITION environment variable can be used +# to provide built-in test partitioning in CI environment. +# Run `mix help test` for more information. +config :featureflagservice, Featureflagservice.Repo, + username: "postgres", + password: "postgres", + hostname: "localhost", + database: "featureflagservice_test#{System.get_env("MIX_TEST_PARTITION")}", + pool: Ecto.Adapters.SQL.Sandbox, + pool_size: 10 + +# We don't run a server during test. If one is required, +# you can enable the server option below. +config :featureflagservice, FeatureflagserviceWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], + secret_key_base: "HcCBiW6WwFO9llsQig9V6rxpIwlHoKC722YEs/ANSl+w6uJG1aAbeSZOcR/3sA57", + server: false + +# In test we don't send emails. +config :featureflagservice, Featureflagservice.Mailer, adapter: Swoosh.Adapters.Test + +# Print only warnings and errors during test +config :logger, level: :warn + +# Initialize plugs at runtime for faster test compilation +config :phoenix, :plug_init_mode, :runtime diff --git a/src/featureflagservice/docker-compose.yml b/src/featureflagservice/docker-compose.yml new file mode 100644 index 0000000000..15909dd201 --- /dev/null +++ b/src/featureflagservice/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.7' + +services: + postgres: + image: cimg/postgres:14.2 + environment: + - POSTGRES_USER=postgres + - POSTGRES_DB=featureflagservice_dev + - POSTGRES_PASSWORD=postgres + - POSTGRES_HOST_AUTH_METHOD=scram-sha-256 + ports: + - 5432:5432 + diff --git a/src/featureflagservice/lib/featureflagservice.ex b/src/featureflagservice/lib/featureflagservice.ex new file mode 100644 index 0000000000..971a698267 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice.ex @@ -0,0 +1,9 @@ +defmodule Featureflagservice do + @moduledoc """ + Featureflagservice keeps the contexts that define your domain + and business logic. + + Contexts are also responsible for managing your data, regardless + if it comes from the database, an external API or others. + """ +end diff --git a/src/featureflagservice/lib/featureflagservice/application.ex b/src/featureflagservice/lib/featureflagservice/application.ex new file mode 100644 index 0000000000..24417f1ab7 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/application.ex @@ -0,0 +1,39 @@ +defmodule Featureflagservice.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + OpentelemetryEcto.setup([:featureflagservice, :repo]) + OpentelemetryPhoenix.setup() + + children = [ + # Start the Ecto repository + Featureflagservice.Repo, + # Start the Telemetry supervisor + FeatureflagserviceWeb.Telemetry, + # Start the PubSub system + {Phoenix.PubSub, name: Featureflagservice.PubSub}, + # Start the Endpoint (http/https) + FeatureflagserviceWeb.Endpoint + # Start a worker by calling: Featureflagservice.Worker.start_link(arg) + # {Featureflagservice.Worker, arg} + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: Featureflagservice.Supervisor] + Supervisor.start_link(children, opts) + end + + # Tell Phoenix to update the endpoint configuration + # whenever the application is updated. + @impl true + def config_change(changed, _new, removed) do + FeatureflagserviceWeb.Endpoint.config_change(changed, removed) + :ok + end +end diff --git a/src/featureflagservice/lib/featureflagservice/feature_flags.ex b/src/featureflagservice/lib/featureflagservice/feature_flags.ex new file mode 100644 index 0000000000..827682e565 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/feature_flags.ex @@ -0,0 +1,118 @@ +defmodule Featureflagservice.FeatureFlags do + @moduledoc """ + The FeatureFlags context. + """ + + import Ecto.Query, warn: false + alias Featureflagservice.Repo + + alias Featureflagservice.FeatureFlags.FeatureFlag + + @doc """ + Returns the list of featureflags. + + ## Examples + + iex> list_featureflags() + [%FeatureFlag{}, ...] + + """ + def list_featureflags do + Repo.all(FeatureFlag) + end + + @doc """ + Gets a single feature_flag. + + Raises `Ecto.NoResultsError` if the Feature flag does not exist. + + ## Examples + + iex> get_feature_flag!(123) + %FeatureFlag{} + + iex> get_feature_flag!(456) + ** (Ecto.NoResultsError) + + """ + def get_feature_flag!(id), do: Repo.get!(FeatureFlag, id) + + @doc """ + Gets a single feature_flag by name. + + ## Examples + + iex> get_feature_flag_by_name("feature-1") + %FeatureFlag{} + + iex> get_feature_flag_by_name("not-a-feature-flag") + nil + + """ + def get_feature_flag_by_name(name), do: Repo.get_by(FeatureFlag, name: name) + + @doc """ + Creates a feature_flag. + + ## Examples + + iex> create_feature_flag(%{field: value}) + {:ok, %FeatureFlag{}} + + iex> create_feature_flag(%{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def create_feature_flag(attrs \\ %{}) do + %FeatureFlag{} + |> FeatureFlag.changeset(attrs) + |> Repo.insert() + end + + @doc """ + Updates a feature_flag. + + ## Examples + + iex> update_feature_flag(feature_flag, %{field: new_value}) + {:ok, %FeatureFlag{}} + + iex> update_feature_flag(feature_flag, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_feature_flag(%FeatureFlag{} = feature_flag, attrs) do + feature_flag + |> FeatureFlag.changeset(attrs) + |> Repo.update() + end + + @doc """ + Deletes a feature_flag. + + ## Examples + + iex> delete_feature_flag(feature_flag) + {:ok, %FeatureFlag{}} + + iex> delete_feature_flag(feature_flag) + {:error, %Ecto.Changeset{}} + + """ + def delete_feature_flag(%FeatureFlag{} = feature_flag) do + Repo.delete(feature_flag) + end + + @doc """ + Returns an `%Ecto.Changeset{}` for tracking feature_flag changes. + + ## Examples + + iex> change_feature_flag(feature_flag) + %Ecto.Changeset{data: %FeatureFlag{}} + + """ + def change_feature_flag(%FeatureFlag{} = feature_flag, attrs \\ %{}) do + FeatureFlag.changeset(feature_flag, attrs) + end +end diff --git a/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex b/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex new file mode 100644 index 0000000000..29ab530163 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex @@ -0,0 +1,20 @@ +defmodule Featureflagservice.FeatureFlags.FeatureFlag do + use Ecto.Schema + import Ecto.Changeset + + schema "featureflags" do + field :description, :string + field :enabled, :boolean, default: false + field :name, :string + + timestamps() + end + + @doc false + def changeset(feature_flag, attrs) do + feature_flag + |> cast(attrs, [:name, :description, :enabled]) + |> validate_required([:name, :description, :enabled]) + |> unique_constraint(:name) + end +end diff --git a/src/featureflagservice/lib/featureflagservice/mailer.ex b/src/featureflagservice/lib/featureflagservice/mailer.ex new file mode 100644 index 0000000000..51e635fabc --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/mailer.ex @@ -0,0 +1,3 @@ +defmodule Featureflagservice.Mailer do + use Swoosh.Mailer, otp_app: :featureflagservice +end diff --git a/src/featureflagservice/lib/featureflagservice/release.ex b/src/featureflagservice/lib/featureflagservice/release.ex new file mode 100644 index 0000000000..9adad2960e --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/release.ex @@ -0,0 +1,28 @@ +defmodule Featureflagservice.Release do + @moduledoc """ + Used for executing DB release tasks when run in production without Mix + installed. + """ + @app :featureflagservice + + def migrate do + load_app() + + for repo <- repos() do + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) + end + end + + def rollback(repo, version) do + load_app() + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) + end + + defp repos do + Application.fetch_env!(@app, :ecto_repos) + end + + defp load_app do + Application.load(@app) + end +end diff --git a/src/featureflagservice/lib/featureflagservice/repo.ex b/src/featureflagservice/lib/featureflagservice/repo.ex new file mode 100644 index 0000000000..b18e85d08e --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice/repo.ex @@ -0,0 +1,5 @@ +defmodule Featureflagservice.Repo do + use Ecto.Repo, + otp_app: :featureflagservice, + adapter: Ecto.Adapters.Postgres +end diff --git a/src/featureflagservice/lib/featureflagservice_web.ex b/src/featureflagservice/lib/featureflagservice_web.ex new file mode 100644 index 0000000000..c2ad9a8ca2 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web.ex @@ -0,0 +1,110 @@ +defmodule FeatureflagserviceWeb do + @moduledoc """ + The entrypoint for defining your web interface, such + as controllers, views, channels and so on. + + This can be used in your application as: + + use FeatureflagserviceWeb, :controller + use FeatureflagserviceWeb, :view + + The definitions below will be executed for every view, + controller, etc, so keep them short and clean, focused + on imports, uses and aliases. + + Do NOT define functions inside the quoted expressions + below. Instead, define any helper function in modules + and import those modules here. + """ + + def controller do + quote do + use Phoenix.Controller, namespace: FeatureflagserviceWeb + + import Plug.Conn + import FeatureflagserviceWeb.Gettext + alias FeatureflagserviceWeb.Router.Helpers, as: Routes + end + end + + def view do + quote do + use Phoenix.View, + root: "lib/featureflagservice_web/templates", + namespace: FeatureflagserviceWeb + + # Import convenience functions from controllers + import Phoenix.Controller, + only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1] + + # Include shared imports and aliases for views + unquote(view_helpers()) + end + end + + def live_view do + quote do + use Phoenix.LiveView, + layout: {FeatureflagserviceWeb.LayoutView, "live.html"} + + unquote(view_helpers()) + end + end + + def live_component do + quote do + use Phoenix.LiveComponent + + unquote(view_helpers()) + end + end + + def component do + quote do + use Phoenix.Component + + unquote(view_helpers()) + end + end + + def router do + quote do + use Phoenix.Router + + import Plug.Conn + import Phoenix.Controller + import Phoenix.LiveView.Router + end + end + + def channel do + quote do + use Phoenix.Channel + import FeatureflagserviceWeb.Gettext + end + end + + defp view_helpers do + quote do + # Use all HTML functionality (forms, tags, etc) + use Phoenix.HTML + + # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) + import Phoenix.LiveView.Helpers + + # Import basic rendering functionality (render, render_layout, etc) + import Phoenix.View + + import FeatureflagserviceWeb.ErrorHelpers + import FeatureflagserviceWeb.Gettext + alias FeatureflagserviceWeb.Router.Helpers, as: Routes + end + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex b/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex new file mode 100644 index 0000000000..b0fbe40c0a --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex @@ -0,0 +1,62 @@ +defmodule FeatureflagserviceWeb.FeatureFlagController do + use FeatureflagserviceWeb, :controller + + alias Featureflagservice.FeatureFlags + alias Featureflagservice.FeatureFlags.FeatureFlag + + def index(conn, _params) do + featureflags = FeatureFlags.list_featureflags() + render(conn, "index.html", featureflags: featureflags) + end + + def new(conn, _params) do + changeset = FeatureFlags.change_feature_flag(%FeatureFlag{}) + render(conn, "new.html", changeset: changeset) + end + + def create(conn, %{"feature_flag" => feature_flag_params}) do + case FeatureFlags.create_feature_flag(feature_flag_params) do + {:ok, feature_flag} -> + conn + |> put_flash(:info, "Feature flag created successfully.") + |> redirect(to: Routes.feature_flag_path(conn, :show, feature_flag)) + + {:error, %Ecto.Changeset{} = changeset} -> + render(conn, "new.html", changeset: changeset) + end + end + + def show(conn, %{"id" => id}) do + feature_flag = FeatureFlags.get_feature_flag!(id) + render(conn, "show.html", feature_flag: feature_flag) + end + + def edit(conn, %{"id" => id}) do + feature_flag = FeatureFlags.get_feature_flag!(id) + changeset = FeatureFlags.change_feature_flag(feature_flag) + render(conn, "edit.html", feature_flag: feature_flag, changeset: changeset) + end + + def update(conn, %{"id" => id, "feature_flag" => feature_flag_params}) do + feature_flag = FeatureFlags.get_feature_flag!(id) + + case FeatureFlags.update_feature_flag(feature_flag, feature_flag_params) do + {:ok, feature_flag} -> + conn + |> put_flash(:info, "Feature flag updated successfully.") + |> redirect(to: Routes.feature_flag_path(conn, :show, feature_flag)) + + {:error, %Ecto.Changeset{} = changeset} -> + render(conn, "edit.html", feature_flag: feature_flag, changeset: changeset) + end + end + + def delete(conn, %{"id" => id}) do + feature_flag = FeatureFlags.get_feature_flag!(id) + {:ok, _feature_flag} = FeatureFlags.delete_feature_flag(feature_flag) + + conn + |> put_flash(:info, "Feature flag deleted successfully.") + |> redirect(to: Routes.feature_flag_path(conn, :index)) + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex b/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex new file mode 100644 index 0000000000..1d8dd37650 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex @@ -0,0 +1,11 @@ +defmodule FeatureflagserviceWeb.PageController do + use FeatureflagserviceWeb, :controller + + alias Featureflagservice.FeatureFlags + alias Featureflagservice.FeatureFlags.FeatureFlag + + def index(conn, _params) do + featureflags = FeatureFlags.list_featureflags() + render(conn, "index.html", featureflags: featureflags) + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/endpoint.ex b/src/featureflagservice/lib/featureflagservice_web/endpoint.ex new file mode 100644 index 0000000000..57413f9747 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/endpoint.ex @@ -0,0 +1,50 @@ +defmodule FeatureflagserviceWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :featureflagservice + + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_featureflagservice_key", + signing_salt: "B7PAq71f" + ] + + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] + + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :featureflagservice, + gzip: false, + only: ~w(assets fonts images favicon.ico robots.txt) + + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + plug Phoenix.Ecto.CheckRepoStatus, otp_app: :featureflagservice + end + + plug Phoenix.LiveDashboard.RequestLogger, + param_key: "request_logger", + cookie_key: "request_logger" + + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug FeatureflagserviceWeb.Router +end diff --git a/src/featureflagservice/lib/featureflagservice_web/gettext.ex b/src/featureflagservice/lib/featureflagservice_web/gettext.ex new file mode 100644 index 0000000000..4e8f23c287 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/gettext.ex @@ -0,0 +1,24 @@ +defmodule FeatureflagserviceWeb.Gettext do + @moduledoc """ + A module providing Internationalization with a gettext-based API. + + By using [Gettext](https://hexdocs.pm/gettext), + your module gains a set of macros for translations, for example: + + import FeatureflagserviceWeb.Gettext + + # Simple translation + gettext("Here is the string to translate") + + # Plural translation + ngettext("Here is the string to translate", + "Here are the strings to translate", + 3) + + # Domain-based translation + dgettext("errors", "Here is the error message to translate") + + See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. + """ + use Gettext, otp_app: :featureflagservice +end diff --git a/src/featureflagservice/lib/featureflagservice_web/router.ex b/src/featureflagservice/lib/featureflagservice_web/router.ex new file mode 100644 index 0000000000..5ba5b70c8b --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/router.ex @@ -0,0 +1,57 @@ +defmodule FeatureflagserviceWeb.Router do + use FeatureflagserviceWeb, :router + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_live_flash + plug :put_root_layout, {FeatureflagserviceWeb.LayoutView, :root} + plug :protect_from_forgery + plug :put_secure_browser_headers + end + + pipeline :api do + plug :accepts, ["json"] + end + + scope "/", FeatureflagserviceWeb do + pipe_through :browser + + get "/", PageController, :index + resources "/featureflags", FeatureFlagController + end + + # Other scopes may use custom stacks. + # scope "/api", FeatureflagserviceWeb do + # pipe_through :api + # end + + # Enables LiveDashboard only for development + # + # If you want to use the LiveDashboard in production, you should put + # it behind authentication and allow only admins to access it. + # If your application does not have an admins-only section yet, + # you can use Plug.BasicAuth to set up some basic authentication + # as long as you are also using SSL (which you should anyway). + if Mix.env() in [:dev, :test] do + import Phoenix.LiveDashboard.Router + + scope "/" do + pipe_through :browser + + live_dashboard "/dashboard", metrics: FeatureflagserviceWeb.Telemetry + end + end + + # Enables the Swoosh mailbox preview in development. + # + # Note that preview only shows emails that were sent by the same + # node running the Phoenix server. + if Mix.env() == :dev do + scope "/dev" do + pipe_through :browser + + forward "/mailbox", Plug.Swoosh.MailboxPreview + end + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/telemetry.ex b/src/featureflagservice/lib/featureflagservice_web/telemetry.ex new file mode 100644 index 0000000000..c9e4298d3a --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/telemetry.ex @@ -0,0 +1,71 @@ +defmodule FeatureflagserviceWeb.Telemetry do + use Supervisor + import Telemetry.Metrics + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + @impl true + def init(_arg) do + children = [ + # Telemetry poller will execute the given period measurements + # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics + {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} + # Add reporters as children of your supervision tree. + # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} + ] + + Supervisor.init(children, strategy: :one_for_one) + end + + def metrics do + [ + # Phoenix Metrics + summary("phoenix.endpoint.stop.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.stop.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + + # Database Metrics + summary("featureflagservice.repo.query.total_time", + unit: {:native, :millisecond}, + description: "The sum of the other measurements" + ), + summary("featureflagservice.repo.query.decode_time", + unit: {:native, :millisecond}, + description: "The time spent decoding the data received from the database" + ), + summary("featureflagservice.repo.query.query_time", + unit: {:native, :millisecond}, + description: "The time spent executing the query" + ), + summary("featureflagservice.repo.query.queue_time", + unit: {:native, :millisecond}, + description: "The time spent waiting for a database connection" + ), + summary("featureflagservice.repo.query.idle_time", + unit: {:native, :millisecond}, + description: + "The time the connection spent waiting before being checked out for the query" + ), + + # VM Metrics + summary("vm.memory.total", unit: {:byte, :kilobyte}), + summary("vm.total_run_queue_lengths.total"), + summary("vm.total_run_queue_lengths.cpu"), + summary("vm.total_run_queue_lengths.io") + ] + end + + defp periodic_measurements do + [ + # A module, function and arguments to be invoked periodically. + # This function must call :telemetry.execute/3 and a metric must be added above. + # {FeatureflagserviceWeb, :count_users, []} + ] + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex new file mode 100644 index 0000000000..c8f96e7140 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex @@ -0,0 +1,5 @@ +

Edit Feature flag

+ +<%= render "form.html", Map.put(assigns, :action, Routes.feature_flag_path(@conn, :update, @feature_flag)) %> + +<%= link "Back", to: Routes.feature_flag_path(@conn, :index) %> diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex new file mode 100644 index 0000000000..81ebee96ba --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex @@ -0,0 +1,23 @@ +<.form let={f} for={@changeset} action={@action}> + <%= if @changeset.action do %> +
+

Oops, something went wrong! Please check the errors below.

+
+ <% end %> + + <%= label f, :name %> + <%= text_input f, :name %> + <%= error_tag f, :name %> + + <%= label f, :description %> + <%= text_input f, :description %> + <%= error_tag f, :description %> + + <%= label f, :enabled %> + <%= checkbox f, :enabled %> + <%= error_tag f, :enabled %> + +
+ <%= submit "Save" %> +
+ diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex new file mode 100644 index 0000000000..10ab76ec53 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex @@ -0,0 +1,30 @@ +

Listing Featureflags

+ + + + + + + + + + + + +<%= for feature_flag <- @featureflags do %> + + + + + + + +<% end %> + +
NameDescriptionEnabled
<%= feature_flag.name %><%= feature_flag.description %><%= feature_flag.enabled %> + <%= link "Show", to: Routes.feature_flag_path(@conn, :show, feature_flag) %> + <%= link "Edit", to: Routes.feature_flag_path(@conn, :edit, feature_flag) %> + <%= link "Delete", to: Routes.feature_flag_path(@conn, :delete, feature_flag), method: :delete, data: [confirm: "Are you sure?"] %> +
+ +<%= link "New Feature flag", to: Routes.feature_flag_path(@conn, :new) %> diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex new file mode 100644 index 0000000000..e95b4e0985 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex @@ -0,0 +1,5 @@ +

New Feature flag

+ +<%= render "form.html", Map.put(assigns, :action, Routes.feature_flag_path(@conn, :create)) %> + +<%= link "Back", to: Routes.feature_flag_path(@conn, :index) %> diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex new file mode 100644 index 0000000000..493650b5a5 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex @@ -0,0 +1,23 @@ +

Show Feature flag

+ + + +<%= link "Edit", to: Routes.feature_flag_path(@conn, :edit, @feature_flag) %> | +<%= link "Back", to: Routes.feature_flag_path(@conn, :index) %> diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/layout/app.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/layout/app.html.heex new file mode 100644 index 0000000000..169aed9569 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/layout/app.html.heex @@ -0,0 +1,5 @@ +
+ + + <%= @inner_content %> +
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/layout/live.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/layout/live.html.heex new file mode 100644 index 0000000000..a29d604480 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/layout/live.html.heex @@ -0,0 +1,11 @@ +
+ + + + + <%= @inner_content %> +
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/layout/root.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/layout/root.html.heex new file mode 100644 index 0000000000..c4c336b9d5 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/layout/root.html.heex @@ -0,0 +1,30 @@ + + + + + + + + <%= live_title_tag assigns[:page_title] || "Featureflagservice", suffix: " ยท Phoenix Framework" %> + + + + +
+
+ + +
+
+ <%= @inner_content %> + + diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/page/index.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/page/index.html.heex new file mode 100644 index 0000000000..10ab76ec53 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/templates/page/index.html.heex @@ -0,0 +1,30 @@ +

Listing Featureflags

+ + + + + + + + + + + + +<%= for feature_flag <- @featureflags do %> + + + + + + + +<% end %> + +
NameDescriptionEnabled
<%= feature_flag.name %><%= feature_flag.description %><%= feature_flag.enabled %> + <%= link "Show", to: Routes.feature_flag_path(@conn, :show, feature_flag) %> + <%= link "Edit", to: Routes.feature_flag_path(@conn, :edit, feature_flag) %> + <%= link "Delete", to: Routes.feature_flag_path(@conn, :delete, feature_flag), method: :delete, data: [confirm: "Are you sure?"] %> +
+ +<%= link "New Feature flag", to: Routes.feature_flag_path(@conn, :new) %> diff --git a/src/featureflagservice/lib/featureflagservice_web/views/error_helpers.ex b/src/featureflagservice/lib/featureflagservice_web/views/error_helpers.ex new file mode 100644 index 0000000000..d1abab6bef --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/views/error_helpers.ex @@ -0,0 +1,47 @@ +defmodule FeatureflagserviceWeb.ErrorHelpers do + @moduledoc """ + Conveniences for translating and building error messages. + """ + + use Phoenix.HTML + + @doc """ + Generates tag for inlined form input errors. + """ + def error_tag(form, field) do + Enum.map(Keyword.get_values(form.errors, field), fn error -> + content_tag(:span, translate_error(error), + class: "invalid-feedback", + phx_feedback_for: input_name(form, field) + ) + end) + end + + @doc """ + Translates an error message using gettext. + """ + def translate_error({msg, opts}) do + # When using gettext, we typically pass the strings we want + # to translate as a static argument: + # + # # Translate "is invalid" in the "errors" domain + # dgettext("errors", "is invalid") + # + # # Translate the number of files with plural rules + # dngettext("errors", "1 file", "%{count} files", count) + # + # Because the error messages we show in our forms and APIs + # are defined inside Ecto, we need to translate them dynamically. + # This requires us to call the Gettext module passing our gettext + # backend as first argument. + # + # Note we use the "errors" domain, which means translations + # should be written to the errors.po file. The :count option is + # set by Ecto and indicates we should also apply plural rules. + if count = opts[:count] do + Gettext.dngettext(FeatureflagserviceWeb.Gettext, "errors", msg, msg, count, opts) + else + Gettext.dgettext(FeatureflagserviceWeb.Gettext, "errors", msg, opts) + end + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/views/error_view.ex b/src/featureflagservice/lib/featureflagservice_web/views/error_view.ex new file mode 100644 index 0000000000..d2b91d6a9d --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/views/error_view.ex @@ -0,0 +1,16 @@ +defmodule FeatureflagserviceWeb.ErrorView do + use FeatureflagserviceWeb, :view + + # If you want to customize a particular status code + # for a certain format, you may uncomment below. + # def render("500.html", _assigns) do + # "Internal Server Error" + # end + + # By default, Phoenix returns the status message from + # the template name. For example, "404.html" becomes + # "Not Found". + def template_not_found(template, _assigns) do + Phoenix.Controller.status_message_from_template(template) + end +end diff --git a/src/featureflagservice/lib/featureflagservice_web/views/feature_flag_view.ex b/src/featureflagservice/lib/featureflagservice_web/views/feature_flag_view.ex new file mode 100644 index 0000000000..16232e421c --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/views/feature_flag_view.ex @@ -0,0 +1,3 @@ +defmodule FeatureflagserviceWeb.FeatureFlagView do + use FeatureflagserviceWeb, :view +end diff --git a/src/featureflagservice/lib/featureflagservice_web/views/layout_view.ex b/src/featureflagservice/lib/featureflagservice_web/views/layout_view.ex new file mode 100644 index 0000000000..fbc031245d --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/views/layout_view.ex @@ -0,0 +1,7 @@ +defmodule FeatureflagserviceWeb.LayoutView do + use FeatureflagserviceWeb, :view + + # Phoenix LiveDashboard is available only in development by default, + # so we instruct Elixir to not warn if the dashboard route is missing. + @compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}} +end diff --git a/src/featureflagservice/lib/featureflagservice_web/views/page_view.ex b/src/featureflagservice/lib/featureflagservice_web/views/page_view.ex new file mode 100644 index 0000000000..b2aac1f929 --- /dev/null +++ b/src/featureflagservice/lib/featureflagservice_web/views/page_view.ex @@ -0,0 +1,3 @@ +defmodule FeatureflagserviceWeb.PageView do + use FeatureflagserviceWeb, :view +end diff --git a/src/featureflagservice/mix.exs b/src/featureflagservice/mix.exs new file mode 100644 index 0000000000..4b1b052a6b --- /dev/null +++ b/src/featureflagservice/mix.exs @@ -0,0 +1,78 @@ +defmodule Featureflagservice.MixProject do + use Mix.Project + + def project do + [ + app: :featureflagservice, + version: "0.1.0", + elixir: "~> 1.12", + elixirc_paths: elixirc_paths(Mix.env()), + compilers: [:gettext] ++ Mix.compilers(), + start_permanent: Mix.env() == :prod, + aliases: aliases(), + deps: deps() + ] + end + + # Configuration for the OTP application. + # + # Type `mix help compile.app` for more information. + def application do + [ + mod: {Featureflagservice.Application, []}, + extra_applications: [:logger, :runtime_tools] + ] + end + + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + + # Specifies your project dependencies. + # + # Type `mix help deps` for examples and options. + defp deps do + [ + {:phoenix, "~> 1.6.9"}, + {:phoenix_ecto, "~> 4.4"}, + {:ecto_sql, "~> 3.6"}, + {:postgrex, ">= 0.0.0"}, + {:phoenix_html, "~> 3.0"}, + {:phoenix_live_reload, "~> 1.2", only: :dev}, + {:phoenix_live_view, "~> 0.17.5"}, + {:floki, ">= 0.30.0", only: :test}, + {:phoenix_live_dashboard, "~> 0.6"}, + {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, + {:swoosh, "~> 1.3"}, + {:telemetry_metrics, "~> 0.6"}, + {:telemetry_poller, "~> 1.0"}, + {:gettext, "~> 0.18"}, + {:jason, "~> 1.2"}, + {:plug_cowboy, "~> 2.5"}, + + {:grpcbox, "~> 0.15.0", override: true}, + {:opentelemetry_grpcbox, "~> 0.1"}, + {:opentelemetry_api, "~> 1.0"}, + {:opentelemetry, "~> 1.0.0"}, + {:opentelemetry_phoenix, "~> 1.0.0"}, + {:opentelemetry_ecto, "~> 1.0.0"}, + {:opentelemetry_exporter, "~> 1.0.0"} + ] + end + + # Aliases are shortcuts or tasks specific to the current project. + # For example, to install project dependencies and perform other setup tasks, run: + # + # $ mix setup + # + # See the documentation for `Mix` for more info on aliases. + defp aliases do + [ + setup: ["deps.get", "ecto.setup"], + "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], + "ecto.reset": ["ecto.drop", "ecto.setup"], + test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], + "assets.deploy": ["esbuild default --minify", "phx.digest"] + ] + end +end diff --git a/src/featureflagservice/mix.lock b/src/featureflagservice/mix.lock new file mode 100644 index 0000000000..1c0eeedbe2 --- /dev/null +++ b/src/featureflagservice/mix.lock @@ -0,0 +1,52 @@ +%{ + "acceptor_pool": {:hex, :acceptor_pool, "1.0.0", "43c20d2acae35f0c2bcd64f9d2bde267e459f0f3fd23dab26485bf518c281b21", [:rebar3], [], "hexpm", "0cbcd83fdc8b9ad2eee2067ef8b91a14858a5883cb7cd800e6fcd5803e158788"}, + "castore": {:hex, :castore, "0.1.17", "ba672681de4e51ed8ec1f74ed624d104c0db72742ea1a5e74edbc770c815182f", [:mix], [], "hexpm", "d9844227ed52d26e7519224525cb6868650c272d4a3d327ce3ca5570c12163f9"}, + "chatterbox": {:hex, :ts_chatterbox, "0.12.0", "4e54f199e15c0320b85372a24e35554a2ccfc4342e0b7cd8daed9a04f9b8ef4a", [:rebar3], [{:hpack, "~>0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "6478c161bc60244f41cd5847cc3accd26d997883e9f7facd36ff24533b2fa579"}, + "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, + "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, + "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, + "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "ctx": {:hex, :ctx, "0.6.0", "8ff88b70e6400c4df90142e7f130625b82086077a45364a78d208ed3ed53c7fe", [:rebar3], [], "hexpm", "a14ed2d1b67723dbebbe423b28d7615eb0bdcba6ff28f2d1f1b0a7e1d4aa5fc2"}, + "db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"}, + "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, + "ecto": {:hex, :ecto, "3.8.3", "5e681d35bc2cbb46dcca1e2675837c7d666316e5ada14eca6c9c609b6232817c", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "af92dd7815967bcaea0daaaccf31c3b23165432b1c7a475d84144efbc703d105"}, + "ecto_sql": {:hex, :ecto_sql, "3.8.2", "d7d44bc8d45ba9c85485952710c80408632a7336eb811b045e791718d11ddb5b", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.8.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7b9b03d64360d6cc05dc263500a43c11740b5fd4552244c27efad358e98c75b3"}, + "esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "floki": {:hex, :floki, "0.32.1", "dfe3b8db3b793939c264e6f785bca01753d17318d144bd44b407fb3493acaa87", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "d4b91c713e4a784a3f7b1e3cc016eefc619f6b1c3898464222867cafd3c681a3"}, + "gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"}, + "gproc": {:hex, :gproc, "0.8.0", "cea02c578589c61e5341fce149ea36ccef236cc2ecac8691fba408e7ea77ec2f", [:rebar3], [], "hexpm", "580adafa56463b75263ef5a5df4c86af321f68694e7786cb057fd805d1e2a7de"}, + "grpcbox": {:hex, :grpcbox, "0.15.0", "97c7126296a091602d372ebf5860a04f7bc795b45b33a984cad2b8e362774fd8", [:rebar3], [{:acceptor_pool, "~>1.0.0", [hex: :acceptor_pool, repo: "hexpm", optional: false]}, {:chatterbox, "~>0.12.0", [hex: :ts_chatterbox, repo: "hexpm", optional: false]}, {:ctx, "~>0.6.0", [hex: :ctx, repo: "hexpm", optional: false]}, {:gproc, "~>0.8.0", [hex: :gproc, repo: "hexpm", optional: false]}], "hexpm", "161abe9e17e7d1982efa6488adeaa13c3e847a07984a6e6b224e553368918647"}, + "hpack": {:hex, :hpack_erl, "0.2.3", "17670f83ff984ae6cd74b1c456edde906d27ff013740ee4d9efaa4f1bf999633", [:rebar3], [], "hexpm", "06f580167c4b8b8a6429040df36cc93bba6d571faeaec1b28816523379cbb23a"}, + "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, + "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, + "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, + "opentelemetry": {:hex, :opentelemetry, "1.0.5", "f0cd36ac8b30b68e8d70cec5bb88801ed7f3fe79aac67597054ed5490542e810", [:rebar3], [{:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "3b17f8933a58e1246f42a0c215840fd8218aebbcabdb0aac62b0c766fe85542e"}, + "opentelemetry_api": {:hex, :opentelemetry_api, "1.0.3", "77f9644c42340cd8b18c728cde4822ed55ae136f0d07761b78e8c54da46af93a", [:mix, :rebar3], [], "hexpm", "4293e06bd369bc004e6fad5edbb56456d891f14bd3f9f1772b18f1923e0678ea"}, + "opentelemetry_ecto": {:hex, :opentelemetry_ecto, "1.0.0", "8463cc466429b3e125ae236a5cc32869ea38c88eb2f07722dd88e78ceca6963c", [:mix], [{:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:opentelemetry_process_propagator, "~> 0.1.0", [hex: :opentelemetry_process_propagator, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "39cc60dbdd54e371bd12fb010ee960de851d782dca197efefa5c35eb6b4c18bd"}, + "opentelemetry_exporter": {:hex, :opentelemetry_exporter, "1.0.4", "60a64c75633a82b6c36a20043be355ac72a7b9b21633edd47407924c5596dde0", [:rebar3], [{:grpcbox, ">= 0.0.0", [hex: :grpcbox, repo: "hexpm", optional: false]}, {:opentelemetry, "~> 1.0", [hex: :opentelemetry, repo: "hexpm", optional: false]}, {:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:tls_certificate_check, "~> 1.11", [hex: :tls_certificate_check, repo: "hexpm", optional: false]}], "hexpm", "61da65290fbb6cac3459b84b8cd630795bf608df93a2b2cc49251cae78200e5e"}, + "opentelemetry_grpcbox": {:hex, :opentelemetry_grpcbox, "0.1.0", "2106e5c1dbce433537529df809d773bb6cc243e55add8bf6f596f218a63e26db", [:rebar3], [{:grpcbox, "~>0.14.0", [hex: :grpcbox, repo: "hexpm", optional: false]}, {:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "4d54c9376a8ec79ed71a654633e25470c545a1789ab46a589b6562699c677b54"}, + "opentelemetry_phoenix": {:hex, :opentelemetry_phoenix, "1.0.0", "73b8fee8bca6ac7a6aa0b17f61eb63494d1c78fffccdbac9656d92d279f9980c", [:mix], [{:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:opentelemetry_telemetry, "~> 1.0", [hex: :opentelemetry_telemetry, repo: "hexpm", optional: false]}, {:plug, ">= 1.11.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9cb30018fda95657f5698130541988b68269de2c9a870051f845f7e2193e72c3"}, + "opentelemetry_process_propagator": {:hex, :opentelemetry_process_propagator, "0.1.1", "81ec6825971903486ee73be23230d06764df39ee11011e520f601aa2bb21c893", [:mix, :rebar3], [{:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "0572f26066bbb0457e22e169f966c0140a8f95237716c9c6ba4458d6dbaa724b"}, + "opentelemetry_telemetry": {:hex, :opentelemetry_telemetry, "1.0.0", "d5982a319e725fcd2305b306b65c18a86afdcf7d96821473cf0649ff88877615", [:mix, :rebar3], [{:opentelemetry_api, "~> 1.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_registry, "~> 0.3.0", [hex: :telemetry_registry, repo: "hexpm", optional: false]}], "hexpm", "3401d13a1d4b7aa941a77e6b3ec074f0ae77f83b5b2206766ce630123a9291a9"}, + "phoenix": {:hex, :phoenix, "1.6.9", "648e660040cdc758c5401972e0f592ce622d4ce9cd16d2d9c33dda32d0c9f7fa", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "be2fe497597d6bf297dcbf9f4416b4929dbfbdcc25edc1acf6d4dcaecbe898a6"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, + "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, + "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.9", "36b5aa812bc3ccd64c9630f6b3234d9ea21105493237e927aae19d0ba758f0db", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f7ebc3e0ba0c5f6b6996ed6c901ddbfdaba59a6d09b569e7cb2f2f7d693b4455"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, + "phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"}, + "plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, + "postgrex": {:hex, :postgrex, "0.16.3", "fac79a81a9a234b11c44235a4494d8565303fa4b9147acf57e48978a074971db", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "aeaae1d2d1322da4e5fe90d241b0a564ce03a3add09d7270fb85362166194590"}, + "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, + "swoosh": {:hex, :swoosh, "1.6.6", "6018c6f4659ac0b4f30684982993b7812b2bb97436d39f76fcfa8c9e3ae74f85", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e92c7206efd442f08484993676ab072afab2f2bb1e87e604230bb1183c5980de"}, + "telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"}, + "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, + "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, + "telemetry_registry": {:hex, :telemetry_registry, "0.3.0", "6768f151ea53fc0fbca70dbff5b20a8d663ee4e0c0b2ae589590e08658e76f1e", [:mix, :rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "492e2adbc609f3e79ece7f29fec363a97a2c484ac78a83098535d6564781e917"}, + "tls_certificate_check": {:hex, :tls_certificate_check, "1.14.0", "6d1638d56ac68b25c987d401dffb7cd059281339aadc3f8bf27ab33ee19ddbfe", [:rebar3], [{:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "b4452ddd3ae89cd84451afa0e218cb3ccd5178fe3c1de7fabcbddb12a137bcf4"}, +} diff --git a/src/featureflagservice/priv/gettext/en/LC_MESSAGES/errors.po b/src/featureflagservice/priv/gettext/en/LC_MESSAGES/errors.po new file mode 100644 index 0000000000..844c4f5cea --- /dev/null +++ b/src/featureflagservice/priv/gettext/en/LC_MESSAGES/errors.po @@ -0,0 +1,112 @@ +## `msgid`s in this file come from POT (.pot) files. +## +## Do not add, change, or remove `msgid`s manually here as +## they're tied to the ones in the corresponding POT file +## (with the same domain). +## +## Use `mix gettext.extract --merge` or `mix gettext.merge` +## to merge POT files into PO files. +msgid "" +msgstr "" +"Language: en\n" + +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} byte(s)" +msgid_plural "should be %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} byte(s)" +msgid_plural "should be at least %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} byte(s)" +msgid_plural "should be at most %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/src/featureflagservice/priv/gettext/errors.pot b/src/featureflagservice/priv/gettext/errors.pot new file mode 100644 index 0000000000..39a220be35 --- /dev/null +++ b/src/featureflagservice/priv/gettext/errors.pot @@ -0,0 +1,95 @@ +## This is a PO Template file. +## +## `msgid`s here are often extracted from source code. +## Add new translations manually only if they're dynamic +## translations that can't be statically extracted. +## +## Run `mix gettext.extract` to bring this file up to +## date. Leave `msgstr`s empty as changing them here has no +## effect: edit them in PO (`.po`) files instead. + +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/src/featureflagservice/priv/repo/migrations/.formatter.exs b/src/featureflagservice/priv/repo/migrations/.formatter.exs new file mode 100644 index 0000000000..49f9151ed2 --- /dev/null +++ b/src/featureflagservice/priv/repo/migrations/.formatter.exs @@ -0,0 +1,4 @@ +[ + import_deps: [:ecto_sql], + inputs: ["*.exs"] +] diff --git a/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs b/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs new file mode 100644 index 0000000000..4d1f61ebad --- /dev/null +++ b/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs @@ -0,0 +1,15 @@ +defmodule Featureflagservice.Repo.Migrations.CreateFeatureflags do + use Ecto.Migration + + def change do + create table(:featureflags) do + add :name, :string + add :description, :string + add :enabled, :boolean, default: false, null: false + + timestamps() + end + + create unique_index(:featureflags, [:name]) + end +end diff --git a/src/featureflagservice/priv/repo/seeds.exs b/src/featureflagservice/priv/repo/seeds.exs new file mode 100644 index 0000000000..6fb1043eae --- /dev/null +++ b/src/featureflagservice/priv/repo/seeds.exs @@ -0,0 +1,11 @@ +# Script for populating the database. You can run it as: +# +# mix run priv/repo/seeds.exs +# +# Inside the script, you can read and write to any of your +# repositories directly: +# +# Featureflagservice.Repo.insert!(%Featureflagservice.SomeSchema{}) +# +# We recommend using the bang functions (`insert!`, `update!` +# and so on) as they will fail if something goes wrong. diff --git a/src/featureflagservice/priv/static/favicon.ico b/src/featureflagservice/priv/static/favicon.ico new file mode 100644 index 0000000000..73de524aaa Binary files /dev/null and b/src/featureflagservice/priv/static/favicon.ico differ diff --git a/src/featureflagservice/priv/static/images/phoenix.png b/src/featureflagservice/priv/static/images/phoenix.png new file mode 100644 index 0000000000..9c81075f63 Binary files /dev/null and b/src/featureflagservice/priv/static/images/phoenix.png differ diff --git a/src/featureflagservice/priv/static/robots.txt b/src/featureflagservice/priv/static/robots.txt new file mode 100644 index 0000000000..26e06b5f19 --- /dev/null +++ b/src/featureflagservice/priv/static/robots.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/src/featureflagservice/proto/featureflag.proto b/src/featureflagservice/proto/featureflag.proto new file mode 100644 index 0000000000..ff28c6b4d0 --- /dev/null +++ b/src/featureflagservice/proto/featureflag.proto @@ -0,0 +1,70 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +// ------------Feature flag service------------------ + +service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} +} + +message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; +} + +message GetFlagRequest { + string name = 1; +} + +message GetFlagResponse { + Flag flag = 1; +} + +message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; +} + +message CreateFlagResponse { + Flag flag = 1; +} + +message UpdateFlagRequest { + string name = 1; + bool enabled = 2; +} + +message UpdateFlagResponse {} + +message ListFlagsRequest {} + +message ListFlagsResponse { + repeated Flag flag = 1; +} + +message DeleteFlagRequest { + string name = 1; +} + +message DeleteFlagResponse {} diff --git a/src/featureflagservice/rebar.config b/src/featureflagservice/rebar.config new file mode 100644 index 0000000000..24685783d0 --- /dev/null +++ b/src/featureflagservice/rebar.config @@ -0,0 +1,12 @@ +{erl_opts, [debug_info]}. +{deps, []}. + +{grpc, [{protos, ["proto"]}, + {service_modules, [{'FeatureFlagService', "ffs_service"}, + {'grpc.health.v1.Health', "grpcbox_health"}, + {'grpc.reflection.v1alpha.ServerReflection', "grpcbox_reflection"}]}, + {gpb_opts, [{descriptor, true}, + {module_name_prefix, "ffs_"}, + {module_name_suffix, "_pb"}]}]}. + +{project_plugins, [grpcbox_plugin]}. diff --git a/src/featureflagservice/rebar.lock b/src/featureflagservice/rebar.lock new file mode 100644 index 0000000000..da04d5ee31 --- /dev/null +++ b/src/featureflagservice/rebar.lock @@ -0,0 +1,31 @@ +{"1.2.0", +[{<<"acceptor_pool">>,{pkg,<<"acceptor_pool">>,<<"1.0.0">>},1}, + {<<"chatterbox">>,{pkg,<<"ts_chatterbox">>,<<"0.12.0">>},1}, + {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},1}, + {<<"gproc">>,{pkg,<<"gproc">>,<<"0.8.0">>},1}, + {<<"grpcbox">>,{pkg,<<"grpcbox">>,<<"0.15.0">>},0}, + {<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2}, + {<<"opentelemetry_api">>,{pkg,<<"opentelemetry_api">>,<<"1.0.3">>},0}, + {<<"opentelemetry_grpcbox">>, + {pkg,<<"opentelemetry_grpcbox">>,<<"0.1.0">>}, + 0}]}. +[ +{pkg_hash,[ + {<<"acceptor_pool">>, <<"43C20D2ACAE35F0C2BCD64F9D2BDE267E459F0F3FD23DAB26485BF518C281B21">>}, + {<<"chatterbox">>, <<"4E54F199E15C0320B85372A24E35554A2CCFC4342E0B7CD8DAED9A04F9B8EF4A">>}, + {<<"ctx">>, <<"8FF88B70E6400C4DF90142E7F130625B82086077A45364A78D208ED3ED53C7FE">>}, + {<<"gproc">>, <<"CEA02C578589C61E5341FCE149EA36CCEF236CC2ECAC8691FBA408E7EA77EC2F">>}, + {<<"grpcbox">>, <<"97C7126296A091602D372EBF5860A04F7BC795B45B33A984CAD2B8E362774FD8">>}, + {<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>}, + {<<"opentelemetry_api">>, <<"77F9644C42340CD8B18C728CDE4822ED55AE136F0D07761B78E8C54DA46AF93A">>}, + {<<"opentelemetry_grpcbox">>, <<"2106E5C1DBCE433537529DF809D773BB6CC243E55ADD8BF6F596F218A63E26DB">>}]}, +{pkg_hash_ext,[ + {<<"acceptor_pool">>, <<"0CBCD83FDC8B9AD2EEE2067EF8B91A14858A5883CB7CD800E6FCD5803E158788">>}, + {<<"chatterbox">>, <<"6478C161BC60244F41CD5847CC3ACCD26D997883E9F7FACD36FF24533B2FA579">>}, + {<<"ctx">>, <<"A14ED2D1B67723DBEBBE423B28D7615EB0BDCBA6FF28F2D1F1B0A7E1D4AA5FC2">>}, + {<<"gproc">>, <<"580ADAFA56463B75263EF5A5DF4C86AF321F68694E7786CB057FD805D1E2A7DE">>}, + {<<"grpcbox">>, <<"161ABE9E17E7D1982EFA6488ADEAA13C3E847A07984A6E6B224E553368918647">>}, + {<<"hpack">>, <<"06F580167C4B8B8A6429040DF36CC93BBA6D571FAEAEC1B28816523379CBB23A">>}, + {<<"opentelemetry_api">>, <<"4293E06BD369BC004E6FAD5EDBB56456D891F14BD3F9F1772B18F1923E0678EA">>}, + {<<"opentelemetry_grpcbox">>, <<"4D54C9376A8EC79ED71A654633E25470C545A1789AB46A589B6562699C677B54">>}]} +]. diff --git a/src/featureflagservice/src/featureflagservice.app.src b/src/featureflagservice/src/featureflagservice.app.src new file mode 100644 index 0000000000..7174a8d876 --- /dev/null +++ b/src/featureflagservice/src/featureflagservice.app.src @@ -0,0 +1,14 @@ +{application, featureflagservice, + [{description, "this is here just so rebar3 will build the necessary grpc code"}, + {vsn, "notused"}, + {registered, []}, + {applications, + [kernel, + stdlib + ]}, + {env,[]}, + {modules, []}, + + {licenses, ["Apache 2.0"]}, + {links, []} + ]}. diff --git a/src/featureflagservice/src/ffs_featureflag_pb.erl b/src/featureflagservice/src/ffs_featureflag_pb.erl new file mode 100644 index 0000000000..4c1b512173 --- /dev/null +++ b/src/featureflagservice/src/ffs_featureflag_pb.erl @@ -0,0 +1,2013 @@ +%% -*- coding: utf-8 -*- +%% @private +%% Automatically generated, do not edit +%% Generated by gpb_compile version 4.19.5 +%% Version source: file +-module(ffs_featureflag_pb). + +-export([encode_msg/2, encode_msg/3]). +-export([decode_msg/2, decode_msg/3]). +-export([merge_msgs/3, merge_msgs/4]). +-export([verify_msg/2, verify_msg/3]). +-export([get_msg_defs/0]). +-export([get_msg_names/0]). +-export([get_group_names/0]). +-export([get_msg_or_group_names/0]). +-export([get_enum_names/0]). +-export([find_msg_def/1, fetch_msg_def/1]). +-export([find_enum_def/1, fetch_enum_def/1]). +-export([enum_symbol_by_value/2, enum_value_by_symbol/2]). +-export([get_service_names/0]). +-export([get_service_def/1]). +-export([get_rpc_names/1]). +-export([find_rpc_def/2, fetch_rpc_def/2]). +-export([fqbin_to_service_name/1]). +-export([service_name_to_fqbin/1]). +-export([fqbins_to_service_and_rpc_name/2]). +-export([service_and_rpc_name_to_fqbins/2]). +-export([fqbin_to_msg_name/1]). +-export([msg_name_to_fqbin/1]). +-export([fqbin_to_enum_name/1]). +-export([enum_name_to_fqbin/1]). +-export([get_package_name/0]). +-export([uses_packages/0]). +-export([source_basename/0]). +-export([get_all_source_basenames/0]). +-export([get_all_proto_names/0]). +-export([get_msg_containment/1]). +-export([get_pkg_containment/1]). +-export([get_service_containment/1]). +-export([get_rpc_containment/1]). +-export([get_enum_containment/1]). +-export([get_proto_by_msg_name_as_fqbin/1]). +-export([get_proto_by_service_name_as_fqbin/1]). +-export([get_proto_by_enum_name_as_fqbin/1]). +-export([get_protos_by_pkg_name_as_fqbin/1]). +-export([descriptor/0, descriptor/1]). +-export([gpb_version_as_string/0, gpb_version_as_list/0]). +-export([gpb_version_source/0]). + + +%% enumerated types + +-export_type([]). + +%% message types +-type flag() :: + #{name => unicode:chardata(), % = 1, optional + description => unicode:chardata(), % = 2, optional + enabled => boolean() | 0 | 1, % = 3, optional + created_at => timestamp(), % = 4, optional + updated_at => timestamp() % = 5, optional + }. + +-type get_flag_request() :: + #{name => unicode:chardata() % = 1, optional + }. + +-type get_flag_response() :: + #{flag => flag() % = 1, optional + }. + +-type create_flag_request() :: + #{name => unicode:chardata(), % = 1, optional + description => unicode:chardata(), % = 2, optional + enabled => boolean() | 0 | 1 % = 3, optional + }. + +-type create_flag_response() :: + #{flag => flag() % = 1, optional + }. + +-type update_flag_request() :: + #{name => unicode:chardata(), % = 1, optional + enabled => boolean() | 0 | 1 % = 2, optional + }. + +-type update_flag_response() :: + #{ + }. + +-type list_flags_request() :: + #{ + }. + +-type list_flags_response() :: + #{flag => [flag()] % = 1, repeated + }. + +-type delete_flag_request() :: + #{name => unicode:chardata() % = 1, optional + }. + +-type delete_flag_response() :: + #{ + }. + +-type timestamp() :: + #{seconds => integer(), % = 1, optional, 64 bits + nanos => integer() % = 2, optional, 32 bits + }. + +-export_type(['flag'/0, 'get_flag_request'/0, 'get_flag_response'/0, 'create_flag_request'/0, 'create_flag_response'/0, 'update_flag_request'/0, 'update_flag_response'/0, 'list_flags_request'/0, 'list_flags_response'/0, 'delete_flag_request'/0, 'delete_flag_response'/0, 'timestamp'/0]). +-type '$msg_name'() :: flag | get_flag_request | get_flag_response | create_flag_request | create_flag_response | update_flag_request | update_flag_response | list_flags_request | list_flags_response | delete_flag_request | delete_flag_response | timestamp. +-type '$msg'() :: flag() | get_flag_request() | get_flag_response() | create_flag_request() | create_flag_response() | update_flag_request() | update_flag_response() | list_flags_request() | list_flags_response() | delete_flag_request() | delete_flag_response() | timestamp(). +-export_type(['$msg_name'/0, '$msg'/0]). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/2}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'()) -> binary(). +encode_msg(Msg, MsgName) when is_atom(MsgName) -> encode_msg(Msg, MsgName, []). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/3}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'(), list()) -> binary(). +encode_msg(Msg, MsgName, Opts) -> + case proplists:get_bool(verify, Opts) of + true -> verify_msg(Msg, MsgName, Opts); + false -> ok + end, + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + flag -> encode_msg_flag(id(Msg, TrUserData), TrUserData); + get_flag_request -> encode_msg_get_flag_request(id(Msg, TrUserData), TrUserData); + get_flag_response -> encode_msg_get_flag_response(id(Msg, TrUserData), TrUserData); + create_flag_request -> encode_msg_create_flag_request(id(Msg, TrUserData), TrUserData); + create_flag_response -> encode_msg_create_flag_response(id(Msg, TrUserData), TrUserData); + update_flag_request -> encode_msg_update_flag_request(id(Msg, TrUserData), TrUserData); + update_flag_response -> encode_msg_update_flag_response(id(Msg, TrUserData), TrUserData); + list_flags_request -> encode_msg_list_flags_request(id(Msg, TrUserData), TrUserData); + list_flags_response -> encode_msg_list_flags_response(id(Msg, TrUserData), TrUserData); + delete_flag_request -> encode_msg_delete_flag_request(id(Msg, TrUserData), TrUserData); + delete_flag_response -> encode_msg_delete_flag_response(id(Msg, TrUserData), TrUserData); + timestamp -> encode_msg_timestamp(id(Msg, TrUserData), TrUserData) + end. + + +encode_msg_flag(Msg, TrUserData) -> encode_msg_flag(Msg, <<>>, TrUserData). + + +encode_msg_flag(#{} = M, Bin, TrUserData) -> + B1 = case M of + #{name := F1} -> + begin + TrF1 = id(F1, TrUserData), + case is_empty_string(TrF1) of + true -> Bin; + false -> e_type_string(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end, + B2 = case M of + #{description := F2} -> + begin + TrF2 = id(F2, TrUserData), + case is_empty_string(TrF2) of + true -> B1; + false -> e_type_string(TrF2, <>, TrUserData) + end + end; + _ -> B1 + end, + B3 = case M of + #{enabled := F3} -> + begin + TrF3 = id(F3, TrUserData), + if TrF3 =:= false -> B2; + true -> e_type_bool(TrF3, <>, TrUserData) + end + end; + _ -> B2 + end, + B4 = case M of + #{created_at := F4} -> + begin + TrF4 = id(F4, TrUserData), + if TrF4 =:= undefined -> B3; + true -> e_mfield_flag_created_at(TrF4, <>, TrUserData) + end + end; + _ -> B3 + end, + case M of + #{updated_at := F5} -> + begin + TrF5 = id(F5, TrUserData), + if TrF5 =:= undefined -> B4; + true -> e_mfield_flag_updated_at(TrF5, <>, TrUserData) + end + end; + _ -> B4 + end. + +encode_msg_get_flag_request(Msg, TrUserData) -> encode_msg_get_flag_request(Msg, <<>>, TrUserData). + + +encode_msg_get_flag_request(#{} = M, Bin, TrUserData) -> + case M of + #{name := F1} -> + begin + TrF1 = id(F1, TrUserData), + case is_empty_string(TrF1) of + true -> Bin; + false -> e_type_string(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end. + +encode_msg_get_flag_response(Msg, TrUserData) -> encode_msg_get_flag_response(Msg, <<>>, TrUserData). + + +encode_msg_get_flag_response(#{} = M, Bin, TrUserData) -> + case M of + #{flag := F1} -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= undefined -> Bin; + true -> e_mfield_get_flag_response_flag(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end. + +encode_msg_create_flag_request(Msg, TrUserData) -> encode_msg_create_flag_request(Msg, <<>>, TrUserData). + + +encode_msg_create_flag_request(#{} = M, Bin, TrUserData) -> + B1 = case M of + #{name := F1} -> + begin + TrF1 = id(F1, TrUserData), + case is_empty_string(TrF1) of + true -> Bin; + false -> e_type_string(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end, + B2 = case M of + #{description := F2} -> + begin + TrF2 = id(F2, TrUserData), + case is_empty_string(TrF2) of + true -> B1; + false -> e_type_string(TrF2, <>, TrUserData) + end + end; + _ -> B1 + end, + case M of + #{enabled := F3} -> + begin + TrF3 = id(F3, TrUserData), + if TrF3 =:= false -> B2; + true -> e_type_bool(TrF3, <>, TrUserData) + end + end; + _ -> B2 + end. + +encode_msg_create_flag_response(Msg, TrUserData) -> encode_msg_create_flag_response(Msg, <<>>, TrUserData). + + +encode_msg_create_flag_response(#{} = M, Bin, TrUserData) -> + case M of + #{flag := F1} -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= undefined -> Bin; + true -> e_mfield_create_flag_response_flag(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end. + +encode_msg_update_flag_request(Msg, TrUserData) -> encode_msg_update_flag_request(Msg, <<>>, TrUserData). + + +encode_msg_update_flag_request(#{} = M, Bin, TrUserData) -> + B1 = case M of + #{name := F1} -> + begin + TrF1 = id(F1, TrUserData), + case is_empty_string(TrF1) of + true -> Bin; + false -> e_type_string(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end, + case M of + #{enabled := F2} -> + begin + TrF2 = id(F2, TrUserData), + if TrF2 =:= false -> B1; + true -> e_type_bool(TrF2, <>, TrUserData) + end + end; + _ -> B1 + end. + +encode_msg_update_flag_response(_Msg, _TrUserData) -> <<>>. + +encode_msg_list_flags_request(_Msg, _TrUserData) -> <<>>. + +encode_msg_list_flags_response(Msg, TrUserData) -> encode_msg_list_flags_response(Msg, <<>>, TrUserData). + + +encode_msg_list_flags_response(#{} = M, Bin, TrUserData) -> + case M of + #{flag := F1} -> + TrF1 = id(F1, TrUserData), + if TrF1 == [] -> Bin; + true -> e_field_list_flags_response_flag(TrF1, Bin, TrUserData) + end; + _ -> Bin + end. + +encode_msg_delete_flag_request(Msg, TrUserData) -> encode_msg_delete_flag_request(Msg, <<>>, TrUserData). + + +encode_msg_delete_flag_request(#{} = M, Bin, TrUserData) -> + case M of + #{name := F1} -> + begin + TrF1 = id(F1, TrUserData), + case is_empty_string(TrF1) of + true -> Bin; + false -> e_type_string(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end. + +encode_msg_delete_flag_response(_Msg, _TrUserData) -> <<>>. + +encode_msg_timestamp(Msg, TrUserData) -> encode_msg_timestamp(Msg, <<>>, TrUserData). + + +encode_msg_timestamp(#{} = M, Bin, TrUserData) -> + B1 = case M of + #{seconds := F1} -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= 0 -> Bin; + true -> e_type_int64(TrF1, <>, TrUserData) + end + end; + _ -> Bin + end, + case M of + #{nanos := F2} -> + begin + TrF2 = id(F2, TrUserData), + if TrF2 =:= 0 -> B1; + true -> e_type_int32(TrF2, <>, TrUserData) + end + end; + _ -> B1 + end. + +e_mfield_flag_created_at(Msg, Bin, TrUserData) -> + SubBin = encode_msg_timestamp(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_mfield_flag_updated_at(Msg, Bin, TrUserData) -> + SubBin = encode_msg_timestamp(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_mfield_get_flag_response_flag(Msg, Bin, TrUserData) -> + SubBin = encode_msg_flag(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_mfield_create_flag_response_flag(Msg, Bin, TrUserData) -> + SubBin = encode_msg_flag(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_mfield_list_flags_response_flag(Msg, Bin, TrUserData) -> + SubBin = encode_msg_flag(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_field_list_flags_response_flag([Elem | Rest], Bin, TrUserData) -> + Bin2 = <>, + Bin3 = e_mfield_list_flags_response_flag(id(Elem, TrUserData), Bin2, TrUserData), + e_field_list_flags_response_flag(Rest, Bin3, TrUserData); +e_field_list_flags_response_flag([], Bin, _TrUserData) -> Bin. + +-compile({nowarn_unused_function,e_type_sint/3}). +e_type_sint(Value, Bin, _TrUserData) when Value >= 0 -> e_varint(Value * 2, Bin); +e_type_sint(Value, Bin, _TrUserData) -> e_varint(Value * -2 - 1, Bin). + +-compile({nowarn_unused_function,e_type_int32/3}). +e_type_int32(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int32(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_int64/3}). +e_type_int64(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int64(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_bool/3}). +e_type_bool(true, Bin, _TrUserData) -> <>; +e_type_bool(false, Bin, _TrUserData) -> <>; +e_type_bool(1, Bin, _TrUserData) -> <>; +e_type_bool(0, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_string/3}). +e_type_string(S, Bin, _TrUserData) -> + Utf8 = unicode:characters_to_binary(S), + Bin2 = e_varint(byte_size(Utf8), Bin), + <>. + +-compile({nowarn_unused_function,e_type_bytes/3}). +e_type_bytes(Bytes, Bin, _TrUserData) when is_binary(Bytes) -> + Bin2 = e_varint(byte_size(Bytes), Bin), + <>; +e_type_bytes(Bytes, Bin, _TrUserData) when is_list(Bytes) -> + BytesBin = iolist_to_binary(Bytes), + Bin2 = e_varint(byte_size(BytesBin), Bin), + <>. + +-compile({nowarn_unused_function,e_type_fixed32/3}). +e_type_fixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed32/3}). +e_type_sfixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_fixed64/3}). +e_type_fixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed64/3}). +e_type_sfixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_float/3}). +e_type_float(V, Bin, _) when is_number(V) -> <>; +e_type_float(infinity, Bin, _) -> <>; +e_type_float('-infinity', Bin, _) -> <>; +e_type_float(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_type_double/3}). +e_type_double(V, Bin, _) when is_number(V) -> <>; +e_type_double(infinity, Bin, _) -> <>; +e_type_double('-infinity', Bin, _) -> <>; +e_type_double(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_unknown_elems/2}). +e_unknown_elems([Elem | Rest], Bin) -> + BinR = case Elem of + {varint, FNum, N} -> + BinF = e_varint(FNum bsl 3, Bin), + e_varint(N, BinF); + {length_delimited, FNum, Data} -> + BinF = e_varint(FNum bsl 3 bor 2, Bin), + BinL = e_varint(byte_size(Data), BinF), + <>; + {group, FNum, GroupFields} -> + Bin1 = e_varint(FNum bsl 3 bor 3, Bin), + Bin2 = e_unknown_elems(GroupFields, Bin1), + e_varint(FNum bsl 3 bor 4, Bin2); + {fixed32, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 5, Bin), + <>; + {fixed64, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 1, Bin), + <> + end, + e_unknown_elems(Rest, BinR); +e_unknown_elems([], Bin) -> Bin. + +-compile({nowarn_unused_function,e_varint/3}). +e_varint(N, Bin, _TrUserData) -> e_varint(N, Bin). + +-compile({nowarn_unused_function,e_varint/2}). +e_varint(N, Bin) when N =< 127 -> <>; +e_varint(N, Bin) -> + Bin2 = <>, + e_varint(N bsr 7, Bin2). + +is_empty_string("") -> true; +is_empty_string(<<>>) -> true; +is_empty_string(L) when is_list(L) -> not string_has_chars(L); +is_empty_string(B) when is_binary(B) -> false. + +string_has_chars([C | _]) when is_integer(C) -> true; +string_has_chars([H | T]) -> + case string_has_chars(H) of + true -> true; + false -> string_has_chars(T) + end; +string_has_chars(B) when is_binary(B), byte_size(B) =/= 0 -> true; +string_has_chars(C) when is_integer(C) -> true; +string_has_chars(<<>>) -> false; +string_has_chars([]) -> false. + + +decode_msg(Bin, MsgName) when is_binary(Bin) -> decode_msg(Bin, MsgName, []). + +decode_msg(Bin, MsgName, Opts) when is_binary(Bin) -> + TrUserData = proplists:get_value(user_data, Opts), + decode_msg_1_catch(Bin, MsgName, TrUserData). + +-ifdef('OTP_RELEASE'). +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason:StackTrace -> + erlang:raise(error, Reason, StackTrace); + Class:Reason:StackTrace -> error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-else. +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason -> + erlang:raise(error, Reason, + erlang:get_stacktrace()); + Class:Reason -> + StackTrace = erlang:get_stacktrace(), + error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-endif. + +decode_msg_2_doit(flag, Bin, TrUserData) -> id(decode_msg_flag(Bin, TrUserData), TrUserData); +decode_msg_2_doit(get_flag_request, Bin, TrUserData) -> id(decode_msg_get_flag_request(Bin, TrUserData), TrUserData); +decode_msg_2_doit(get_flag_response, Bin, TrUserData) -> id(decode_msg_get_flag_response(Bin, TrUserData), TrUserData); +decode_msg_2_doit(create_flag_request, Bin, TrUserData) -> id(decode_msg_create_flag_request(Bin, TrUserData), TrUserData); +decode_msg_2_doit(create_flag_response, Bin, TrUserData) -> id(decode_msg_create_flag_response(Bin, TrUserData), TrUserData); +decode_msg_2_doit(update_flag_request, Bin, TrUserData) -> id(decode_msg_update_flag_request(Bin, TrUserData), TrUserData); +decode_msg_2_doit(update_flag_response, Bin, TrUserData) -> id(decode_msg_update_flag_response(Bin, TrUserData), TrUserData); +decode_msg_2_doit(list_flags_request, Bin, TrUserData) -> id(decode_msg_list_flags_request(Bin, TrUserData), TrUserData); +decode_msg_2_doit(list_flags_response, Bin, TrUserData) -> id(decode_msg_list_flags_response(Bin, TrUserData), TrUserData); +decode_msg_2_doit(delete_flag_request, Bin, TrUserData) -> id(decode_msg_delete_flag_request(Bin, TrUserData), TrUserData); +decode_msg_2_doit(delete_flag_response, Bin, TrUserData) -> id(decode_msg_delete_flag_response(Bin, TrUserData), TrUserData); +decode_msg_2_doit(timestamp, Bin, TrUserData) -> id(decode_msg_timestamp(Bin, TrUserData), TrUserData). + + + +decode_msg_flag(Bin, TrUserData) -> dfp_read_field_def_flag(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), id(false, TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_flag(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_flag_name(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_flag(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_flag_description(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_flag(<<24, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_flag_enabled(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_flag(<<34, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_flag_created_at(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_flag(<<42, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_flag_updated_at(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_flag(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> + S1 = #{name => F@_1, description => F@_2, enabled => F@_3}, + S2 = if F@_4 == '$undef' -> S1; + true -> S1#{created_at => F@_4} + end, + if F@_5 == '$undef' -> S2; + true -> S2#{updated_at => F@_5} + end; +dfp_read_field_def_flag(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dg_read_field_def_flag(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +dg_read_field_def_flag(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 32 - 7 -> dg_read_field_def_flag(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dg_read_field_def_flag(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_flag_name(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 18 -> d_field_flag_description(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 24 -> d_field_flag_enabled(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 34 -> d_field_flag_created_at(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 42 -> d_field_flag_updated_at(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_flag(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 1 -> skip_64_flag(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 2 -> skip_length_delimited_flag(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 3 -> skip_group_flag(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 5 -> skip_32_flag(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) + end + end; +dg_read_field_def_flag(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> + S1 = #{name => F@_1, description => F@_2, enabled => F@_3}, + S2 = if F@_4 == '$undef' -> S1; + true -> S1#{created_at => F@_4} + end, + if F@_5 == '$undef' -> S2; + true -> S2#{updated_at => F@_5} + end. + +d_field_flag_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_flag_name(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_flag_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_flag(RestF, 0, 0, F, NewFValue, F@_2, F@_3, F@_4, F@_5, TrUserData). + +d_field_flag_description(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_flag_description(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_flag_description(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_flag(RestF, 0, 0, F, F@_1, NewFValue, F@_3, F@_4, F@_5, TrUserData). + +d_field_flag_enabled(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_flag_enabled(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_flag_enabled(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = {id(X bsl N + Acc =/= 0, TrUserData), Rest}, + dfp_read_field_def_flag(RestF, 0, 0, F, F@_1, F@_2, NewFValue, F@_4, F@_5, TrUserData). + +d_field_flag_created_at(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_flag_created_at(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_flag_created_at(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, Prev, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_timestamp(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_flag(RestF, + 0, + 0, + F, + F@_1, + F@_2, + F@_3, + if Prev == '$undef' -> NewFValue; + true -> merge_msg_timestamp(Prev, NewFValue, TrUserData) + end, + F@_5, + TrUserData). + +d_field_flag_updated_at(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_flag_updated_at(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_flag_updated_at(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, Prev, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_timestamp(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_flag(RestF, + 0, + 0, + F, + F@_1, + F@_2, + F@_3, + F@_4, + if Prev == '$undef' -> NewFValue; + true -> merge_msg_timestamp(Prev, NewFValue, TrUserData) + end, + TrUserData). + +skip_varint_flag(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> skip_varint_flag(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_varint_flag(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_flag(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_length_delimited_flag(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> skip_length_delimited_flag(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_length_delimited_flag(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_flag(Rest2, 0, 0, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_group_flag(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_flag(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_32_flag(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_flag(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_64_flag(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_flag(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +decode_msg_get_flag_request(Bin, TrUserData) -> dfp_read_field_def_get_flag_request(Bin, 0, 0, 0, id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_get_flag_request(<<10, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_get_flag_request_name(Rest, Z1, Z2, F, F@_1, TrUserData); +dfp_read_field_def_get_flag_request(<<>>, 0, 0, _, F@_1, _) -> #{name => F@_1}; +dfp_read_field_def_get_flag_request(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_get_flag_request(Other, Z1, Z2, F, F@_1, TrUserData). + +dg_read_field_def_get_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_get_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +dg_read_field_def_get_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_get_flag_request_name(Rest, 0, 0, 0, F@_1, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_get_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 1 -> skip_64_get_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 2 -> skip_length_delimited_get_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 3 -> skip_group_get_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 5 -> skip_32_get_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData) + end + end; +dg_read_field_def_get_flag_request(<<>>, 0, 0, _, F@_1, _) -> #{name => F@_1}. + +d_field_get_flag_request_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_get_flag_request_name(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +d_field_get_flag_request_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_get_flag_request(RestF, 0, 0, F, NewFValue, TrUserData). + +skip_varint_get_flag_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_get_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData); +skip_varint_get_flag_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_length_delimited_get_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_get_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +skip_length_delimited_get_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_get_flag_request(Rest2, 0, 0, F, F@_1, TrUserData). + +skip_group_get_flag_request(Bin, _, Z2, FNum, F@_1, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_get_flag_request(Rest, 0, Z2, FNum, F@_1, TrUserData). + +skip_32_get_flag_request(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_64_get_flag_request(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +decode_msg_get_flag_response(Bin, TrUserData) -> dfp_read_field_def_get_flag_response(Bin, 0, 0, 0, id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_get_flag_response(<<10, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_get_flag_response_flag(Rest, Z1, Z2, F, F@_1, TrUserData); +dfp_read_field_def_get_flag_response(<<>>, 0, 0, _, F@_1, _) -> + S1 = #{}, + if F@_1 == '$undef' -> S1; + true -> S1#{flag => F@_1} + end; +dfp_read_field_def_get_flag_response(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_get_flag_response(Other, Z1, Z2, F, F@_1, TrUserData). + +dg_read_field_def_get_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_get_flag_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +dg_read_field_def_get_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_get_flag_response_flag(Rest, 0, 0, 0, F@_1, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_get_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 1 -> skip_64_get_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 2 -> skip_length_delimited_get_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 3 -> skip_group_get_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 5 -> skip_32_get_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData) + end + end; +dg_read_field_def_get_flag_response(<<>>, 0, 0, _, F@_1, _) -> + S1 = #{}, + if F@_1 == '$undef' -> S1; + true -> S1#{flag => F@_1} + end. + +d_field_get_flag_response_flag(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_get_flag_response_flag(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +d_field_get_flag_response_flag(<<0:1, X:7, Rest/binary>>, N, Acc, F, Prev, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_flag(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_get_flag_response(RestF, + 0, + 0, + F, + if Prev == '$undef' -> NewFValue; + true -> merge_msg_flag(Prev, NewFValue, TrUserData) + end, + TrUserData). + +skip_varint_get_flag_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_get_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData); +skip_varint_get_flag_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_length_delimited_get_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_get_flag_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +skip_length_delimited_get_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_get_flag_response(Rest2, 0, 0, F, F@_1, TrUserData). + +skip_group_get_flag_response(Bin, _, Z2, FNum, F@_1, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_get_flag_response(Rest, 0, Z2, FNum, F@_1, TrUserData). + +skip_32_get_flag_response(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_64_get_flag_response(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_get_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +decode_msg_create_flag_request(Bin, TrUserData) -> dfp_read_field_def_create_flag_request(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), id(false, TrUserData), TrUserData). + +dfp_read_field_def_create_flag_request(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_create_flag_request_name(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_create_flag_request(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_create_flag_request_description(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_create_flag_request(<<24, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_create_flag_request_enabled(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_create_flag_request(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #{name => F@_1, description => F@_2, enabled => F@_3}; +dfp_read_field_def_create_flag_request(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_create_flag_request(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +dg_read_field_def_create_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_create_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_create_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_create_flag_request_name(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 18 -> d_field_create_flag_request_description(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 24 -> d_field_create_flag_request_enabled(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_create_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_create_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_create_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_create_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_create_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + end + end; +dg_read_field_def_create_flag_request(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #{name => F@_1, description => F@_2, enabled => F@_3}. + +d_field_create_flag_request_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_create_flag_request_name(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_create_flag_request_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_create_flag_request(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). + +d_field_create_flag_request_description(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_create_flag_request_description(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_create_flag_request_description(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_create_flag_request(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). + +d_field_create_flag_request_enabled(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_create_flag_request_enabled(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_create_flag_request_enabled(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> + {NewFValue, RestF} = {id(X bsl N + Acc =/= 0, TrUserData), Rest}, + dfp_read_field_def_create_flag_request(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). + +skip_varint_create_flag_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_create_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_create_flag_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_create_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_length_delimited_create_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_create_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_create_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_create_flag_request(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + +skip_group_create_flag_request(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_create_flag_request(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + +skip_32_create_flag_request(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_create_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_64_create_flag_request(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_create_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +decode_msg_create_flag_response(Bin, TrUserData) -> dfp_read_field_def_create_flag_response(Bin, 0, 0, 0, id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_create_flag_response(<<10, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_create_flag_response_flag(Rest, Z1, Z2, F, F@_1, TrUserData); +dfp_read_field_def_create_flag_response(<<>>, 0, 0, _, F@_1, _) -> + S1 = #{}, + if F@_1 == '$undef' -> S1; + true -> S1#{flag => F@_1} + end; +dfp_read_field_def_create_flag_response(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_create_flag_response(Other, Z1, Z2, F, F@_1, TrUserData). + +dg_read_field_def_create_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_create_flag_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +dg_read_field_def_create_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_create_flag_response_flag(Rest, 0, 0, 0, F@_1, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_create_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 1 -> skip_64_create_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 2 -> skip_length_delimited_create_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 3 -> skip_group_create_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 5 -> skip_32_create_flag_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData) + end + end; +dg_read_field_def_create_flag_response(<<>>, 0, 0, _, F@_1, _) -> + S1 = #{}, + if F@_1 == '$undef' -> S1; + true -> S1#{flag => F@_1} + end. + +d_field_create_flag_response_flag(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_create_flag_response_flag(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +d_field_create_flag_response_flag(<<0:1, X:7, Rest/binary>>, N, Acc, F, Prev, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_flag(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_create_flag_response(RestF, + 0, + 0, + F, + if Prev == '$undef' -> NewFValue; + true -> merge_msg_flag(Prev, NewFValue, TrUserData) + end, + TrUserData). + +skip_varint_create_flag_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_create_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData); +skip_varint_create_flag_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_create_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_length_delimited_create_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_create_flag_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +skip_length_delimited_create_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_create_flag_response(Rest2, 0, 0, F, F@_1, TrUserData). + +skip_group_create_flag_response(Bin, _, Z2, FNum, F@_1, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_create_flag_response(Rest, 0, Z2, FNum, F@_1, TrUserData). + +skip_32_create_flag_response(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_create_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_64_create_flag_response(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_create_flag_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +decode_msg_update_flag_request(Bin, TrUserData) -> dfp_read_field_def_update_flag_request(Bin, 0, 0, 0, id(<<>>, TrUserData), id(false, TrUserData), TrUserData). + +dfp_read_field_def_update_flag_request(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_update_flag_request_name(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_update_flag_request(<<16, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_update_flag_request_enabled(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_update_flag_request(<<>>, 0, 0, _, F@_1, F@_2, _) -> #{name => F@_1, enabled => F@_2}; +dfp_read_field_def_update_flag_request(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_update_flag_request(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_update_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_update_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_update_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_update_flag_request_name(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 16 -> d_field_update_flag_request_enabled(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_update_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_update_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_update_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_update_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_update_flag_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_update_flag_request(<<>>, 0, 0, _, F@_1, F@_2, _) -> #{name => F@_1, enabled => F@_2}. + +d_field_update_flag_request_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_update_flag_request_name(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_update_flag_request_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_update_flag_request(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_update_flag_request_enabled(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_update_flag_request_enabled(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_update_flag_request_enabled(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = {id(X bsl N + Acc =/= 0, TrUserData), Rest}, + dfp_read_field_def_update_flag_request(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_update_flag_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_update_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_update_flag_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_update_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_update_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_update_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_update_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_update_flag_request(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_update_flag_request(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_update_flag_request(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_update_flag_request(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_update_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_update_flag_request(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_update_flag_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_update_flag_response(Bin, TrUserData) -> dfp_read_field_def_update_flag_response(Bin, 0, 0, 0, TrUserData). + +dfp_read_field_def_update_flag_response(<<>>, 0, 0, _, _) -> #{}; +dfp_read_field_def_update_flag_response(Other, Z1, Z2, F, TrUserData) -> dg_read_field_def_update_flag_response(Other, Z1, Z2, F, TrUserData). + +dg_read_field_def_update_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 32 - 7 -> dg_read_field_def_update_flag_response(Rest, N + 7, X bsl N + Acc, F, TrUserData); +dg_read_field_def_update_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, TrUserData) -> + Key = X bsl N + Acc, + case Key band 7 of + 0 -> skip_varint_update_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 1 -> skip_64_update_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 2 -> skip_length_delimited_update_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 3 -> skip_group_update_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 5 -> skip_32_update_flag_response(Rest, 0, 0, Key bsr 3, TrUserData) + end; +dg_read_field_def_update_flag_response(<<>>, 0, 0, _, _) -> #{}. + +skip_varint_update_flag_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> skip_varint_update_flag_response(Rest, Z1, Z2, F, TrUserData); +skip_varint_update_flag_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_update_flag_response(Rest, Z1, Z2, F, TrUserData). + +skip_length_delimited_update_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 57 -> skip_length_delimited_update_flag_response(Rest, N + 7, X bsl N + Acc, F, TrUserData); +skip_length_delimited_update_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_update_flag_response(Rest2, 0, 0, F, TrUserData). + +skip_group_update_flag_response(Bin, _, Z2, FNum, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_update_flag_response(Rest, 0, Z2, FNum, TrUserData). + +skip_32_update_flag_response(<<_:32, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_update_flag_response(Rest, Z1, Z2, F, TrUserData). + +skip_64_update_flag_response(<<_:64, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_update_flag_response(Rest, Z1, Z2, F, TrUserData). + +decode_msg_list_flags_request(Bin, TrUserData) -> dfp_read_field_def_list_flags_request(Bin, 0, 0, 0, TrUserData). + +dfp_read_field_def_list_flags_request(<<>>, 0, 0, _, _) -> #{}; +dfp_read_field_def_list_flags_request(Other, Z1, Z2, F, TrUserData) -> dg_read_field_def_list_flags_request(Other, Z1, Z2, F, TrUserData). + +dg_read_field_def_list_flags_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 32 - 7 -> dg_read_field_def_list_flags_request(Rest, N + 7, X bsl N + Acc, F, TrUserData); +dg_read_field_def_list_flags_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, TrUserData) -> + Key = X bsl N + Acc, + case Key band 7 of + 0 -> skip_varint_list_flags_request(Rest, 0, 0, Key bsr 3, TrUserData); + 1 -> skip_64_list_flags_request(Rest, 0, 0, Key bsr 3, TrUserData); + 2 -> skip_length_delimited_list_flags_request(Rest, 0, 0, Key bsr 3, TrUserData); + 3 -> skip_group_list_flags_request(Rest, 0, 0, Key bsr 3, TrUserData); + 5 -> skip_32_list_flags_request(Rest, 0, 0, Key bsr 3, TrUserData) + end; +dg_read_field_def_list_flags_request(<<>>, 0, 0, _, _) -> #{}. + +skip_varint_list_flags_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> skip_varint_list_flags_request(Rest, Z1, Z2, F, TrUserData); +skip_varint_list_flags_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_list_flags_request(Rest, Z1, Z2, F, TrUserData). + +skip_length_delimited_list_flags_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 57 -> skip_length_delimited_list_flags_request(Rest, N + 7, X bsl N + Acc, F, TrUserData); +skip_length_delimited_list_flags_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_list_flags_request(Rest2, 0, 0, F, TrUserData). + +skip_group_list_flags_request(Bin, _, Z2, FNum, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_list_flags_request(Rest, 0, Z2, FNum, TrUserData). + +skip_32_list_flags_request(<<_:32, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_list_flags_request(Rest, Z1, Z2, F, TrUserData). + +skip_64_list_flags_request(<<_:64, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_list_flags_request(Rest, Z1, Z2, F, TrUserData). + +decode_msg_list_flags_response(Bin, TrUserData) -> dfp_read_field_def_list_flags_response(Bin, 0, 0, 0, id([], TrUserData), TrUserData). + +dfp_read_field_def_list_flags_response(<<10, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_list_flags_response_flag(Rest, Z1, Z2, F, F@_1, TrUserData); +dfp_read_field_def_list_flags_response(<<>>, 0, 0, _, R1, TrUserData) -> + S1 = #{}, + if R1 == '$undef' -> S1; + true -> S1#{flag => lists_reverse(R1, TrUserData)} + end; +dfp_read_field_def_list_flags_response(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_list_flags_response(Other, Z1, Z2, F, F@_1, TrUserData). + +dg_read_field_def_list_flags_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_list_flags_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +dg_read_field_def_list_flags_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_list_flags_response_flag(Rest, 0, 0, 0, F@_1, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_list_flags_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 1 -> skip_64_list_flags_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 2 -> skip_length_delimited_list_flags_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 3 -> skip_group_list_flags_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 5 -> skip_32_list_flags_response(Rest, 0, 0, Key bsr 3, F@_1, TrUserData) + end + end; +dg_read_field_def_list_flags_response(<<>>, 0, 0, _, R1, TrUserData) -> + S1 = #{}, + if R1 == '$undef' -> S1; + true -> S1#{flag => lists_reverse(R1, TrUserData)} + end. + +d_field_list_flags_response_flag(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_list_flags_response_flag(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +d_field_list_flags_response_flag(<<0:1, X:7, Rest/binary>>, N, Acc, F, Prev, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_flag(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_list_flags_response(RestF, 0, 0, F, cons(NewFValue, Prev, TrUserData), TrUserData). + +skip_varint_list_flags_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_list_flags_response(Rest, Z1, Z2, F, F@_1, TrUserData); +skip_varint_list_flags_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_list_flags_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_length_delimited_list_flags_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_list_flags_response(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +skip_length_delimited_list_flags_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_list_flags_response(Rest2, 0, 0, F, F@_1, TrUserData). + +skip_group_list_flags_response(Bin, _, Z2, FNum, F@_1, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_list_flags_response(Rest, 0, Z2, FNum, F@_1, TrUserData). + +skip_32_list_flags_response(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_list_flags_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_64_list_flags_response(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_list_flags_response(Rest, Z1, Z2, F, F@_1, TrUserData). + +decode_msg_delete_flag_request(Bin, TrUserData) -> dfp_read_field_def_delete_flag_request(Bin, 0, 0, 0, id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_delete_flag_request(<<10, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_delete_flag_request_name(Rest, Z1, Z2, F, F@_1, TrUserData); +dfp_read_field_def_delete_flag_request(<<>>, 0, 0, _, F@_1, _) -> #{name => F@_1}; +dfp_read_field_def_delete_flag_request(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_delete_flag_request(Other, Z1, Z2, F, F@_1, TrUserData). + +dg_read_field_def_delete_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_delete_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +dg_read_field_def_delete_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_delete_flag_request_name(Rest, 0, 0, 0, F@_1, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_delete_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 1 -> skip_64_delete_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 2 -> skip_length_delimited_delete_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 3 -> skip_group_delete_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData); + 5 -> skip_32_delete_flag_request(Rest, 0, 0, Key bsr 3, F@_1, TrUserData) + end + end; +dg_read_field_def_delete_flag_request(<<>>, 0, 0, _, F@_1, _) -> #{name => F@_1}. + +d_field_delete_flag_request_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_delete_flag_request_name(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +d_field_delete_flag_request_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_delete_flag_request(RestF, 0, 0, F, NewFValue, TrUserData). + +skip_varint_delete_flag_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_delete_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData); +skip_varint_delete_flag_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_delete_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_length_delimited_delete_flag_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_delete_flag_request(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData); +skip_length_delimited_delete_flag_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_delete_flag_request(Rest2, 0, 0, F, F@_1, TrUserData). + +skip_group_delete_flag_request(Bin, _, Z2, FNum, F@_1, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_delete_flag_request(Rest, 0, Z2, FNum, F@_1, TrUserData). + +skip_32_delete_flag_request(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_delete_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +skip_64_delete_flag_request(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_delete_flag_request(Rest, Z1, Z2, F, F@_1, TrUserData). + +decode_msg_delete_flag_response(Bin, TrUserData) -> dfp_read_field_def_delete_flag_response(Bin, 0, 0, 0, TrUserData). + +dfp_read_field_def_delete_flag_response(<<>>, 0, 0, _, _) -> #{}; +dfp_read_field_def_delete_flag_response(Other, Z1, Z2, F, TrUserData) -> dg_read_field_def_delete_flag_response(Other, Z1, Z2, F, TrUserData). + +dg_read_field_def_delete_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 32 - 7 -> dg_read_field_def_delete_flag_response(Rest, N + 7, X bsl N + Acc, F, TrUserData); +dg_read_field_def_delete_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, TrUserData) -> + Key = X bsl N + Acc, + case Key band 7 of + 0 -> skip_varint_delete_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 1 -> skip_64_delete_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 2 -> skip_length_delimited_delete_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 3 -> skip_group_delete_flag_response(Rest, 0, 0, Key bsr 3, TrUserData); + 5 -> skip_32_delete_flag_response(Rest, 0, 0, Key bsr 3, TrUserData) + end; +dg_read_field_def_delete_flag_response(<<>>, 0, 0, _, _) -> #{}. + +skip_varint_delete_flag_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> skip_varint_delete_flag_response(Rest, Z1, Z2, F, TrUserData); +skip_varint_delete_flag_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_delete_flag_response(Rest, Z1, Z2, F, TrUserData). + +skip_length_delimited_delete_flag_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) when N < 57 -> skip_length_delimited_delete_flag_response(Rest, N + 7, X bsl N + Acc, F, TrUserData); +skip_length_delimited_delete_flag_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_delete_flag_response(Rest2, 0, 0, F, TrUserData). + +skip_group_delete_flag_response(Bin, _, Z2, FNum, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_delete_flag_response(Rest, 0, Z2, FNum, TrUserData). + +skip_32_delete_flag_response(<<_:32, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_delete_flag_response(Rest, Z1, Z2, F, TrUserData). + +skip_64_delete_flag_response(<<_:64, Rest/binary>>, Z1, Z2, F, TrUserData) -> dfp_read_field_def_delete_flag_response(Rest, Z1, Z2, F, TrUserData). + +decode_msg_timestamp(Bin, TrUserData) -> dfp_read_field_def_timestamp(Bin, 0, 0, 0, id(0, TrUserData), id(0, TrUserData), TrUserData). + +dfp_read_field_def_timestamp(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_timestamp_seconds(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_timestamp(<<16, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_timestamp_nanos(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_timestamp(<<>>, 0, 0, _, F@_1, F@_2, _) -> #{seconds => F@_1, nanos => F@_2}; +dfp_read_field_def_timestamp(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_timestamp(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_timestamp(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_timestamp(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_timestamp(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 8 -> d_field_timestamp_seconds(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 16 -> d_field_timestamp_nanos(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_timestamp(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_timestamp(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_timestamp(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_timestamp(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_timestamp(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_timestamp(<<>>, 0, 0, _, F@_1, F@_2, _) -> #{seconds => F@_1, nanos => F@_2}. + +d_field_timestamp_seconds(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_timestamp_seconds(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_timestamp_seconds(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):64/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_timestamp(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_timestamp_nanos(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_timestamp_nanos(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_timestamp_nanos(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_timestamp(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_timestamp(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_timestamp(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_timestamp(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_timestamp(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_timestamp(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_timestamp(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_timestamp(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_timestamp(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_timestamp(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_timestamp(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_timestamp(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_timestamp(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_timestamp(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_timestamp(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +read_group(Bin, FieldNum) -> + {NumBytes, EndTagLen} = read_gr_b(Bin, 0, 0, 0, 0, FieldNum), + <> = Bin, + {Group, Rest}. + +%% Like skipping over fields, but record the total length, +%% Each field is <(FieldNum bsl 3) bor FieldType> ++ +%% Record the length because varints may be non-optimally encoded. +%% +%% Groups can be nested, but assume the same FieldNum cannot be nested +%% because group field numbers are shared with the rest of the fields +%% numbers. Thus we can search just for an group-end with the same +%% field number. +%% +%% (The only time the same group field number could occur would +%% be in a nested sub message, but then it would be inside a +%% length-delimited entry, which we skip-read by length.) +read_gr_b(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, FieldNum) + when N < (32-7) -> + read_gr_b(Tl, N+7, X bsl N + Acc, NumBytes, TagLen+1, FieldNum); +read_gr_b(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, + FieldNum) -> + Key = X bsl N + Acc, + TagLen1 = TagLen + 1, + case {Key bsr 3, Key band 7} of + {FieldNum, 4} -> % 4 = group_end + {NumBytes, TagLen1}; + {_, 0} -> % 0 = varint + read_gr_vi(Tl, 0, NumBytes + TagLen1, FieldNum); + {_, 1} -> % 1 = bits64 + <<_:64, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 8, 0, FieldNum); + {_, 2} -> % 2 = length_delimited + read_gr_ld(Tl, 0, 0, NumBytes + TagLen1, FieldNum); + {_, 3} -> % 3 = group_start + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 4} -> % 4 = group_end + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 5} -> % 5 = bits32 + <<_:32, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 4, 0, FieldNum) + end. + +read_gr_vi(<<1:1, _:7, Tl/binary>>, N, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_vi(Tl, N+7, NumBytes+1, FieldNum); +read_gr_vi(<<0:1, _:7, Tl/binary>>, _, NumBytes, FieldNum) -> + read_gr_b(Tl, 0, 0, NumBytes+1, 0, FieldNum). + +read_gr_ld(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_ld(Tl, N+7, X bsl N + Acc, NumBytes+1, FieldNum); +read_gr_ld(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) -> + Len = X bsl N + Acc, + NumBytes1 = NumBytes + 1, + <<_:Len/binary, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes1 + Len, 0, FieldNum). + +merge_msgs(Prev, New, MsgName) when is_atom(MsgName) -> merge_msgs(Prev, New, MsgName, []). + +merge_msgs(Prev, New, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + flag -> merge_msg_flag(Prev, New, TrUserData); + get_flag_request -> merge_msg_get_flag_request(Prev, New, TrUserData); + get_flag_response -> merge_msg_get_flag_response(Prev, New, TrUserData); + create_flag_request -> merge_msg_create_flag_request(Prev, New, TrUserData); + create_flag_response -> merge_msg_create_flag_response(Prev, New, TrUserData); + update_flag_request -> merge_msg_update_flag_request(Prev, New, TrUserData); + update_flag_response -> merge_msg_update_flag_response(Prev, New, TrUserData); + list_flags_request -> merge_msg_list_flags_request(Prev, New, TrUserData); + list_flags_response -> merge_msg_list_flags_response(Prev, New, TrUserData); + delete_flag_request -> merge_msg_delete_flag_request(Prev, New, TrUserData); + delete_flag_response -> merge_msg_delete_flag_response(Prev, New, TrUserData); + timestamp -> merge_msg_timestamp(Prev, New, TrUserData) + end. + +-compile({nowarn_unused_function,merge_msg_flag/3}). +merge_msg_flag(PMsg, NMsg, TrUserData) -> + S1 = #{}, + S2 = case {PMsg, NMsg} of + {_, #{name := NFname}} -> S1#{name => NFname}; + {#{name := PFname}, _} -> S1#{name => PFname}; + _ -> S1 + end, + S3 = case {PMsg, NMsg} of + {_, #{description := NFdescription}} -> S2#{description => NFdescription}; + {#{description := PFdescription}, _} -> S2#{description => PFdescription}; + _ -> S2 + end, + S4 = case {PMsg, NMsg} of + {_, #{enabled := NFenabled}} -> S3#{enabled => NFenabled}; + {#{enabled := PFenabled}, _} -> S3#{enabled => PFenabled}; + _ -> S3 + end, + S5 = case {PMsg, NMsg} of + {#{created_at := PFcreated_at}, #{created_at := NFcreated_at}} -> S4#{created_at => merge_msg_timestamp(PFcreated_at, NFcreated_at, TrUserData)}; + {_, #{created_at := NFcreated_at}} -> S4#{created_at => NFcreated_at}; + {#{created_at := PFcreated_at}, _} -> S4#{created_at => PFcreated_at}; + {_, _} -> S4 + end, + case {PMsg, NMsg} of + {#{updated_at := PFupdated_at}, #{updated_at := NFupdated_at}} -> S5#{updated_at => merge_msg_timestamp(PFupdated_at, NFupdated_at, TrUserData)}; + {_, #{updated_at := NFupdated_at}} -> S5#{updated_at => NFupdated_at}; + {#{updated_at := PFupdated_at}, _} -> S5#{updated_at => PFupdated_at}; + {_, _} -> S5 + end. + +-compile({nowarn_unused_function,merge_msg_get_flag_request/3}). +merge_msg_get_flag_request(PMsg, NMsg, _) -> + S1 = #{}, + case {PMsg, NMsg} of + {_, #{name := NFname}} -> S1#{name => NFname}; + {#{name := PFname}, _} -> S1#{name => PFname}; + _ -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_get_flag_response/3}). +merge_msg_get_flag_response(PMsg, NMsg, TrUserData) -> + S1 = #{}, + case {PMsg, NMsg} of + {#{flag := PFflag}, #{flag := NFflag}} -> S1#{flag => merge_msg_flag(PFflag, NFflag, TrUserData)}; + {_, #{flag := NFflag}} -> S1#{flag => NFflag}; + {#{flag := PFflag}, _} -> S1#{flag => PFflag}; + {_, _} -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_create_flag_request/3}). +merge_msg_create_flag_request(PMsg, NMsg, _) -> + S1 = #{}, + S2 = case {PMsg, NMsg} of + {_, #{name := NFname}} -> S1#{name => NFname}; + {#{name := PFname}, _} -> S1#{name => PFname}; + _ -> S1 + end, + S3 = case {PMsg, NMsg} of + {_, #{description := NFdescription}} -> S2#{description => NFdescription}; + {#{description := PFdescription}, _} -> S2#{description => PFdescription}; + _ -> S2 + end, + case {PMsg, NMsg} of + {_, #{enabled := NFenabled}} -> S3#{enabled => NFenabled}; + {#{enabled := PFenabled}, _} -> S3#{enabled => PFenabled}; + _ -> S3 + end. + +-compile({nowarn_unused_function,merge_msg_create_flag_response/3}). +merge_msg_create_flag_response(PMsg, NMsg, TrUserData) -> + S1 = #{}, + case {PMsg, NMsg} of + {#{flag := PFflag}, #{flag := NFflag}} -> S1#{flag => merge_msg_flag(PFflag, NFflag, TrUserData)}; + {_, #{flag := NFflag}} -> S1#{flag => NFflag}; + {#{flag := PFflag}, _} -> S1#{flag => PFflag}; + {_, _} -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_update_flag_request/3}). +merge_msg_update_flag_request(PMsg, NMsg, _) -> + S1 = #{}, + S2 = case {PMsg, NMsg} of + {_, #{name := NFname}} -> S1#{name => NFname}; + {#{name := PFname}, _} -> S1#{name => PFname}; + _ -> S1 + end, + case {PMsg, NMsg} of + {_, #{enabled := NFenabled}} -> S2#{enabled => NFenabled}; + {#{enabled := PFenabled}, _} -> S2#{enabled => PFenabled}; + _ -> S2 + end. + +-compile({nowarn_unused_function,merge_msg_update_flag_response/3}). +merge_msg_update_flag_response(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,merge_msg_list_flags_request/3}). +merge_msg_list_flags_request(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,merge_msg_list_flags_response/3}). +merge_msg_list_flags_response(PMsg, NMsg, TrUserData) -> + S1 = #{}, + case {PMsg, NMsg} of + {#{flag := PFflag}, #{flag := NFflag}} -> S1#{flag => 'erlang_++'(PFflag, NFflag, TrUserData)}; + {_, #{flag := NFflag}} -> S1#{flag => NFflag}; + {#{flag := PFflag}, _} -> S1#{flag => PFflag}; + {_, _} -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_delete_flag_request/3}). +merge_msg_delete_flag_request(PMsg, NMsg, _) -> + S1 = #{}, + case {PMsg, NMsg} of + {_, #{name := NFname}} -> S1#{name => NFname}; + {#{name := PFname}, _} -> S1#{name => PFname}; + _ -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_delete_flag_response/3}). +merge_msg_delete_flag_response(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,merge_msg_timestamp/3}). +merge_msg_timestamp(PMsg, NMsg, _) -> + S1 = #{}, + S2 = case {PMsg, NMsg} of + {_, #{seconds := NFseconds}} -> S1#{seconds => NFseconds}; + {#{seconds := PFseconds}, _} -> S1#{seconds => PFseconds}; + _ -> S1 + end, + case {PMsg, NMsg} of + {_, #{nanos := NFnanos}} -> S2#{nanos => NFnanos}; + {#{nanos := PFnanos}, _} -> S2#{nanos => PFnanos}; + _ -> S2 + end. + + +verify_msg(Msg, MsgName) when is_atom(MsgName) -> verify_msg(Msg, MsgName, []). + +verify_msg(Msg, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + flag -> v_msg_flag(Msg, [MsgName], TrUserData); + get_flag_request -> v_msg_get_flag_request(Msg, [MsgName], TrUserData); + get_flag_response -> v_msg_get_flag_response(Msg, [MsgName], TrUserData); + create_flag_request -> v_msg_create_flag_request(Msg, [MsgName], TrUserData); + create_flag_response -> v_msg_create_flag_response(Msg, [MsgName], TrUserData); + update_flag_request -> v_msg_update_flag_request(Msg, [MsgName], TrUserData); + update_flag_response -> v_msg_update_flag_response(Msg, [MsgName], TrUserData); + list_flags_request -> v_msg_list_flags_request(Msg, [MsgName], TrUserData); + list_flags_response -> v_msg_list_flags_response(Msg, [MsgName], TrUserData); + delete_flag_request -> v_msg_delete_flag_request(Msg, [MsgName], TrUserData); + delete_flag_response -> v_msg_delete_flag_response(Msg, [MsgName], TrUserData); + timestamp -> v_msg_timestamp(Msg, [MsgName], TrUserData); + _ -> mk_type_error(not_a_known_message, Msg, []) + end. + + +-compile({nowarn_unused_function,v_msg_flag/3}). +-dialyzer({nowarn_function,v_msg_flag/3}). +v_msg_flag(#{} = M, Path, TrUserData) -> + case M of + #{name := F1} -> v_type_string(F1, [name | Path], TrUserData); + _ -> ok + end, + case M of + #{description := F2} -> v_type_string(F2, [description | Path], TrUserData); + _ -> ok + end, + case M of + #{enabled := F3} -> v_type_bool(F3, [enabled | Path], TrUserData); + _ -> ok + end, + case M of + #{created_at := F4} -> v_msg_timestamp(F4, [created_at | Path], TrUserData); + _ -> ok + end, + case M of + #{updated_at := F5} -> v_msg_timestamp(F5, [updated_at | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (description) -> ok; + (enabled) -> ok; + (created_at) -> ok; + (updated_at) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_flag(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), flag}, M, Path); +v_msg_flag(X, Path, _TrUserData) -> mk_type_error({expected_msg, flag}, X, Path). + +-compile({nowarn_unused_function,v_msg_get_flag_request/3}). +-dialyzer({nowarn_function,v_msg_get_flag_request/3}). +v_msg_get_flag_request(#{} = M, Path, TrUserData) -> + case M of + #{name := F1} -> v_type_string(F1, [name | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_get_flag_request(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), get_flag_request}, M, Path); +v_msg_get_flag_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, get_flag_request}, X, Path). + +-compile({nowarn_unused_function,v_msg_get_flag_response/3}). +-dialyzer({nowarn_function,v_msg_get_flag_response/3}). +v_msg_get_flag_response(#{} = M, Path, TrUserData) -> + case M of + #{flag := F1} -> v_msg_flag(F1, [flag | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (flag) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_get_flag_response(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), get_flag_response}, M, Path); +v_msg_get_flag_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, get_flag_response}, X, Path). + +-compile({nowarn_unused_function,v_msg_create_flag_request/3}). +-dialyzer({nowarn_function,v_msg_create_flag_request/3}). +v_msg_create_flag_request(#{} = M, Path, TrUserData) -> + case M of + #{name := F1} -> v_type_string(F1, [name | Path], TrUserData); + _ -> ok + end, + case M of + #{description := F2} -> v_type_string(F2, [description | Path], TrUserData); + _ -> ok + end, + case M of + #{enabled := F3} -> v_type_bool(F3, [enabled | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (description) -> ok; + (enabled) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_create_flag_request(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), create_flag_request}, M, Path); +v_msg_create_flag_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, create_flag_request}, X, Path). + +-compile({nowarn_unused_function,v_msg_create_flag_response/3}). +-dialyzer({nowarn_function,v_msg_create_flag_response/3}). +v_msg_create_flag_response(#{} = M, Path, TrUserData) -> + case M of + #{flag := F1} -> v_msg_flag(F1, [flag | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (flag) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_create_flag_response(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), create_flag_response}, M, Path); +v_msg_create_flag_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, create_flag_response}, X, Path). + +-compile({nowarn_unused_function,v_msg_update_flag_request/3}). +-dialyzer({nowarn_function,v_msg_update_flag_request/3}). +v_msg_update_flag_request(#{} = M, Path, TrUserData) -> + case M of + #{name := F1} -> v_type_string(F1, [name | Path], TrUserData); + _ -> ok + end, + case M of + #{enabled := F2} -> v_type_bool(F2, [enabled | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (enabled) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_update_flag_request(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), update_flag_request}, M, Path); +v_msg_update_flag_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, update_flag_request}, X, Path). + +-compile({nowarn_unused_function,v_msg_update_flag_response/3}). +-dialyzer({nowarn_function,v_msg_update_flag_response/3}). +v_msg_update_flag_response(#{} = M, Path, _) -> + lists:foreach(fun (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) end, maps:keys(M)), + ok; +v_msg_update_flag_response(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), update_flag_response}, M, Path); +v_msg_update_flag_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, update_flag_response}, X, Path). + +-compile({nowarn_unused_function,v_msg_list_flags_request/3}). +-dialyzer({nowarn_function,v_msg_list_flags_request/3}). +v_msg_list_flags_request(#{} = M, Path, _) -> + lists:foreach(fun (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) end, maps:keys(M)), + ok; +v_msg_list_flags_request(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), list_flags_request}, M, Path); +v_msg_list_flags_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, list_flags_request}, X, Path). + +-compile({nowarn_unused_function,v_msg_list_flags_response/3}). +-dialyzer({nowarn_function,v_msg_list_flags_response/3}). +v_msg_list_flags_response(#{} = M, Path, TrUserData) -> + case M of + #{flag := F1} -> + if is_list(F1) -> + _ = [v_msg_flag(Elem, [flag | Path], TrUserData) || Elem <- F1], + ok; + true -> mk_type_error({invalid_list_of, {msg, flag}}, F1, [flag | Path]) + end; + _ -> ok + end, + lists:foreach(fun (flag) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_list_flags_response(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), list_flags_response}, M, Path); +v_msg_list_flags_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, list_flags_response}, X, Path). + +-compile({nowarn_unused_function,v_msg_delete_flag_request/3}). +-dialyzer({nowarn_function,v_msg_delete_flag_request/3}). +v_msg_delete_flag_request(#{} = M, Path, TrUserData) -> + case M of + #{name := F1} -> v_type_string(F1, [name | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_delete_flag_request(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), delete_flag_request}, M, Path); +v_msg_delete_flag_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, delete_flag_request}, X, Path). + +-compile({nowarn_unused_function,v_msg_delete_flag_response/3}). +-dialyzer({nowarn_function,v_msg_delete_flag_response/3}). +v_msg_delete_flag_response(#{} = M, Path, _) -> + lists:foreach(fun (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) end, maps:keys(M)), + ok; +v_msg_delete_flag_response(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), delete_flag_response}, M, Path); +v_msg_delete_flag_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, delete_flag_response}, X, Path). + +-compile({nowarn_unused_function,v_msg_timestamp/3}). +-dialyzer({nowarn_function,v_msg_timestamp/3}). +v_msg_timestamp(#{} = M, Path, TrUserData) -> + case M of + #{seconds := F1} -> v_type_int64(F1, [seconds | Path], TrUserData); + _ -> ok + end, + case M of + #{nanos := F2} -> v_type_int32(F2, [nanos | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (seconds) -> ok; + (nanos) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_timestamp(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [] -- maps:keys(M), timestamp}, M, Path); +v_msg_timestamp(X, Path, _TrUserData) -> mk_type_error({expected_msg, timestamp}, X, Path). + +-compile({nowarn_unused_function,v_type_int32/3}). +-dialyzer({nowarn_function,v_type_int32/3}). +v_type_int32(N, _Path, _TrUserData) when -2147483648 =< N, N =< 2147483647 -> ok; +v_type_int32(N, Path, _TrUserData) when is_integer(N) -> mk_type_error({value_out_of_range, int32, signed, 32}, N, Path); +v_type_int32(X, Path, _TrUserData) -> mk_type_error({bad_integer, int32, signed, 32}, X, Path). + +-compile({nowarn_unused_function,v_type_int64/3}). +-dialyzer({nowarn_function,v_type_int64/3}). +v_type_int64(N, _Path, _TrUserData) when -9223372036854775808 =< N, N =< 9223372036854775807 -> ok; +v_type_int64(N, Path, _TrUserData) when is_integer(N) -> mk_type_error({value_out_of_range, int64, signed, 64}, N, Path); +v_type_int64(X, Path, _TrUserData) -> mk_type_error({bad_integer, int64, signed, 64}, X, Path). + +-compile({nowarn_unused_function,v_type_bool/3}). +-dialyzer({nowarn_function,v_type_bool/3}). +v_type_bool(false, _Path, _TrUserData) -> ok; +v_type_bool(true, _Path, _TrUserData) -> ok; +v_type_bool(0, _Path, _TrUserData) -> ok; +v_type_bool(1, _Path, _TrUserData) -> ok; +v_type_bool(X, Path, _TrUserData) -> mk_type_error(bad_boolean_value, X, Path). + +-compile({nowarn_unused_function,v_type_string/3}). +-dialyzer({nowarn_function,v_type_string/3}). +v_type_string(S, Path, _TrUserData) when is_list(S); is_binary(S) -> + try unicode:characters_to_binary(S) of + B when is_binary(B) -> ok; + {error, _, _} -> mk_type_error(bad_unicode_string, S, Path) + catch + error:badarg -> mk_type_error(bad_unicode_string, S, Path) + end; +v_type_string(X, Path, _TrUserData) -> mk_type_error(bad_unicode_string, X, Path). + +-compile({nowarn_unused_function,mk_type_error/3}). +-spec mk_type_error(_, _, list()) -> no_return(). +mk_type_error(Error, ValueSeen, Path) -> + Path2 = prettify_path(Path), + erlang:error({gpb_type_error, {Error, [{value, ValueSeen}, {path, Path2}]}}). + + +-compile({nowarn_unused_function,prettify_path/1}). +-dialyzer({nowarn_function,prettify_path/1}). +prettify_path([]) -> top_level; +prettify_path(PathR) -> lists:append(lists:join(".", lists:map(fun atom_to_list/1, lists:reverse(PathR)))). + + +-compile({nowarn_unused_function,id/2}). +-compile({inline,id/2}). +id(X, _TrUserData) -> X. + +-compile({nowarn_unused_function,v_ok/3}). +-compile({inline,v_ok/3}). +v_ok(_Value, _Path, _TrUserData) -> ok. + +-compile({nowarn_unused_function,m_overwrite/3}). +-compile({inline,m_overwrite/3}). +m_overwrite(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,cons/3}). +-compile({inline,cons/3}). +cons(Elem, Acc, _TrUserData) -> [Elem | Acc]. + +-compile({nowarn_unused_function,lists_reverse/2}). +-compile({inline,lists_reverse/2}). +'lists_reverse'(L, _TrUserData) -> lists:reverse(L). +-compile({nowarn_unused_function,'erlang_++'/3}). +-compile({inline,'erlang_++'/3}). +'erlang_++'(A, B, _TrUserData) -> A ++ B. + + +get_msg_defs() -> + [{{msg, flag}, + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, + #{name => description, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}, + #{name => enabled, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}, + #{name => created_at, fnum => 4, rnum => 5, type => {msg, timestamp}, occurrence => optional, opts => []}, + #{name => updated_at, fnum => 5, rnum => 6, type => {msg, timestamp}, occurrence => optional, opts => []}]}, + {{msg, get_flag_request}, [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}]}, + {{msg, get_flag_response}, [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => optional, opts => []}]}, + {{msg, create_flag_request}, + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, + #{name => description, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}, + #{name => enabled, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}]}, + {{msg, create_flag_response}, [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => optional, opts => []}]}, + {{msg, update_flag_request}, [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, #{name => enabled, fnum => 2, rnum => 3, type => bool, occurrence => optional, opts => []}]}, + {{msg, update_flag_response}, []}, + {{msg, list_flags_request}, []}, + {{msg, list_flags_response}, [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => repeated, opts => []}]}, + {{msg, delete_flag_request}, [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}]}, + {{msg, delete_flag_response}, []}, + {{msg, timestamp}, [#{name => seconds, fnum => 1, rnum => 2, type => int64, occurrence => optional, opts => []}, #{name => nanos, fnum => 2, rnum => 3, type => int32, occurrence => optional, opts => []}]}]. + + +get_msg_names() -> [flag, get_flag_request, get_flag_response, create_flag_request, create_flag_response, update_flag_request, update_flag_response, list_flags_request, list_flags_response, delete_flag_request, delete_flag_response, timestamp]. + + +get_group_names() -> []. + + +get_msg_or_group_names() -> + [flag, get_flag_request, get_flag_response, create_flag_request, create_flag_response, update_flag_request, update_flag_response, list_flags_request, list_flags_response, delete_flag_request, delete_flag_response, timestamp]. + + +get_enum_names() -> []. + + +fetch_msg_def(MsgName) -> + case find_msg_def(MsgName) of + Fs when is_list(Fs) -> Fs; + error -> erlang:error({no_such_msg, MsgName}) + end. + + +-spec fetch_enum_def(_) -> no_return(). +fetch_enum_def(EnumName) -> erlang:error({no_such_enum, EnumName}). + + +find_msg_def(flag) -> + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, + #{name => description, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}, + #{name => enabled, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}, + #{name => created_at, fnum => 4, rnum => 5, type => {msg, timestamp}, occurrence => optional, opts => []}, + #{name => updated_at, fnum => 5, rnum => 6, type => {msg, timestamp}, occurrence => optional, opts => []}]; +find_msg_def(get_flag_request) -> [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}]; +find_msg_def(get_flag_response) -> [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => optional, opts => []}]; +find_msg_def(create_flag_request) -> + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, + #{name => description, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}, + #{name => enabled, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}]; +find_msg_def(create_flag_response) -> [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => optional, opts => []}]; +find_msg_def(update_flag_request) -> [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}, #{name => enabled, fnum => 2, rnum => 3, type => bool, occurrence => optional, opts => []}]; +find_msg_def(update_flag_response) -> []; +find_msg_def(list_flags_request) -> []; +find_msg_def(list_flags_response) -> [#{name => flag, fnum => 1, rnum => 2, type => {msg, flag}, occurrence => repeated, opts => []}]; +find_msg_def(delete_flag_request) -> [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => optional, opts => []}]; +find_msg_def(delete_flag_response) -> []; +find_msg_def(timestamp) -> [#{name => seconds, fnum => 1, rnum => 2, type => int64, occurrence => optional, opts => []}, #{name => nanos, fnum => 2, rnum => 3, type => int32, occurrence => optional, opts => []}]; +find_msg_def(_) -> error. + + +find_enum_def(_) -> error. + + +-spec enum_symbol_by_value(_, _) -> no_return(). +enum_symbol_by_value(E, V) -> erlang:error({no_enum_defs, E, V}). + + +-spec enum_value_by_symbol(_, _) -> no_return(). +enum_value_by_symbol(E, V) -> erlang:error({no_enum_defs, E, V}). + + + +get_service_names() -> ['FeatureFlagService']. + + +get_service_def('FeatureFlagService') -> + {{service, 'FeatureFlagService'}, + [#{name => 'GetFlag', input => get_flag_request, output => get_flag_response, input_stream => false, output_stream => false, opts => []}, + #{name => 'CreateFlag', input => create_flag_request, output => create_flag_response, input_stream => false, output_stream => false, opts => []}, + #{name => 'UpdateFlag', input => update_flag_request, output => update_flag_response, input_stream => false, output_stream => false, opts => []}, + #{name => 'ListFlags', input => list_flags_request, output => list_flags_response, input_stream => false, output_stream => false, opts => []}, + #{name => 'DeleteFlag', input => delete_flag_request, output => delete_flag_response, input_stream => false, output_stream => false, opts => []}]}; +get_service_def(_) -> error. + + +get_rpc_names('FeatureFlagService') -> ['GetFlag', 'CreateFlag', 'UpdateFlag', 'ListFlags', 'DeleteFlag']; +get_rpc_names(_) -> error. + + +find_rpc_def('FeatureFlagService', RpcName) -> find_rpc_def_FeatureFlagService(RpcName); +find_rpc_def(_, _) -> error. + + +find_rpc_def_FeatureFlagService('GetFlag') -> #{name => 'GetFlag', input => get_flag_request, output => get_flag_response, input_stream => false, output_stream => false, opts => []}; +find_rpc_def_FeatureFlagService('CreateFlag') -> #{name => 'CreateFlag', input => create_flag_request, output => create_flag_response, input_stream => false, output_stream => false, opts => []}; +find_rpc_def_FeatureFlagService('UpdateFlag') -> #{name => 'UpdateFlag', input => update_flag_request, output => update_flag_response, input_stream => false, output_stream => false, opts => []}; +find_rpc_def_FeatureFlagService('ListFlags') -> #{name => 'ListFlags', input => list_flags_request, output => list_flags_response, input_stream => false, output_stream => false, opts => []}; +find_rpc_def_FeatureFlagService('DeleteFlag') -> #{name => 'DeleteFlag', input => delete_flag_request, output => delete_flag_response, input_stream => false, output_stream => false, opts => []}; +find_rpc_def_FeatureFlagService(_) -> error. + + +fetch_rpc_def(ServiceName, RpcName) -> + case find_rpc_def(ServiceName, RpcName) of + Def when is_map(Def) -> Def; + error -> erlang:error({no_such_rpc, ServiceName, RpcName}) + end. + + +%% Convert a a fully qualified (ie with package name) service name +%% as a binary to a service name as an atom. +fqbin_to_service_name(<<"FeatureFlagService">>) -> 'FeatureFlagService'; +fqbin_to_service_name(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a service name as an atom to a fully qualified +%% (ie with package name) name as a binary. +service_name_to_fqbin('FeatureFlagService') -> <<"FeatureFlagService">>; +service_name_to_fqbin(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a a fully qualified (ie with package name) service name +%% and an rpc name, both as binaries to a service name and an rpc +%% name, as atoms. +fqbins_to_service_and_rpc_name(<<"FeatureFlagService">>, <<"GetFlag">>) -> {'FeatureFlagService', 'GetFlag'}; +fqbins_to_service_and_rpc_name(<<"FeatureFlagService">>, <<"CreateFlag">>) -> {'FeatureFlagService', 'CreateFlag'}; +fqbins_to_service_and_rpc_name(<<"FeatureFlagService">>, <<"UpdateFlag">>) -> {'FeatureFlagService', 'UpdateFlag'}; +fqbins_to_service_and_rpc_name(<<"FeatureFlagService">>, <<"ListFlags">>) -> {'FeatureFlagService', 'ListFlags'}; +fqbins_to_service_and_rpc_name(<<"FeatureFlagService">>, <<"DeleteFlag">>) -> {'FeatureFlagService', 'DeleteFlag'}; +fqbins_to_service_and_rpc_name(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +%% Convert a service name and an rpc name, both as atoms, +%% to a fully qualified (ie with package name) service name and +%% an rpc name as binaries. +service_and_rpc_name_to_fqbins('FeatureFlagService', 'GetFlag') -> {<<"FeatureFlagService">>, <<"GetFlag">>}; +service_and_rpc_name_to_fqbins('FeatureFlagService', 'CreateFlag') -> {<<"FeatureFlagService">>, <<"CreateFlag">>}; +service_and_rpc_name_to_fqbins('FeatureFlagService', 'UpdateFlag') -> {<<"FeatureFlagService">>, <<"UpdateFlag">>}; +service_and_rpc_name_to_fqbins('FeatureFlagService', 'ListFlags') -> {<<"FeatureFlagService">>, <<"ListFlags">>}; +service_and_rpc_name_to_fqbins('FeatureFlagService', 'DeleteFlag') -> {<<"FeatureFlagService">>, <<"DeleteFlag">>}; +service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +fqbin_to_msg_name(<<"Flag">>) -> flag; +fqbin_to_msg_name(<<"GetFlagRequest">>) -> get_flag_request; +fqbin_to_msg_name(<<"GetFlagResponse">>) -> get_flag_response; +fqbin_to_msg_name(<<"CreateFlagRequest">>) -> create_flag_request; +fqbin_to_msg_name(<<"CreateFlagResponse">>) -> create_flag_response; +fqbin_to_msg_name(<<"UpdateFlagRequest">>) -> update_flag_request; +fqbin_to_msg_name(<<"UpdateFlagResponse">>) -> update_flag_response; +fqbin_to_msg_name(<<"ListFlagsRequest">>) -> list_flags_request; +fqbin_to_msg_name(<<"ListFlagsResponse">>) -> list_flags_response; +fqbin_to_msg_name(<<"DeleteFlagRequest">>) -> delete_flag_request; +fqbin_to_msg_name(<<"DeleteFlagResponse">>) -> delete_flag_response; +fqbin_to_msg_name(<<"google.protobuf.Timestamp">>) -> timestamp; +fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). + + +msg_name_to_fqbin(flag) -> <<"Flag">>; +msg_name_to_fqbin(get_flag_request) -> <<"GetFlagRequest">>; +msg_name_to_fqbin(get_flag_response) -> <<"GetFlagResponse">>; +msg_name_to_fqbin(create_flag_request) -> <<"CreateFlagRequest">>; +msg_name_to_fqbin(create_flag_response) -> <<"CreateFlagResponse">>; +msg_name_to_fqbin(update_flag_request) -> <<"UpdateFlagRequest">>; +msg_name_to_fqbin(update_flag_response) -> <<"UpdateFlagResponse">>; +msg_name_to_fqbin(list_flags_request) -> <<"ListFlagsRequest">>; +msg_name_to_fqbin(list_flags_response) -> <<"ListFlagsResponse">>; +msg_name_to_fqbin(delete_flag_request) -> <<"DeleteFlagRequest">>; +msg_name_to_fqbin(delete_flag_response) -> <<"DeleteFlagResponse">>; +msg_name_to_fqbin(timestamp) -> <<"google.protobuf.Timestamp">>; +msg_name_to_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec fqbin_to_enum_name(_) -> no_return(). +fqbin_to_enum_name(E) -> error({gpb_error, {badenum, E}}). + + +-spec enum_name_to_fqbin(_) -> no_return(). +enum_name_to_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_package_name() -> 'google.protobuf'. + + +%% Whether or not the message names +%% are prepended with package name or not. +uses_packages() -> true. + + +source_basename() -> "featureflag.proto". + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned with extension, +%% see get_all_proto_names/0 for a version that returns +%% the basenames sans extension +get_all_source_basenames() -> ["featureflag.proto", "timestamp.proto"]. + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned sans .proto extension, +%% to make it easier to use them with the various get_xyz_containment +%% functions. +get_all_proto_names() -> ["featureflag", "timestamp"]. + + +get_msg_containment("featureflag") -> + [create_flag_request, create_flag_response, delete_flag_request, delete_flag_response, flag, get_flag_request, get_flag_response, list_flags_request, list_flags_response, update_flag_request, update_flag_response]; +get_msg_containment("timestamp") -> [timestamp]; +get_msg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_pkg_containment("featureflag") -> undefined; +get_pkg_containment("timestamp") -> 'google.protobuf'; +get_pkg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_service_containment("featureflag") -> ['FeatureFlagService']; +get_service_containment("timestamp") -> []; +get_service_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_rpc_containment("featureflag") -> [{'FeatureFlagService', 'GetFlag'}, {'FeatureFlagService', 'CreateFlag'}, {'FeatureFlagService', 'UpdateFlag'}, {'FeatureFlagService', 'ListFlags'}, {'FeatureFlagService', 'DeleteFlag'}]; +get_rpc_containment("timestamp") -> []; +get_rpc_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_enum_containment("featureflag") -> []; +get_enum_containment("timestamp") -> []; +get_enum_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_proto_by_msg_name_as_fqbin(<<"google.protobuf.Timestamp">>) -> "timestamp"; +get_proto_by_msg_name_as_fqbin(<<"UpdateFlagRequest">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"ListFlagsRequest">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"GetFlagRequest">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"DeleteFlagRequest">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"CreateFlagRequest">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"UpdateFlagResponse">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"ListFlagsResponse">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"GetFlagResponse">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"DeleteFlagResponse">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"CreateFlagResponse">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(<<"Flag">>) -> "featureflag"; +get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +get_proto_by_service_name_as_fqbin(<<"FeatureFlagService">>) -> "featureflag"; +get_proto_by_service_name_as_fqbin(E) -> error({gpb_error, {badservice, E}}). + + +-spec get_proto_by_enum_name_as_fqbin(_) -> no_return(). +get_proto_by_enum_name_as_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_protos_by_pkg_name_as_fqbin(<<"google.protobuf">>) -> ["timestamp"]; +get_protos_by_pkg_name_as_fqbin(E) -> error({gpb_error, {badpkg, E}}). + + +descriptor() -> + <<10, 231, 6, 10, 17, 102, 101, 97, 116, 117, 114, 101, 102, 108, 97, 103, 46, 112, 114, 111, 116, 111, 34, 71, 10, 17, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, + 40, 9, 18, 19, 10, 11, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 24, 2, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 3, 32, 1, 40, 8, 34, 41, 10, 18, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, + 111, 110, 115, 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 1, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 33, 10, 17, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, + 40, 9, 34, 20, 10, 18, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 34, 154, 1, 10, 4, 70, 108, 97, 103, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 18, 19, 10, 11, 100, 101, 115, 99, 114, 105, 112, + 116, 105, 111, 110, 24, 2, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 3, 32, 1, 40, 8, 18, 46, 10, 10, 99, 114, 101, 97, 116, 101, 100, 95, 97, 116, 24, 4, 32, 1, 40, 11, 50, 26, 46, 103, 111, 111, 103, 108, 101, 46, 112, 114, + 111, 116, 111, 98, 117, 102, 46, 84, 105, 109, 101, 115, 116, 97, 109, 112, 18, 46, 10, 10, 117, 112, 100, 97, 116, 101, 100, 95, 97, 116, 24, 5, 32, 1, 40, 11, 50, 26, 46, 103, 111, 111, 103, 108, 101, 46, 112, 114, 111, 116, 111, 98, 117, 102, 46, + 84, 105, 109, 101, 115, 116, 97, 109, 112, 34, 30, 10, 14, 71, 101, 116, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 34, 38, 10, 15, 71, 101, 116, 70, 108, 97, 103, 82, 101, 115, 112, + 111, 110, 115, 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 1, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 18, 10, 16, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, 101, 113, 117, 101, 115, 116, 34, 40, 10, 17, 76, 105, 115, 116, 70, 108, 97, 103, + 115, 82, 101, 115, 112, 111, 110, 115, 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 3, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 50, 10, 17, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, + 109, 101, 24, 1, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 2, 32, 1, 40, 8, 34, 20, 10, 18, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 50, 175, 2, 10, 18, 70, 101, 97, 116, 117, 114, + 101, 70, 108, 97, 103, 83, 101, 114, 118, 105, 99, 101, 18, 48, 10, 7, 71, 101, 116, 70, 108, 97, 103, 18, 15, 46, 71, 101, 116, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 16, 46, 71, 101, 116, 70, 108, 97, 103, 82, 101, 115, 112, 111, + 110, 115, 101, 40, 0, 48, 0, 18, 57, 10, 10, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 18, 18, 46, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, + 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 18, 57, 10, 10, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 18, 18, 46, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 85, 112, 100, 97, 116, 101, 70, 108, 97, + 103, 82, 101, 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 18, 54, 10, 9, 76, 105, 115, 116, 70, 108, 97, 103, 115, 18, 17, 46, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, 101, 113, 117, 101, 115, 116, 26, 18, 46, 76, 105, 115, 116, 70, 108, 97, + 103, 115, 82, 101, 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 18, 57, 10, 10, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 18, 18, 46, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 68, 101, 108, 101, + 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 98, 6, 112, 114, 111, 116, 111, 51, 10, 103, 10, 31, 103, 111, 111, 103, 108, 101, 47, 112, 114, 111, 116, 111, 98, 117, 102, 47, 116, 105, 109, 101, 115, 116, 97, 109, + 112, 46, 112, 114, 111, 116, 111, 18, 15, 103, 111, 111, 103, 108, 101, 46, 112, 114, 111, 116, 111, 98, 117, 102, 34, 43, 10, 9, 84, 105, 109, 101, 115, 116, 97, 109, 112, 18, 15, 10, 7, 115, 101, 99, 111, 110, 100, 115, 24, 1, 32, 1, 40, 3, 18, 13, + 10, 5, 110, 97, 110, 111, 115, 24, 2, 32, 1, 40, 5, 98, 6, 112, 114, 111, 116, 111, 51>>. + +descriptor("featureflag") -> + <<10, 17, 102, 101, 97, 116, 117, 114, 101, 102, 108, 97, 103, 46, 112, 114, 111, 116, 111, 34, 71, 10, 17, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 18, 19, + 10, 11, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 24, 2, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 3, 32, 1, 40, 8, 34, 41, 10, 18, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, + 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 1, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 33, 10, 17, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 34, 20, + 10, 18, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 34, 154, 1, 10, 4, 70, 108, 97, 103, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 18, 19, 10, 11, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, + 110, 24, 2, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 3, 32, 1, 40, 8, 18, 46, 10, 10, 99, 114, 101, 97, 116, 101, 100, 95, 97, 116, 24, 4, 32, 1, 40, 11, 50, 26, 46, 103, 111, 111, 103, 108, 101, 46, 112, 114, 111, 116, 111, + 98, 117, 102, 46, 84, 105, 109, 101, 115, 116, 97, 109, 112, 18, 46, 10, 10, 117, 112, 100, 97, 116, 101, 100, 95, 97, 116, 24, 5, 32, 1, 40, 11, 50, 26, 46, 103, 111, 111, 103, 108, 101, 46, 112, 114, 111, 116, 111, 98, 117, 102, 46, 84, 105, 109, + 101, 115, 116, 97, 109, 112, 34, 30, 10, 14, 71, 101, 116, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, 1, 32, 1, 40, 9, 34, 38, 10, 15, 71, 101, 116, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, + 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 1, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 18, 10, 16, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, 101, 113, 117, 101, 115, 116, 34, 40, 10, 17, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, 101, + 115, 112, 111, 110, 115, 101, 18, 19, 10, 4, 102, 108, 97, 103, 24, 1, 32, 3, 40, 11, 50, 5, 46, 70, 108, 97, 103, 34, 50, 10, 17, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 18, 12, 10, 4, 110, 97, 109, 101, 24, + 1, 32, 1, 40, 9, 18, 15, 10, 7, 101, 110, 97, 98, 108, 101, 100, 24, 2, 32, 1, 40, 8, 34, 20, 10, 18, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 50, 175, 2, 10, 18, 70, 101, 97, 116, 117, 114, 101, 70, 108, + 97, 103, 83, 101, 114, 118, 105, 99, 101, 18, 48, 10, 7, 71, 101, 116, 70, 108, 97, 103, 18, 15, 46, 71, 101, 116, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 16, 46, 71, 101, 116, 70, 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, + 40, 0, 48, 0, 18, 57, 10, 10, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 18, 18, 46, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 67, 114, 101, 97, 116, 101, 70, 108, 97, 103, 82, 101, 115, 112, 111, + 110, 115, 101, 40, 0, 48, 0, 18, 57, 10, 10, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 18, 18, 46, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 85, 112, 100, 97, 116, 101, 70, 108, 97, 103, 82, 101, + 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 18, 54, 10, 9, 76, 105, 115, 116, 70, 108, 97, 103, 115, 18, 17, 46, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, 101, 113, 117, 101, 115, 116, 26, 18, 46, 76, 105, 115, 116, 70, 108, 97, 103, 115, 82, + 101, 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 18, 57, 10, 10, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 18, 18, 46, 68, 101, 108, 101, 116, 101, 70, 108, 97, 103, 82, 101, 113, 117, 101, 115, 116, 26, 19, 46, 68, 101, 108, 101, 116, 101, 70, + 108, 97, 103, 82, 101, 115, 112, 111, 110, 115, 101, 40, 0, 48, 0, 98, 6, 112, 114, 111, 116, 111, 51>>; +descriptor("timestamp") -> + <<10, 31, 103, 111, 111, 103, 108, 101, 47, 112, 114, 111, 116, 111, 98, 117, 102, 47, 116, 105, 109, 101, 115, 116, 97, 109, 112, 46, 112, 114, 111, 116, 111, 18, 15, 103, 111, 111, 103, 108, 101, 46, 112, 114, 111, 116, 111, 98, 117, 102, 34, 43, + 10, 9, 84, 105, 109, 101, 115, 116, 97, 109, 112, 18, 15, 10, 7, 115, 101, 99, 111, 110, 100, 115, 24, 1, 32, 1, 40, 3, 18, 13, 10, 5, 110, 97, 110, 111, 115, 24, 2, 32, 1, 40, 5, 98, 6, 112, 114, 111, 116, 111, 51>>; +descriptor(X) -> error({gpb_error, {badname, X}}). + + +gpb_version_as_string() -> + "4.19.5". + +gpb_version_as_list() -> + [4,19,5]. + +gpb_version_source() -> + "file". diff --git a/src/featureflagservice/src/ffs_service.erl b/src/featureflagservice/src/ffs_service.erl new file mode 100644 index 0000000000..939101b6f8 --- /dev/null +++ b/src/featureflagservice/src/ffs_service.erl @@ -0,0 +1,54 @@ +-module(ffs_service). + +-behaviour(ffs_service_bhvr). + +-export([get_flag/2, + create_flag/2, + update_flag/2, + list_flags/2, + delete_flag/2]). + +-include_lib("grpcbox/include/grpcbox.hrl"). + +-spec get_flag(ctx:t(), ffs_featureflag_pb:get_flag_request()) -> + {ok, ffs_featureflag_pb:get_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). +get_flag(Ctx, #{name := Name}) -> + case 'Elixir.Featureflagservice.FeatureFlags':get_feature_flag_by_name(Name) of + nil -> + {grpc_error, {?GRPC_STATUS_NOT_FOUND, <<"the requested feature flag does not exist">>}}; + #{'__struct__' := 'Elixir.Featureflagservice.FeatureFlags.FeatureFlag', + description := Description, + enabled := Enabled, + inserted_at := CreatedAt, + updated_at := UpdatedAt + } -> + {ok, Epoch} = 'Elixir.NaiveDateTime':from_erl({{1970, 1, 1}, {0, 0, 0}}), + CreatedAtSeconds = 'Elixir.NaiveDateTime':diff(CreatedAt, Epoch), + UpdatedAtSeconds = 'Elixir.NaiveDateTime':diff(UpdatedAt, Epoch), + Flag = #{name => Name, + description => Description, + enabled => Enabled, + created_at => #{seconds => CreatedAtSeconds, nanos => 0}, + updated_at => #{seconds => UpdatedAtSeconds, nanos => 0}}, + {ok, #{flag => Flag}, Ctx} + end. + +-spec create_flag(ctx:t(), ffs_featureflag_pb:create_flag_request()) -> + {ok, ffs_featureflag_pb:create_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). +create_flag(_Ctx, _) -> + {grpc_error, {?GRPC_STATUS_UNIMPLEMENTED, <<"use the web interface to create flags.">>}}. + +-spec update_flag(ctx:t(), ffs_featureflag_pb:update_flag_request()) -> + {ok, ffs_featureflag_pb:update_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). +update_flag(_Ctx, _) -> + {grpc_error, {?GRPC_STATUS_UNIMPLEMENTED, <<"use the web interface to update flags.">>}}. + +-spec list_flags(ctx:t(), ffs_featureflag_pb:list_flags_request()) -> + {ok, ffs_featureflag_pb:list_flags_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). +list_flags(_Ctx, _) -> + {grpc_error, {?GRPC_STATUS_UNIMPLEMENTED, <<"use the web interface to view all flags.">>}}. + +-spec delete_flag(ctx:t(), ffs_featureflag_pb:delete_flag_request()) -> + {ok, ffs_featureflag_pb:delete_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). +delete_flag(_Ctx, _) -> + {grpc_error, {?GRPC_STATUS_UNIMPLEMENTED, <<"use the web interface to delete flags.">>}}. diff --git a/src/featureflagservice/src/ffs_service_bhvr.erl b/src/featureflagservice/src/ffs_service_bhvr.erl new file mode 100644 index 0000000000..c15f7487c2 --- /dev/null +++ b/src/featureflagservice/src/ffs_service_bhvr.erl @@ -0,0 +1,29 @@ +%%%------------------------------------------------------------------- +%% @doc Behaviour to implement for grpc service FeatureFlagService. +%% @end +%%%------------------------------------------------------------------- + +%% this module was generated and should not be modified manually + +-module(ffs_service_bhvr). + +%% Unary RPC +-callback get_flag(ctx:t(), ffs_featureflag_pb:get_flag_request()) -> + {ok, ffs_featureflag_pb:get_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). + +%% Unary RPC +-callback create_flag(ctx:t(), ffs_featureflag_pb:create_flag_request()) -> + {ok, ffs_featureflag_pb:create_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). + +%% Unary RPC +-callback update_flag(ctx:t(), ffs_featureflag_pb:update_flag_request()) -> + {ok, ffs_featureflag_pb:update_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). + +%% Unary RPC +-callback list_flags(ctx:t(), ffs_featureflag_pb:list_flags_request()) -> + {ok, ffs_featureflag_pb:list_flags_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). + +%% Unary RPC +-callback delete_flag(ctx:t(), ffs_featureflag_pb:delete_flag_request()) -> + {ok, ffs_featureflag_pb:delete_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response(). + diff --git a/src/featureflagservice/src/ffs_service_client.erl b/src/featureflagservice/src/ffs_service_client.erl new file mode 100644 index 0000000000..85c8087c2a --- /dev/null +++ b/src/featureflagservice/src/ffs_service_client.erl @@ -0,0 +1,115 @@ +%%%------------------------------------------------------------------- +%% @doc Client module for grpc service FeatureFlagService. +%% @end +%%%------------------------------------------------------------------- + +%% this module was generated and should not be modified manually + +-module(ffs_service_client). + +-compile(export_all). +-compile(nowarn_export_all). + +-include_lib("grpcbox/include/grpcbox.hrl"). + +-define(is_ctx(Ctx), is_tuple(Ctx) andalso element(1, Ctx) =:= ctx). + +-define(SERVICE, 'FeatureFlagService'). +-define(PROTO_MODULE, 'ffs_featureflag_pb'). +-define(MARSHAL_FUN(T), fun(I) -> ?PROTO_MODULE:encode_msg(I, T) end). +-define(UNMARSHAL_FUN(T), fun(I) -> ?PROTO_MODULE:decode_msg(I, T) end). +-define(DEF(Input, Output, MessageType), #grpcbox_def{service=?SERVICE, + message_type=MessageType, + marshal_fun=?MARSHAL_FUN(Input), + unmarshal_fun=?UNMARSHAL_FUN(Output)}). + +%% @doc Unary RPC +-spec get_flag(ffs_featureflag_pb:get_flag_request()) -> + {ok, ffs_featureflag_pb:get_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +get_flag(Input) -> + get_flag(ctx:new(), Input, #{}). + +-spec get_flag(ctx:t() | ffs_featureflag_pb:get_flag_request(), ffs_featureflag_pb:get_flag_request() | grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:get_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +get_flag(Ctx, Input) when ?is_ctx(Ctx) -> + get_flag(Ctx, Input, #{}); +get_flag(Input, Options) -> + get_flag(ctx:new(), Input, Options). + +-spec get_flag(ctx:t(), ffs_featureflag_pb:get_flag_request(), grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:get_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +get_flag(Ctx, Input, Options) -> + grpcbox_client:unary(Ctx, <<"/FeatureFlagService/GetFlag">>, Input, ?DEF(get_flag_request, get_flag_response, <<"GetFlagRequest">>), Options). + +%% @doc Unary RPC +-spec create_flag(ffs_featureflag_pb:create_flag_request()) -> + {ok, ffs_featureflag_pb:create_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +create_flag(Input) -> + create_flag(ctx:new(), Input, #{}). + +-spec create_flag(ctx:t() | ffs_featureflag_pb:create_flag_request(), ffs_featureflag_pb:create_flag_request() | grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:create_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +create_flag(Ctx, Input) when ?is_ctx(Ctx) -> + create_flag(Ctx, Input, #{}); +create_flag(Input, Options) -> + create_flag(ctx:new(), Input, Options). + +-spec create_flag(ctx:t(), ffs_featureflag_pb:create_flag_request(), grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:create_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +create_flag(Ctx, Input, Options) -> + grpcbox_client:unary(Ctx, <<"/FeatureFlagService/CreateFlag">>, Input, ?DEF(create_flag_request, create_flag_response, <<"CreateFlagRequest">>), Options). + +%% @doc Unary RPC +-spec update_flag(ffs_featureflag_pb:update_flag_request()) -> + {ok, ffs_featureflag_pb:update_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +update_flag(Input) -> + update_flag(ctx:new(), Input, #{}). + +-spec update_flag(ctx:t() | ffs_featureflag_pb:update_flag_request(), ffs_featureflag_pb:update_flag_request() | grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:update_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +update_flag(Ctx, Input) when ?is_ctx(Ctx) -> + update_flag(Ctx, Input, #{}); +update_flag(Input, Options) -> + update_flag(ctx:new(), Input, Options). + +-spec update_flag(ctx:t(), ffs_featureflag_pb:update_flag_request(), grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:update_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +update_flag(Ctx, Input, Options) -> + grpcbox_client:unary(Ctx, <<"/FeatureFlagService/UpdateFlag">>, Input, ?DEF(update_flag_request, update_flag_response, <<"UpdateFlagRequest">>), Options). + +%% @doc Unary RPC +-spec list_flags(ffs_featureflag_pb:list_flags_request()) -> + {ok, ffs_featureflag_pb:list_flags_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +list_flags(Input) -> + list_flags(ctx:new(), Input, #{}). + +-spec list_flags(ctx:t() | ffs_featureflag_pb:list_flags_request(), ffs_featureflag_pb:list_flags_request() | grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:list_flags_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +list_flags(Ctx, Input) when ?is_ctx(Ctx) -> + list_flags(Ctx, Input, #{}); +list_flags(Input, Options) -> + list_flags(ctx:new(), Input, Options). + +-spec list_flags(ctx:t(), ffs_featureflag_pb:list_flags_request(), grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:list_flags_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +list_flags(Ctx, Input, Options) -> + grpcbox_client:unary(Ctx, <<"/FeatureFlagService/ListFlags">>, Input, ?DEF(list_flags_request, list_flags_response, <<"ListFlagsRequest">>), Options). + +%% @doc Unary RPC +-spec delete_flag(ffs_featureflag_pb:delete_flag_request()) -> + {ok, ffs_featureflag_pb:delete_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +delete_flag(Input) -> + delete_flag(ctx:new(), Input, #{}). + +-spec delete_flag(ctx:t() | ffs_featureflag_pb:delete_flag_request(), ffs_featureflag_pb:delete_flag_request() | grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:delete_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +delete_flag(Ctx, Input) when ?is_ctx(Ctx) -> + delete_flag(Ctx, Input, #{}); +delete_flag(Input, Options) -> + delete_flag(ctx:new(), Input, Options). + +-spec delete_flag(ctx:t(), ffs_featureflag_pb:delete_flag_request(), grpcbox_client:options()) -> + {ok, ffs_featureflag_pb:delete_flag_response(), grpcbox:metadata()} | grpcbox_stream:grpc_error_response() | {error, any()}. +delete_flag(Ctx, Input, Options) -> + grpcbox_client:unary(Ctx, <<"/FeatureFlagService/DeleteFlag">>, Input, ?DEF(delete_flag_request, delete_flag_response, <<"DeleteFlagRequest">>), Options). + diff --git a/src/featureflagservice/test/featureflagservice/feature_flags_test.exs b/src/featureflagservice/test/featureflagservice/feature_flags_test.exs new file mode 100644 index 0000000000..01a3e1fbbd --- /dev/null +++ b/src/featureflagservice/test/featureflagservice/feature_flags_test.exs @@ -0,0 +1,63 @@ +defmodule Featureflagservice.FeatureFlagsTest do + use Featureflagservice.DataCase + + alias Featureflagservice.FeatureFlags + + describe "featureflags" do + alias Featureflagservice.FeatureFlags.FeatureFlag + + import Featureflagservice.FeatureFlagsFixtures + + @invalid_attrs %{description: nil, enabled: nil, name: nil} + + test "list_featureflags/0 returns all featureflags" do + feature_flag = feature_flag_fixture() + assert FeatureFlags.list_featureflags() == [feature_flag] + end + + test "get_feature_flag!/1 returns the feature_flag with given id" do + feature_flag = feature_flag_fixture() + assert FeatureFlags.get_feature_flag!(feature_flag.id) == feature_flag + end + + test "create_feature_flag/1 with valid data creates a feature_flag" do + valid_attrs = %{description: "some description", enabled: true, name: "some name"} + + assert {:ok, %FeatureFlag{} = feature_flag} = FeatureFlags.create_feature_flag(valid_attrs) + assert feature_flag.description == "some description" + assert feature_flag.enabled == true + assert feature_flag.name == "some name" + end + + test "create_feature_flag/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = FeatureFlags.create_feature_flag(@invalid_attrs) + end + + test "update_feature_flag/2 with valid data updates the feature_flag" do + feature_flag = feature_flag_fixture() + update_attrs = %{description: "some updated description", enabled: false, name: "some updated name"} + + assert {:ok, %FeatureFlag{} = feature_flag} = FeatureFlags.update_feature_flag(feature_flag, update_attrs) + assert feature_flag.description == "some updated description" + assert feature_flag.enabled == false + assert feature_flag.name == "some updated name" + end + + test "update_feature_flag/2 with invalid data returns error changeset" do + feature_flag = feature_flag_fixture() + assert {:error, %Ecto.Changeset{}} = FeatureFlags.update_feature_flag(feature_flag, @invalid_attrs) + assert feature_flag == FeatureFlags.get_feature_flag!(feature_flag.id) + end + + test "delete_feature_flag/1 deletes the feature_flag" do + feature_flag = feature_flag_fixture() + assert {:ok, %FeatureFlag{}} = FeatureFlags.delete_feature_flag(feature_flag) + assert_raise Ecto.NoResultsError, fn -> FeatureFlags.get_feature_flag!(feature_flag.id) end + end + + test "change_feature_flag/1 returns a feature_flag changeset" do + feature_flag = feature_flag_fixture() + assert %Ecto.Changeset{} = FeatureFlags.change_feature_flag(feature_flag) + end + end +end diff --git a/src/featureflagservice/test/featureflagservice_web/controllers/feature_flag_controller_test.exs b/src/featureflagservice/test/featureflagservice_web/controllers/feature_flag_controller_test.exs new file mode 100644 index 0000000000..a8d74e3639 --- /dev/null +++ b/src/featureflagservice/test/featureflagservice_web/controllers/feature_flag_controller_test.exs @@ -0,0 +1,84 @@ +defmodule FeatureflagserviceWeb.FeatureFlagControllerTest do + use FeatureflagserviceWeb.ConnCase + + import Featureflagservice.FeatureFlagsFixtures + + @create_attrs %{description: "some description", enabled: true, name: "some name"} + @update_attrs %{description: "some updated description", enabled: false, name: "some updated name"} + @invalid_attrs %{description: nil, enabled: nil, name: nil} + + describe "index" do + test "lists all featureflags", %{conn: conn} do + conn = get(conn, Routes.feature_flag_path(conn, :index)) + assert html_response(conn, 200) =~ "Listing Featureflags" + end + end + + describe "new feature_flag" do + test "renders form", %{conn: conn} do + conn = get(conn, Routes.feature_flag_path(conn, :new)) + assert html_response(conn, 200) =~ "New Feature flag" + end + end + + describe "create feature_flag" do + test "redirects to show when data is valid", %{conn: conn} do + conn = post(conn, Routes.feature_flag_path(conn, :create), feature_flag: @create_attrs) + + assert %{id: id} = redirected_params(conn) + assert redirected_to(conn) == Routes.feature_flag_path(conn, :show, id) + + conn = get(conn, Routes.feature_flag_path(conn, :show, id)) + assert html_response(conn, 200) =~ "Show Feature flag" + end + + test "renders errors when data is invalid", %{conn: conn} do + conn = post(conn, Routes.feature_flag_path(conn, :create), feature_flag: @invalid_attrs) + assert html_response(conn, 200) =~ "New Feature flag" + end + end + + describe "edit feature_flag" do + setup [:create_feature_flag] + + test "renders form for editing chosen feature_flag", %{conn: conn, feature_flag: feature_flag} do + conn = get(conn, Routes.feature_flag_path(conn, :edit, feature_flag)) + assert html_response(conn, 200) =~ "Edit Feature flag" + end + end + + describe "update feature_flag" do + setup [:create_feature_flag] + + test "redirects when data is valid", %{conn: conn, feature_flag: feature_flag} do + conn = put(conn, Routes.feature_flag_path(conn, :update, feature_flag), feature_flag: @update_attrs) + assert redirected_to(conn) == Routes.feature_flag_path(conn, :show, feature_flag) + + conn = get(conn, Routes.feature_flag_path(conn, :show, feature_flag)) + assert html_response(conn, 200) =~ "some updated description" + end + + test "renders errors when data is invalid", %{conn: conn, feature_flag: feature_flag} do + conn = put(conn, Routes.feature_flag_path(conn, :update, feature_flag), feature_flag: @invalid_attrs) + assert html_response(conn, 200) =~ "Edit Feature flag" + end + end + + describe "delete feature_flag" do + setup [:create_feature_flag] + + test "deletes chosen feature_flag", %{conn: conn, feature_flag: feature_flag} do + conn = delete(conn, Routes.feature_flag_path(conn, :delete, feature_flag)) + assert redirected_to(conn) == Routes.feature_flag_path(conn, :index) + + assert_error_sent 404, fn -> + get(conn, Routes.feature_flag_path(conn, :show, feature_flag)) + end + end + end + + defp create_feature_flag(_) do + feature_flag = feature_flag_fixture() + %{feature_flag: feature_flag} + end +end diff --git a/src/featureflagservice/test/featureflagservice_web/controllers/page_controller_test.exs b/src/featureflagservice/test/featureflagservice_web/controllers/page_controller_test.exs new file mode 100644 index 0000000000..bb0f20b314 --- /dev/null +++ b/src/featureflagservice/test/featureflagservice_web/controllers/page_controller_test.exs @@ -0,0 +1,8 @@ +defmodule FeatureflagserviceWeb.PageControllerTest do + use FeatureflagserviceWeb.ConnCase + + test "GET /", %{conn: conn} do + _conn = get(conn, "/") + assert true + end +end diff --git a/src/featureflagservice/test/featureflagservice_web/views/error_view_test.exs b/src/featureflagservice/test/featureflagservice_web/views/error_view_test.exs new file mode 100644 index 0000000000..bbadcb82ef --- /dev/null +++ b/src/featureflagservice/test/featureflagservice_web/views/error_view_test.exs @@ -0,0 +1,14 @@ +defmodule FeatureflagserviceWeb.ErrorViewTest do + use FeatureflagserviceWeb.ConnCase, async: true + + # Bring render/3 and render_to_string/3 for testing custom views + import Phoenix.View + + test "renders 404.html" do + assert render_to_string(FeatureflagserviceWeb.ErrorView, "404.html", []) == "Not Found" + end + + test "renders 500.html" do + assert render_to_string(FeatureflagserviceWeb.ErrorView, "500.html", []) == "Internal Server Error" + end +end diff --git a/src/featureflagservice/test/featureflagservice_web/views/layout_view_test.exs b/src/featureflagservice/test/featureflagservice_web/views/layout_view_test.exs new file mode 100644 index 0000000000..e4055bc08c --- /dev/null +++ b/src/featureflagservice/test/featureflagservice_web/views/layout_view_test.exs @@ -0,0 +1,8 @@ +defmodule FeatureflagserviceWeb.LayoutViewTest do + use FeatureflagserviceWeb.ConnCase, async: true + + # When testing helpers, you may want to import Phoenix.HTML and + # use functions such as safe_to_string() to convert the helper + # result into an HTML string. + # import Phoenix.HTML +end diff --git a/src/featureflagservice/test/featureflagservice_web/views/page_view_test.exs b/src/featureflagservice/test/featureflagservice_web/views/page_view_test.exs new file mode 100644 index 0000000000..2b187a7763 --- /dev/null +++ b/src/featureflagservice/test/featureflagservice_web/views/page_view_test.exs @@ -0,0 +1,3 @@ +defmodule FeatureflagserviceWeb.PageViewTest do + use FeatureflagserviceWeb.ConnCase, async: true +end diff --git a/src/featureflagservice/test/support/conn_case.ex b/src/featureflagservice/test/support/conn_case.ex new file mode 100644 index 0000000000..4d0639de86 --- /dev/null +++ b/src/featureflagservice/test/support/conn_case.ex @@ -0,0 +1,38 @@ +defmodule FeatureflagserviceWeb.ConnCase do + @moduledoc """ + This module defines the test case to be used by + tests that require setting up a connection. + + Such tests rely on `Phoenix.ConnTest` and also + import other functionality to make it easier + to build common data structures and query the data layer. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use FeatureflagserviceWeb.ConnCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with connections + import Plug.Conn + import Phoenix.ConnTest + import FeatureflagserviceWeb.ConnCase + + alias FeatureflagserviceWeb.Router.Helpers, as: Routes + + # The default endpoint for testing + @endpoint FeatureflagserviceWeb.Endpoint + end + end + + setup tags do + Featureflagservice.DataCase.setup_sandbox(tags) + {:ok, conn: Phoenix.ConnTest.build_conn()} + end +end diff --git a/src/featureflagservice/test/support/data_case.ex b/src/featureflagservice/test/support/data_case.ex new file mode 100644 index 0000000000..7f7b312d93 --- /dev/null +++ b/src/featureflagservice/test/support/data_case.ex @@ -0,0 +1,58 @@ +defmodule Featureflagservice.DataCase do + @moduledoc """ + This module defines the setup for tests requiring + access to the application's data layer. + + You may define functions here to be used as helpers in + your tests. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use Featureflagservice.DataCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + alias Featureflagservice.Repo + + import Ecto + import Ecto.Changeset + import Ecto.Query + import Featureflagservice.DataCase + end + end + + setup tags do + Featureflagservice.DataCase.setup_sandbox(tags) + :ok + end + + @doc """ + Sets up the sandbox based on the test tags. + """ + def setup_sandbox(tags) do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Featureflagservice.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + end + + @doc """ + A helper that transforms changeset errors into a map of messages. + + assert {:error, changeset} = Accounts.create_user(%{password: "short"}) + assert "password is too short" in errors_on(changeset).password + assert %{password: ["password is too short"]} = errors_on(changeset) + + """ + def errors_on(changeset) do + Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> + Regex.replace(~r"%{(\w+)}", message, fn _, key -> + opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() + end) + end) + end +end diff --git a/src/featureflagservice/test/support/fixtures/feature_flags_fixtures.ex b/src/featureflagservice/test/support/fixtures/feature_flags_fixtures.ex new file mode 100644 index 0000000000..fe5728a59e --- /dev/null +++ b/src/featureflagservice/test/support/fixtures/feature_flags_fixtures.ex @@ -0,0 +1,27 @@ +defmodule Featureflagservice.FeatureFlagsFixtures do + @moduledoc """ + This module defines test helpers for creating + entities via the `Featureflagservice.FeatureFlags` context. + """ + + @doc """ + Generate a unique feature_flag name. + """ + def unique_feature_flag_name, do: "some name#{System.unique_integer([:positive])}" + + @doc """ + Generate a feature_flag. + """ + def feature_flag_fixture(attrs \\ %{}) do + {:ok, feature_flag} = + attrs + |> Enum.into(%{ + description: "some description", + enabled: true, + name: unique_feature_flag_name() + }) + |> Featureflagservice.FeatureFlags.create_feature_flag() + + feature_flag + end +end diff --git a/src/featureflagservice/test/test_helper.exs b/src/featureflagservice/test/test_helper.exs new file mode 100644 index 0000000000..3dacb23a39 --- /dev/null +++ b/src/featureflagservice/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +Ecto.Adapters.SQL.Sandbox.mode(Featureflagservice.Repo, :manual) diff --git a/src/otelcollector/otelcol-config.yml b/src/otelcollector/otelcol-config.yml index 8d723b13a1..e653551b5f 100644 --- a/src/otelcollector/otelcol-config.yml +++ b/src/otelcollector/otelcol-config.yml @@ -3,7 +3,6 @@ receivers: protocols: grpc: http: - exporters: jaeger: endpoint: "jaeger:14250"