diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml index 6b46ebb..a271121 100644 --- a/.github/workflows/dependabot.yml +++ b/.github/workflows/dependabot.yml @@ -19,7 +19,10 @@ permissions: contents: write jobs: + test: + uses: ./.github/workflows/test.yml dependabot: + needs: test runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} env: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index e848a77..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Publish to Maven Central Repository -on: - workflow_dispatch: - release: - types: [created] -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Java - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b - - name: Create .gpg key - run: | - echo $GPG_KEY_ARMOR | base64 --decode > ./release.asc - gpg --quiet --output $GITHUB_WORKSPACE/release.gpg --dearmor ./release.asc - SONATYPE_PASSWORD_ESCAPED=$(printf '%s\n' "$SONATYPE_PASSWORD" | sed -e 's/[\/&]/\\&/g') - sed -i -e "s,sonatypeUsername=,sonatypeUsername=$SONATYPE_USERNAME,g" gradle.properties - sed -i -e "s,sonatypePassword=,sonatypePassword=$SONATYPE_PASSWORD_ESCAPED,g" gradle.properties - sed -i -e "s,githubPassword=,githubPassword=$GITHUB_PASSWORD,g" gradle.properties - sed -i -e "s,signing.keyId=,signing.keyId=$GPG_KEY_ID,g" gradle.properties - sed -i -e "s,signing.password=,signing.password=$GPG_PASSWORD,g" gradle.properties - sed -i -e "s,signing.secretKeyRingFile=,signing.secretKeyRingFile=$GITHUB_WORKSPACE/release.gpg,g" gradle.properties - env: - GPG_KEY_ARMOR: "${{ secrets.SYNCED_GPG_KEY_ARMOR }}" - GPG_KEY_ID: ${{ secrets.SYNCED_GPG_KEY_ID }} - GPG_PASSWORD: ${{ secrets.SYNCED_GPG_KEY_PASSWORD }} - SONATYPE_PASSWORD: '${{ secrets.SYNCED_SONATYPE_PASSWORD }}' - SONATYPE_USERNAME: ${{ secrets.SYNCED_SONATYPE_USERNAME }} - GITHUB_PASSWORD: '${{ secrets.SYNCED_GITHUB_TOKEN_REPO }}' - - name: Publish package - uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021 - with: - arguments: publish - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc900a3..9cedc57 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,10 @@ on: workflow_dispatch: jobs: + test: + uses: ./.github/workflows/test.yml release: + needs: test runs-on: ubuntu-latest steps: - name: Checkout @@ -46,14 +49,11 @@ jobs: SONATYPE_USERNAME: ${{ secrets.SYNCED_SONATYPE_USERNAME }} GITHUB_PASSWORD: '${{ secrets.SYNCED_GITHUB_TOKEN_REPO }}' - name: Semantic Release - uses: cycjimmy/semantic-release-action@v3 + uses: cycjimmy/semantic-release-action@v4 with: extra_plugins: | - "@semantic-release/commit-analyzer" - "@semantic-release/release-notes-generator" "@google/semantic-release-replace-plugin" "@semantic-release/exec" - "@semantic-release/git" "@semantic-release/github" env: GH_TOKEN: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} diff --git a/.github/workflows/main.yml b/.github/workflows/test.yml similarity index 67% rename from .github/workflows/main.yml rename to .github/workflows/test.yml index 423475a..92d5340 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/test.yml @@ -1,16 +1,17 @@ # This workflow will build a Java project with Gradle # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle -name: Java CI with Gradle +name: Test on: push: branches: [ main ] pull_request: branches: [ main ] + workflow_call: jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -29,15 +30,5 @@ jobs: run: | cd ./sample/ ./gradlew test - - name: Release - uses: cycjimmy/semantic-release-action@v3 - with: - extra_plugins: | - "@semantic-release/commit-analyzer" - "@semantic-release/release-notes-generator" - "@google/semantic-release-replace-plugin" - "@semantic-release/exec" - "@semantic-release/git" - "@semantic-release/github" env: GH_TOKEN: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} diff --git a/README.md b/README.md index 9026b72..0fbd3ef 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,6 @@ You can add the library to your project via Maven or Gradle. fleetengine-auth (insert latest version) - - com.auth0 - java-jwt - 3.10.2 - - - com.google.guava - guava - 1.55.0 - - - com.google.auth - google-auth-library-oauth2-http - 0.26.0 - ``` @@ -49,9 +34,6 @@ You can add the library to your project via Maven or Gradle. ```groovy dependencies { implementation 'com.google.maps:fleetengine-auth:(insert latest version here)' - implementation 'com.auth0:java-jwt:3.10.2' - implementation 'com.google.guava:guava:1.55.0' - implementation 'com.google.auth:google-auth-library-oauth2-http:0.26.0' } ``` diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradlew b/gradlew index 4f906e0..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..93e3f59 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/sample/build.gradle b/sample/build.gradle index 5bde9d5..fe6d768 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -36,14 +36,22 @@ run { standardInput = System.in } +sourceSets.all { + configurations.getByName(runtimeClasspathConfigurationName) { + attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm") + } + configurations.getByName(compileClasspathConfigurationName) { + attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm") + } +} dependencies { annotationProcessor 'com.google.auto.value:auto-value:1.6.2' implementation 'com.google.api:gax:1.65.1' implementation 'com.google.api:gax-grpc:1.65.1' - implementation 'com.google.maps:gapic-google-maps-fleetengine-v1-java:0.0.348' - implementation 'com.google.maps:gapic-google-maps-fleetengine-delivery-v1-java:0.0.348' + implementation 'com.google.maps:gapic-google-maps-fleetengine-v1-java:0.0.3231' + implementation 'com.google.maps:gapic-google-maps-fleetengine-delivery-v1-java:0.0.3231' implementation project(':fleetengine-auth') testImplementation 'junit:junit:4.13.1' diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar index e708b1c..7f93135 100644 Binary files a/sample/gradle/wrapper/gradle-wrapper.jar and b/sample/gradle/wrapper/gradle-wrapper.jar differ diff --git a/sample/gradlew b/sample/gradlew index 4f906e0..1aa94a4 100755 --- a/sample/gradlew +++ b/sample/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/sample/gradlew.bat b/sample/gradlew.bat index ac1b06f..93e3f59 100755 --- a/sample/gradlew.bat +++ b/sample/gradlew.bat @@ -1,89 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/DeliveryServiceStubClient.java b/sample/src/main/java/com/google/fleetengine/auth/sample/DeliveryServiceStubClient.java index 4e33055..f2fdebd 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/DeliveryServiceStubClient.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/DeliveryServiceStubClient.java @@ -7,8 +7,9 @@ import google.maps.fleetengine.delivery.v1.DeliveryVehicle; import google.maps.fleetengine.delivery.v1.GetDeliveryVehicleRequest; import google.maps.fleetengine.delivery.v1.GetTaskRequest; -import google.maps.fleetengine.delivery.v1.SearchTasksRequest; +import google.maps.fleetengine.delivery.v1.GetTaskTrackingInfoRequest; import google.maps.fleetengine.delivery.v1.Task; +import google.maps.fleetengine.delivery.v1.TaskTrackingInfo; import google.maps.fleetengine.delivery.v1.UpdateTaskRequest; public class DeliveryServiceStubClient implements DeliveryServiceStub { @@ -31,8 +32,9 @@ public Task getTask(GetTaskRequest getTaskRequest) { } @Override - public void searchTasks(SearchTasksRequest searchTripRequest) { - client.searchTasks(searchTripRequest); + public TaskTrackingInfo getTaskTrackingInfo( + GetTaskTrackingInfoRequest getTaskTrackingInfoRequest) { + return client.getTaskTrackingInfo(getTaskTrackingInfoRequest); } @Override diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/LmfsConfiguration.java b/sample/src/main/java/com/google/fleetengine/auth/sample/LmfsConfiguration.java index 80892b8..f9451a6 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/LmfsConfiguration.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/LmfsConfiguration.java @@ -25,6 +25,10 @@ public class LmfsConfiguration { public static final String DELIVERY_FLEET_READER_TOKEN_ACCOUNT = "@.iam.gserviceaccount.com"; + // Set to service account with the Fleet Engine Fleet Read SDK role. + public static final String FLEET_READER_TOKEN_ACCOUNT = + "@.iam.gserviceaccount.com"; + // Provider Id is the same as your GCP Project Id. public static final String PROVIDER_ID = ""; diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/OdrdConfiguration.java b/sample/src/main/java/com/google/fleetengine/auth/sample/OdrdConfiguration.java index 5c04710..2825176 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/OdrdConfiguration.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/OdrdConfiguration.java @@ -32,6 +32,10 @@ class OdrdConfiguration { public static final String DRIVER_TOKEN_ACCOUNT = "@.iam.gserviceaccount.com"; + // Set to service account with the Fleet Engine Fleet Read SDK role. + public static final String FLEET_READER_TOKEN_ACCOUNT = + "@.iam.gserviceaccount.com"; + // Provider Id is the same as your GCP Project Id. public static final String PROVIDER_ID = ""; diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateLmfsRoles.java b/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateLmfsRoles.java index 28fed70..f014d30 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateLmfsRoles.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateLmfsRoles.java @@ -1,7 +1,9 @@ package com.google.fleetengine.auth.sample; import com.google.fleetengine.auth.AuthTokenMinter; +import com.google.fleetengine.auth.sample.validation.DeliveryConsumerFleetReaderTokenValidationScript; import com.google.fleetengine.auth.sample.validation.DeliveryConsumerTokenValidationScript; +import com.google.fleetengine.auth.sample.validation.DeliveryDriverFleetReaderTokenValidationScript; import com.google.fleetengine.auth.sample.validation.DeliveryFleetReaderTokenValidationScript; import com.google.fleetengine.auth.sample.validation.DeliveryServerTokenValidationScript; import com.google.fleetengine.auth.sample.validation.DeliveryServerTokenValidationScript.Ids; @@ -18,6 +20,7 @@ public class ValidateLmfsRoles { private static final String CONSUMER = "deliver consumer"; private static final String UNTRUSTED_DRIVER = "untrusted driver"; private static final String TRUSTED_DRIVER = "trusted driver"; + private static final String DELIVERY_FLEET_READER = "delivery fleet reader"; private static final String FLEET_READER = "fleet reader"; public static void run() throws Throwable { @@ -34,6 +37,8 @@ public static void run() throws Throwable { LmfsConfiguration.DELIVERY_UNTRUSTED_DRIVER_TOKEN_ACCOUNT)) .setDeliveryFleetReaderSigner( ImpersonatedSigner.create(LmfsConfiguration.DELIVERY_FLEET_READER_TOKEN_ACCOUNT)) + .setFleetReaderSigner( + ImpersonatedSigner.create(LmfsConfiguration.FLEET_READER_TOKEN_ACCOUNT)) .setTokenFactory( new FleetEngineTokenFactory( FleetEngineTokenFactorySettings.builder() @@ -78,11 +83,27 @@ public static void run() throws Throwable { } if (configuration.getMinter().deliveryFleetReaderSigner() != null) { - CommandLineRuntime.printRunScriptMessage(FLEET_READER); + CommandLineRuntime.printRunScriptMessage(DELIVERY_FLEET_READER); new DeliveryFleetReaderTokenValidationScript(runtime, configuration, clientFactory) + .run(ids.getTrackingId()); + } else { + CommandLineRuntime.printSkipScriptMessage(DELIVERY_FLEET_READER); + } + + if (configuration.getMinter().deliveryFleetReaderSigner() != null) { + CommandLineRuntime.printRunScriptMessage(FLEET_READER); + new DeliveryConsumerFleetReaderTokenValidationScript(runtime, configuration, clientFactory) + .run(ids.getTrackingId()); + } else { + CommandLineRuntime.printSkipScriptMessage(FLEET_READER); + } + + if (configuration.getMinter().deliveryFleetReaderSigner() != null) { + CommandLineRuntime.printRunScriptMessage(FLEET_READER); + new DeliveryDriverFleetReaderTokenValidationScript(runtime, configuration, clientFactory) .run(ids.getDeliveryVehicleId()); } else { - CommandLineRuntime.printSkipScriptMessage(TRUSTED_DRIVER); + CommandLineRuntime.printSkipScriptMessage(FLEET_READER); } } } diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateOdrdRoles.java b/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateOdrdRoles.java index eb6b382..22d1550 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateOdrdRoles.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/ValidateOdrdRoles.java @@ -17,6 +17,7 @@ import com.google.fleetengine.auth.AuthTokenMinter; import com.google.fleetengine.auth.sample.validation.ConsumerTokenValidationScript; import com.google.fleetengine.auth.sample.validation.DriverTokenValidationScript; +import com.google.fleetengine.auth.sample.validation.ConsumerFleetReaderTokenValidationScript; import com.google.fleetengine.auth.sample.validation.SampleScriptConfiguration; import com.google.fleetengine.auth.sample.validation.SampleScriptRuntime; import com.google.fleetengine.auth.sample.validation.ServerTokenValidationScript; @@ -30,6 +31,7 @@ final class ValidateOdrdRoles { private static final String SERVER = "server"; private static final String CONSUMER = "consumer"; private static final String DRIVER = "driver"; + private static final String FLEET_READER = "fleet reader"; public static void run() throws Throwable { AuthTokenMinter minter = @@ -37,6 +39,8 @@ public static void run() throws Throwable { .setServerSigner(ImpersonatedSigner.create(OdrdConfiguration.SERVER_TOKEN_ACCOUNT)) .setConsumerSigner(ImpersonatedSigner.create(OdrdConfiguration.CONSUMER_TOKEN_ACCOUNT)) .setDriverSigner(ImpersonatedSigner.create(OdrdConfiguration.DRIVER_TOKEN_ACCOUNT)) + .setFleetReaderSigner( + ImpersonatedSigner.create(OdrdConfiguration.FLEET_READER_TOKEN_ACCOUNT)) .setTokenFactory( new FleetEngineTokenFactory( FleetEngineTokenFactorySettings.builder() @@ -70,6 +74,14 @@ public static void run() throws Throwable { } else { CommandLineRuntime.printSkipScriptMessage(DRIVER); } + + if (configuration.getMinter().fleetReaderSigner() != null) { + CommandLineRuntime.printRunScriptMessage(FLEET_READER); + new ConsumerFleetReaderTokenValidationScript(runtime, configuration, clientFactory) + .run(ids.getTripId()); + } else { + CommandLineRuntime.printSkipScriptMessage(FLEET_READER); + } } private ValidateOdrdRoles() {} diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/ConsumerFleetReaderTokenValidationScript.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/ConsumerFleetReaderTokenValidationScript.java new file mode 100644 index 0000000..3dd1836 --- /dev/null +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/ConsumerFleetReaderTokenValidationScript.java @@ -0,0 +1,45 @@ +package com.google.fleetengine.auth.sample.validation; + +/** Validates that fleet reader tokens provide the correct access. */ +public class ConsumerFleetReaderTokenValidationScript { + + private final SampleScriptRuntime runtime; + private final SampleScriptConfiguration configuration; + private final CommandsFactory commandsFactory; + + public ConsumerFleetReaderTokenValidationScript( + SampleScriptRuntime runtime, + SampleScriptConfiguration configuration, + CommandsFactory commandsFactory) { + this.runtime = runtime; + this.configuration = configuration; + this.commandsFactory = commandsFactory; + } + + /** + * Run validation script. + * + * @param tripId existing trip id + */ + public void run(String tripId) throws Throwable { + // Tokens are minted with the fleet reader role and authorized to access tripId. + TripCommands tripCommands = + commandsFactory.createTripCommands( + configuration.getFleetEngineAddress(), + configuration.getProviderId(), + () -> configuration.getMinter().getFleetReaderToken()); + + VehicleCommands vehicleCommands = + commandsFactory.createVehicleCommands( + configuration.getFleetEngineAddress(), + configuration.getProviderId(), + () -> configuration.getMinter().getFleetReaderToken()); + + runtime.runCommand( + "Get trip with trip id on fleet reader token", () -> tripCommands.getTrip(tripId)); + + runtime.runCommand( + "Search for vehicles with fleet reader token", + () -> vehicleCommands.searchVehicles(tripId)); + } +} diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerFleetReaderTokenValidationScript.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerFleetReaderTokenValidationScript.java new file mode 100644 index 0000000..8fb5736 --- /dev/null +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerFleetReaderTokenValidationScript.java @@ -0,0 +1,38 @@ +package com.google.fleetengine.auth.sample.validation; + +/** Validates that fleet reader tokens provide the correct access. */ +public class DeliveryConsumerFleetReaderTokenValidationScript { + + private final SampleScriptRuntime runtime; + private final SampleScriptConfiguration configuration; + private final CommandsFactory commandsFactory; + + public DeliveryConsumerFleetReaderTokenValidationScript( + SampleScriptRuntime runtime, + SampleScriptConfiguration configuration, + CommandsFactory commandsFactory) { + this.runtime = runtime; + this.configuration = configuration; + this.commandsFactory = commandsFactory; + } + + /** + * Run validation script. + * + * @param trackingId existing tracking id + */ + public void run(String trackingId) throws Throwable { + // Tokens are minted with the fleet reader role and authorized to access trackingId. + DeliveryServiceCommands commands = + commandsFactory.createDeliveryServiceCommands( + configuration.getFleetEngineAddress(), + configuration.getProviderId(), + () -> configuration.getMinter().getFleetReaderToken()); + + runtime.runCommand( + "Get task tracking info with fleet reader token", + () -> { + var unused = commands.getTaskTrackingInfo(trackingId); + }); + } +} diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerTokenValidationScript.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerTokenValidationScript.java index 6832980..b082b1a 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerTokenValidationScript.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryConsumerTokenValidationScript.java @@ -29,8 +29,10 @@ public void run(String trackingId) throws Throwable { .getDeliveryConsumerToken(TrackingClaims.create(trackingId))); runtime.runCommand( - "Search tasks with delivery consumer token", - () -> taskCommandsWithTrackingId.searchTasks(trackingId)); + "Get task tracking info with delivery consumer token", + () -> { + var unused = taskCommandsWithTrackingId.getTaskTrackingInfo(trackingId); + }); DeliveryServiceCommands taskCommandsWithIncorrectTrackingId = commandsFactory.createDeliveryServiceCommands( @@ -43,7 +45,10 @@ public void run(String trackingId) throws Throwable { TrackingClaims.create(ScriptUtils.generateRandomTrackingId()))); runtime.expectPermissionDenied( - "Search task fails when tracking id of task different than delivery " + "consumer token", - () -> taskCommandsWithIncorrectTrackingId.searchTasks(trackingId)); + "Get task tracking info fails when tracking id of task different than delivery " + + "consumer token", + () -> { + var unused = taskCommandsWithIncorrectTrackingId.getTaskTrackingInfo(trackingId); + }); } } diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryDriverFleetReaderTokenValidationScript.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryDriverFleetReaderTokenValidationScript.java new file mode 100644 index 0000000..a3c9d1d --- /dev/null +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryDriverFleetReaderTokenValidationScript.java @@ -0,0 +1,36 @@ +package com.google.fleetengine.auth.sample.validation; + +/** Validates that fleet reader tokens provide the correct access. */ +public class DeliveryDriverFleetReaderTokenValidationScript { + + private final SampleScriptRuntime runtime; + private final SampleScriptConfiguration configuration; + private final CommandsFactory commandsFactory; + + public DeliveryDriverFleetReaderTokenValidationScript( + SampleScriptRuntime runtime, + SampleScriptConfiguration configuration, + CommandsFactory commandsFactory) { + this.runtime = runtime; + this.configuration = configuration; + this.commandsFactory = commandsFactory; + } + + /** + * Run validation script. + * + * @param deliveryVehicleId existing delivery vehicle id + */ + public void run(String deliveryVehicleId) throws Throwable { + // Tokens are minted with the fleet reader role and authorized to access deliveryVehicleId. + DeliveryServiceCommands commands = + commandsFactory.createDeliveryServiceCommands( + configuration.getFleetEngineAddress(), + configuration.getProviderId(), + () -> configuration.getMinter().getFleetReaderToken()); + + runtime.runCommand( + "Get delivery vehicle with fleet reader token", + () -> commands.getDeliveryVehicle(deliveryVehicleId)); + } +} diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryFleetReaderTokenValidationScript.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryFleetReaderTokenValidationScript.java index 1e067d8..2493437 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryFleetReaderTokenValidationScript.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryFleetReaderTokenValidationScript.java @@ -24,6 +24,9 @@ public void run(String trackingId) throws Throwable { () -> configuration.getMinter().getDeliveryFleetReaderToken()); runtime.runCommand( - "Search tasks with fleet reader token", () -> commands.searchTasks(trackingId)); + "Get task tracking info with delivery fleet reader token", + () -> { + var unused = commands.getTaskTrackingInfo(trackingId); + }); } } diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceCommands.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceCommands.java index 81f9fcb..d688a2e 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceCommands.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceCommands.java @@ -8,11 +8,12 @@ import google.maps.fleetengine.delivery.v1.DeliveryVehicle; import google.maps.fleetengine.delivery.v1.GetDeliveryVehicleRequest; import google.maps.fleetengine.delivery.v1.GetTaskRequest; +import google.maps.fleetengine.delivery.v1.GetTaskTrackingInfoRequest; import google.maps.fleetengine.delivery.v1.LocationInfo; -import google.maps.fleetengine.delivery.v1.SearchTasksRequest; import google.maps.fleetengine.delivery.v1.Task; import google.maps.fleetengine.delivery.v1.Task.State; import google.maps.fleetengine.delivery.v1.Task.TaskOutcome; +import google.maps.fleetengine.delivery.v1.TaskTrackingInfo; import google.maps.fleetengine.delivery.v1.UpdateTaskRequest; public class DeliveryServiceCommands { @@ -56,13 +57,12 @@ public Task getTask(String taskId) { } /** Search existing tasks by tracking id. */ - public void searchTasks(String trackingId) { - SearchTasksRequest searchTasksRequest = - SearchTasksRequest.newBuilder() - .setParent(ScriptUtils.getProviderName(providerId)) - .setTrackingId(trackingId) + public TaskTrackingInfo getTaskTrackingInfo(String trackingId) { + GetTaskTrackingInfoRequest getTaskTrackingInfoRequest = + GetTaskTrackingInfoRequest.newBuilder() + .setName(getTaskTrackingInfoName(trackingId)) .build(); - stub.searchTasks(searchTasksRequest); + return stub.getTaskTrackingInfo(getTaskTrackingInfoRequest); } /** Update task outcome to succeed. */ @@ -84,6 +84,10 @@ private String getTaskName(String taskId) { return String.format("providers/%s/tasks/%s", providerId, taskId); } + private String getTaskTrackingInfoName(String trackingId) { + return String.format("providers/%s/taskTrackingInfo/%s", providerId, trackingId); + } + public DeliveryVehicle createDeliveryVehicle(String deliveryVehicleId) { DeliveryVehicle deliveryVehicle = DeliveryVehicle.newBuilder().setName(getDeliveryVehicleName(deliveryVehicleId)).build(); diff --git a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceStub.java b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceStub.java index be1d791..4ad0a1c 100644 --- a/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceStub.java +++ b/sample/src/main/java/com/google/fleetengine/auth/sample/validation/DeliveryServiceStub.java @@ -5,8 +5,9 @@ import google.maps.fleetengine.delivery.v1.DeliveryVehicle; import google.maps.fleetengine.delivery.v1.GetDeliveryVehicleRequest; import google.maps.fleetengine.delivery.v1.GetTaskRequest; -import google.maps.fleetengine.delivery.v1.SearchTasksRequest; +import google.maps.fleetengine.delivery.v1.GetTaskTrackingInfoRequest; import google.maps.fleetengine.delivery.v1.Task; +import google.maps.fleetengine.delivery.v1.TaskTrackingInfo; import google.maps.fleetengine.delivery.v1.UpdateTaskRequest; /** Wraps {@link google.maps.fleetengine.delivery.v1.DeliveryServiceClient} for testing purposes. */ @@ -25,9 +26,9 @@ public interface DeliveryServiceStub { /** * see: {@link - * google.maps.fleetengine.delivery.v1.DeliveryServiceClient#searchTasks(SearchTasksRequest)} + * google.maps.fleetengine.delivery.v1.DeliveryServiceClient#getTaskTrackingInfo(GetTaskTrackingInfoRequest)} */ - void searchTasks(SearchTasksRequest searchTripRequest); + TaskTrackingInfo getTaskTrackingInfo(GetTaskTrackingInfoRequest getTaskTrackingInfoRequest); /** * see: {@link diff --git a/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryConsumerTokenValidationScriptTest.java b/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryConsumerTokenValidationScriptTest.java index 5fe52be..94a372a 100644 --- a/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryConsumerTokenValidationScriptTest.java +++ b/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryConsumerTokenValidationScriptTest.java @@ -4,7 +4,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -49,17 +48,17 @@ public void setup() throws IOException { } @Test - public void run_callsSearchTasks_withTrackingId() throws Throwable { + public void run_callsGetTaskTrackingInfo_withTrackingId() throws Throwable { DeliveryConsumerTokenValidationScript script = new DeliveryConsumerTokenValidationScript(runtime, configuration, commandsFactory); script.run(TEST_TRACKING_ID); ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(deliveryServiceCommandsSuccess, times(1)).searchTasks(captor.capture()); + verify(deliveryServiceCommandsSuccess).getTaskTrackingInfo(captor.capture()); assertEquals(TEST_TRACKING_ID, captor.getValue()); runtime.wasExpectPermissionDeniedCalled(); - verify(deliveryServiceCommandsFails, times(1)).searchTasks(captor.capture()); + verify(deliveryServiceCommandsFails).getTaskTrackingInfo(captor.capture()); assertEquals(TEST_TRACKING_ID, captor.getValue()); } } diff --git a/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryFleetReaderTokenValidationScriptTest.java b/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryFleetReaderTokenValidationScriptTest.java index 9554d38..b8bbaa9 100644 --- a/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryFleetReaderTokenValidationScriptTest.java +++ b/sample/src/test/java/com/google/fleetengine/auth/sample/DeliveryFleetReaderTokenValidationScriptTest.java @@ -4,7 +4,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -46,13 +45,13 @@ public void setup() throws IOException { } @Test - public void run_callsSearchTasks_withTrackingId() throws Throwable { + public void run_callsGetTaskTrackingInfo_withTrackingId() throws Throwable { DeliveryFleetReaderTokenValidationScript script = new DeliveryFleetReaderTokenValidationScript(runtime, configuration, commandsFactory); script.run(TEST_TRACKING_ID); ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(deliveryServiceCommands, times(1)).searchTasks(captor.capture()); + verify(deliveryServiceCommands).getTaskTrackingInfo(captor.capture()); assertEquals(TEST_TRACKING_ID, captor.getValue()); } } diff --git a/src/main/java/com/google/fleetengine/auth/AuthTokenMinter.java b/src/main/java/com/google/fleetengine/auth/AuthTokenMinter.java index b7713fa..e365681 100644 --- a/src/main/java/com/google/fleetengine/auth/AuthTokenMinter.java +++ b/src/main/java/com/google/fleetengine/auth/AuthTokenMinter.java @@ -91,6 +91,10 @@ public abstract class AuthTokenMinter implements FleetEngineTokenProvider { @Nullable public abstract Signer deliveryFleetReaderSigner(); + /** Signer responsible for signing JWTs with a fleet reader key. */ + @Nullable + public abstract Signer fleetReaderSigner(); + /** Signer responsible for signing JWTs with that aren't tied to the standard role set. */ @Nullable public abstract Signer customSigner(); @@ -345,6 +349,22 @@ public FleetEngineToken getDeliveryFleetReaderToken() throws SigningTokenExcepti return tokenStateManager().signToken(deliveryFleetReaderSigner(), unsignedToken); } + /** + * Returns a non expired Fleet Engine Token that was signed with the fleet reader signer. + * + *

