Docs
upload-plugin

upload-plugin

The datagen-rs-upload-plugin is a plugin for datagen-rs (opens in a new tab) providing the ability to upload generated data to a server. The plugin provides a serialization interface to serialize the generated data to a string and upload it to a server.

Parameters

The plugin has the following parameters:

NameTypeDescriptionDefault
urlURLThe URL to upload the data to.unset
methodHttpMethodThe HTTP method to use.post
serializerserializer (opens in a new tab)The serializer to use.json
returnNullboolWhether to discard the serialized value. If set to true, an empty string will be returned by datagenfalse
headersMap<string, string>A map containing headers to send with the request.{}
splitTopLevelArrayboolWhether to split the top level array into multiple requests. If set to true, each element in the top level array will be uploaded in a separate request.false
numParallelRequestsusizeThe number of parallel requests to send.1
expectedStatusu16The expected status code. If the status code of the response is not equal to this value, an error will be returned.200
timeoutu64The timeout in milliseconds.infinite
authAuthArgsThe authentication method to use.none
uploadInUploadInThe data to upload.body
disableCertificateVerificationboolWhether to disable SSL certificate verification. ONLY DISABLE IF YOU KNOW WHAT YOU ARE DOINGfalse
rootCAstring | string[]The root CA to use for certificate verification. If a string is provided, it will be used as the path to the root CA certificate. If an array is provided, each element in the array will be used as a path to a root CA certificate.unset

URL

The URL type is used to specify the URL to upload the data to.

It is defined as follows: String | Map<String, String>.

If a string is provided, it will be used as the URL. If a map is provided, the first type in the generated schema must be an object where each key in the map is a field in the object and the value is the URL to use for that field. If splitTopLevelArray is set to true, any top-level array in the object will be split into multiple requests, with each element in the array being uploaded to the URL specified in the map.

HttpMethod

The HttpMethod enum is used to specify the HTTP method to use. The following values are available:

  • post
  • put
  • patch

AuthArgs

The AuthArgs object is used to specify the authentication method to use. The authentication type is specified by the type field. The following authentication types are available:

basic

The basic authentication method is used to send a username and password to the server. The AuthArgs object has the following fields:

NameTypeDescriptionDefault
type'basic'The authentication type. Must be 'basic'.
usernameStringThe username to use.unset
passwordStringThe password to use. Optional.unset

bearer

The bearer authentication method is used to send a bearer token to the server.

NameTypeDescriptionDefault
type'bearer'The authentication type. Must be 'bearer'.
tokenStringThe token to use.unset

oidc

The oidc authentication method is used to send a bearer token to the server using the OpenID Connect Protocol (opens in a new tab) for retrieving the token.

NameTypeDescriptionDefault
type'oidc'The authentication type. Must be 'oidc'.
clientIdStringThe client ID to use.unset
clientSecretStringThe client secret to use. Optional.none
discoveryUrlStringThe OIDC endpoint discovery URL.unset
scopesString[]The scopes to use.[]
authFlowOidcAuthFlowThe authentication flow to use.authorizationCode
authTypeOidcAuthTypeThe authentication type to use.requestBody
methodOidcLoginMethodThe method to use for logging in.unset
OidcAuthFlow

The OidcAuthFlow enum is used to specify the authentication flow to use. The following values are available:

OidcAuthType

The OidcAuthType enum is used to specify where the credentials will be sent to the oidc provider. The following values are available:

  • requestBody: The credentials will be sent in the request body.
  • basicAuth: The credentials will be sent as basic auth.
OidcLoginMethod

The OidcLoginMethod object is used to specify the method to use for logging in. Currently, there are three methods available:

clientCredentials

The clientCredentials method is used to authorize the client using the client credentials flow (opens in a new tab). This method only has a type field, which must be set to 'clientCredentials'. The client credentials flow will use the clientId and clientSecret fields from the oidc object to authorize the client. The clientSecret field must not be unset.

NameTypeDescriptionDefault
type'clientCredentials'The login method. Must be 'clientCredentials'.unset
password

The password method is used to authorize the client with the users username and password using the Client Credentials Flow (opens in a new tab).

NameTypeDescriptionDefault
type'password'The login method. Must be 'password'.unset
usernameStringThe username to use.unset
passwordStringThe password to use.unset
deviceCode

The deviceCode method is used to authorize the client using the Device Authorization Flow (opens in a new tab).

NameTypeDescriptionDefault
type'deviceCode'The login method. Must be 'deviceCode'.unset
deviceAuthorizationUrlStringThe URL to use for device authorizationunset

UploadIn

The UploadIn enum is used to specify the data to upload. The following values are available:

  • body
  • query
  • form

Examples

Upload data without authentication

{
  "type": "string",
  "value": "test",
  "options": {
    "serializer": {
      "type": "plugin",
      "pluginName": "upload_plugin",
      "args": {
        "url": "http://localhost:8080/upload",
        "method": "post",
        "serializer": {
          "type": "json",
          "pretty": true
        },
        "expectedStatus": 200,
        "timeout": 1000
      }
    }
  }
}

Upload data with oidc using a Keycloak instance as the oidc provider

{
  "type": "string",
  "value": "test",
  "options": {
    "serializer": {
      "type": "plugin",
      "pluginName": "upload_plugin",
      "args": {
        "url": "http://localhost:8080/upload",
        "auth": {
          "type": "oidc",
          "clientId": "my-client-id",
          "clientSecret": "my-client-secret",
          "discoveryUrl": "http://localhost:8080/realms/my-realm",
          "scopes": ["openid", "profile", "email"],
          "method": {
            "type": "deviceCode",
            "deviceAuthorizationUrl": "http://localhost:8080/realms/my-realm/protocol/openid-connect/auth/device"
          }
        }
      }
    }
  }
}

Note that the /auth prefix at the end of the hostname is only required for Keycloak instances with version 16 or lower. Starting from version 17, the /auth prefix must be omitted.

Upload data with basic authentication

{
  "type": "string",
  "value": "test",
  "options": {
    "serializer": {
      "type": "plugin",
      "pluginName": "upload_plugin",
      "args": {
        "url": "http://localhost:8080/upload",
        "auth": {
          "type": "basic",
          "username": "my-username",
          "password": "my-password"
        }
      }
    }
  }
}

Upload data with multiple URLs

{
  "type": "object",
  "properties": {
    "a": {
      "type": "string",
      "value": "test"
    },
    "b": {
      "type": "string",
      "value": "test"
    }
  },
  "options": {
    "serializer": {
      "type": "plugin",
      "pluginName": "upload_plugin",
      "args": {
        "url": {
          "a": "http://localhost:8080/upload/a",
          "b": "http://localhost:8080/upload/b"
        }
      }
    }
  }
}

This will upload the content of the a field to http://localhost:8080/upload/a and the content of the b field to http://localhost:8080/upload/b.