Tokens will have an expiration of at least {@link + * FleetEngineAuthTokenStateManager#EXPIRATION_WINDOW_DURATION}. + * + * @throws SigningTokenException if the fleet reader server signer was not set, or if there is an + * issue while signing the token. + * @return Fleet Engine token with the "Fleet Reader" role, guaranteed to be valid for {@link + * FleetEngineAuthTokenStateManager#EXPIRATION_WINDOW_DURATION} minutes. + */ + public FleetEngineToken getFleetReaderToken() throws SigningTokenException { + FleetEngineToken unsignedToken = tokenFactory().createFleetReaderToken(); + return tokenStateManager().signToken(fleetReaderSigner(), unsignedToken); + } + /** * Returns a non expired Fleet Engine Token that was signed with the custom signer * and authorized for use with entities matching the specified claim. @@ -411,6 +431,9 @@ public abstract static class Builder { /** Sets the signer responsible for signing delivery fleet JWTs. */ public abstract Builder setDeliveryFleetReaderSigner(Signer deliveryFleetReaderSigner); + /** Sets the signer responsible for signing fleet reader JWTs. */ + public abstract Builder setFleetReaderSigner(Signer fleetReaderSigner); + /** * Sets token factory that creates unsigned tokens. * diff --git a/src/main/java/com/google/fleetengine/auth/token/FleetEngineTokenType.java b/src/main/java/com/google/fleetengine/auth/token/FleetEngineTokenType.java index 8f428fa..4183f25 100644 --- a/src/main/java/com/google/fleetengine/auth/token/FleetEngineTokenType.java +++ b/src/main/java/com/google/fleetengine/auth/token/FleetEngineTokenType.java @@ -64,6 +64,12 @@ public enum FleetEngineTokenType { */ DELIVERY_FLEET_READER, + /** + * Fleet reader tokens are usually service accounts associated with the Fleet Engine Fleet Reader + * User role on the Google Cloud project. + */ + FLEET_READER, + /** Custom token type associated with any Fleet Engine Role on the Google Cloud project. */ CUSTOM, } diff --git a/src/main/java/com/google/fleetengine/auth/token/FleetReaderClaims.java b/src/main/java/com/google/fleetengine/auth/token/FleetReaderClaims.java new file mode 100644 index 0000000..a556f99 --- /dev/null +++ b/src/main/java/com/google/fleetengine/auth/token/FleetReaderClaims.java @@ -0,0 +1,40 @@ +package com.google.fleetengine.auth.token; + +import com.google.common.collect.ImmutableMap; + +/** + * Special claim for fleet reader claims. Authorizes a token for use with all trips, tasks, + * vehicles, and delivery vehicles. + */ +public class FleetReaderClaims implements FleetEngineTokenClaims { + + private static final String WILDCARD = "*"; + private static final FleetReaderClaims SINGLETON = new FleetReaderClaims(); + private final ImmutableMap map; + + /** Creates a delivery fleet reader token claims object. */ + public static FleetReaderClaims create() { + return SINGLETON; + } + + private FleetReaderClaims() { + // Load all claims with a wild card. + map = + ImmutableMap.of( + TripClaims.CLAIM_TRIP_ID, WILDCARD, + TaskClaims.CLAIM_TASK_ID, WILDCARD, + TrackingClaims.CLAIM_TRACKING_ID, WILDCARD, + VehicleClaims.CLAIM_VEHICLE_ID, WILDCARD, + DeliveryVehicleClaims.CLAIM_DELIVERY_VEHICLE_ID, WILDCARD); + } + + @Override + public ImmutableMap toMap() { + return map; + } + + @Override + public boolean isWildcard() { + return true; + } +} diff --git a/src/main/java/com/google/fleetengine/auth/token/factory/FleetEngineTokenFactory.java b/src/main/java/com/google/fleetengine/auth/token/factory/FleetEngineTokenFactory.java index 8e01d3d..08a9110 100644 --- a/src/main/java/com/google/fleetengine/auth/token/factory/FleetEngineTokenFactory.java +++ b/src/main/java/com/google/fleetengine/auth/token/factory/FleetEngineTokenFactory.java @@ -22,6 +22,7 @@ import com.google.fleetengine.auth.token.FleetEngineToken; import com.google.fleetengine.auth.token.FleetEngineTokenClaims; import com.google.fleetengine.auth.token.FleetEngineTokenType; +import com.google.fleetengine.auth.token.FleetReaderClaims; import com.google.fleetengine.auth.token.ServerTokenClaims; import com.google.fleetengine.auth.token.TaskClaims; import com.google.fleetengine.auth.token.TrackingClaims; @@ -133,6 +134,12 @@ public FleetEngineToken createDeliveryFleetReaderToken() { FleetEngineTokenType.DELIVERY_FLEET_READER, DeliveryFleetReaderClaims.create()); } + /** {@inheritDoc} */ + @Override + public FleetEngineToken createFleetReaderToken() { + return createToken(FleetEngineTokenType.FLEET_READER, FleetReaderClaims.create()); + } + /** {@inheritDoc} */ @Override public FleetEngineToken createCustomToken(FleetEngineTokenClaims claims) { diff --git a/src/main/java/com/google/fleetengine/auth/token/factory/TokenFactory.java b/src/main/java/com/google/fleetengine/auth/token/factory/TokenFactory.java index df38c06..cd5e49a 100644 --- a/src/main/java/com/google/fleetengine/auth/token/factory/TokenFactory.java +++ b/src/main/java/com/google/fleetengine/auth/token/factory/TokenFactory.java @@ -89,6 +89,12 @@ FleetEngineToken createTrustedDeliveryDriverToken( */ FleetEngineToken createDeliveryFleetReaderToken(); + /** + * Creates tokens for the {@link + * com.google.fleetengine.auth.token.FleetEngineTokenType#FLEET_READER} role. + */ + FleetEngineToken createFleetReaderToken(); + /** * Creates tokens for tokens of type {@link * com.google.fleetengine.auth.token.FleetEngineTokenType#CUSTOM} and can be associated to any diff --git a/src/test/java/com/google/fleetengine/auth/AuthTokenMinterTest.java b/src/test/java/com/google/fleetengine/auth/AuthTokenMinterTest.java index d72a446..419daf6 100644 --- a/src/test/java/com/google/fleetengine/auth/AuthTokenMinterTest.java +++ b/src/test/java/com/google/fleetengine/auth/AuthTokenMinterTest.java @@ -54,6 +54,7 @@ public class AuthTokenMinterTest { private Signer untrustedDeliveryDriverSigner; private Signer trustedDeliveryDriverSigner; private Signer deliveryFleetReaderSigner; + private Signer fleetReaderSigner; private Signer customSigner; private FleetEngineAuthTokenStateManager authStateManager; private AuthTokenMinter.Builder defaultFleetEngineAuthBuilder; @@ -70,6 +71,7 @@ public void setup() { this.untrustedDeliveryDriverSigner = mock(Signer.class); this.trustedDeliveryDriverSigner = mock(Signer.class); this.deliveryFleetReaderSigner = mock(Signer.class); + this.fleetReaderSigner = mock(Signer.class); this.customSigner = mock(Signer.class); this.authStateManager = mock(FleetEngineAuthTokenStateManager.class); this.tokenFactory = mock(TokenFactory.class); @@ -250,6 +252,18 @@ public void getDeliveryServerToken_whenDeliveryServerSignerSet_signsWithSetDeliv .signToken(eq(deliveryFleetReaderSigner), eq(fleetEngineToken)); } + @Test + public void getFleetReaderToken_whenFleetReaderSignerSet_signsWithSetFleetReaderSigner() + throws SigningTokenException { + AuthTokenMinter baseFleetEngineAuth = + defaultFleetEngineAuthBuilder.setFleetReaderSigner(fleetReaderSigner).build(); + when(tokenFactory.createFleetReaderToken()).thenReturn(fleetEngineToken); + + FleetEngineToken unused = baseFleetEngineAuth.getFleetReaderToken(); + + verify(authStateManager, times(1)).signToken(eq(fleetReaderSigner), eq(fleetEngineToken)); + } + @Test public void getCustomToken_whenCustomSignerSet_signsWithSetCustomSigner() throws SigningTokenException { diff --git a/version.properties b/version.properties index 23bd66f..80d6c60 100644 --- a/version.properties +++ b/version.properties @@ -15,5 +15,5 @@ ################################################################################ # Used by conventional commits in github. Do not touch. -libVersion=1.11.0 +libVersion=1.12.0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy