q-shift / backstage-plugins

Apache License 2.0
3 stars 7 forks source link

Add the Starter Code field to the POST request for code.quarkus.io #29

Closed aureamunoz closed 9 months ago

aureamunoz commented 9 months ago

In order to have some code in the generated project we need to pass the Starter Code field with yesvalue. This way some basic resources will be included in the project depending on the extensions added.

cmoulliard commented 9 months ago

to pass the Starter Code field with

I suppose that the field to be used is providesCode as the other is deprecated: https://github.com/quarkusio/code.quarkus.io/blob/9d3a11b6df02d23aaa98c21105c4504f636ce268/base/src/main/java/io/quarkus/code/model/CodeQuarkusExtension.java#L70-L71

        @Deprecated boolean providesExampleCode,
        boolean providesCode,

After digging into the code, I think that the right string to be used is : https://github.com/quarkusio/code.quarkus.io/blob/main/base/src/main/java/io/quarkus/code/model/ProjectDefinition.java#L78-L79

private Boolean noCode
cmoulliard commented 9 months ago

If we send to code.quarkus.io, such a JSON body

{"groupId":"io.quarkus","artifactId":"quarkus-app","version":"1.0.0-SNAPSHOT","buildTool":"MAVEN","javaVersion":"11","extensions":["io.quarkus:quarkus-resteasy-reactive","io.quarkus:quarkus-hibernate-orm","quarkus-info","quarkus-smallrye-health","quarkus-jdbc-postgresql"],"noCode":"true"}

, then we got a HTTP error 400

Error making HTTP POST request: AxiosError: Request failed with status code 400
    at settle (/Users/cmoullia/code/openshift/backstage/fork-backstage-playground/node_modules/axios/lib/core/settle.js:19:12)
    at Unzip.handleStreamEnd (/Users/cmoullia/code/openshift/backstage/fork-backstage-playground/node_modules/axios/lib/adapters/http.js:589:11)
    at Unzip.emit (node:events:530:35)
    at Unzip.emit (node:domain:488:12)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_BAD_REQUEST',
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function], Blob: [class Blob] },
    validateStatus: [Function: validateStatus],
    headers: Object [AxiosHeaders] {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': '*',
      'User-Agent': 'axios/1.6.5',
      'Content-Length': '289',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    responseType: 'arraybuffer',
    method: 'post',
    url: 'https://code.quarkus.io/api/download',
    data: '{"groupId":"io.quarkus","artifactId":"quarkus-app","version":"1.0.0-SNAPSHOT","buildTool":"MAVEN","javaVersion":"11","extensions":["io.quarkus:quarkus-resteasy-reactive","io.quarkus:quarkus-hibernate-orm","quarkus-info","quarkus-smallrye-health","quarkus-jdbc-postgresql"],"noCode":"true"}'
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: true,
    _last: false,
    chunkedEncoding: false,
    shouldKeepAlive: true,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: '289',
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: true,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'code.quarkus.io',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'code.quarkus.io',
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _writableState: [WritableState],
      allowHalfOpen: false,
      _maxListeners: undefined,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      timeout: 5000,
      parser: null,
      _httpMessage: null,
      autoSelectFamilyAttemptedAddresses: [Array],
      [Symbol(alpncallback)]: null,
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: -1,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: Timeout {
        _idleTimeout: 5000,
        _idlePrev: [TimersList],
        _idleNext: [Timeout],
        _idleStart: 77174,
        _onTimeout: [Function: bound ],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(refed)]: false,
        [Symbol(kHasPrimitive)]: false,
        [Symbol(asyncId)]: 11422,
        [Symbol(triggerId)]: 11420
      },
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(shapeMode)]: true,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 1,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },

Do you know why ? @aureamunoz

cmoulliard commented 9 months ago

It seems that we got such HTTP error 400 as the java version passed is incorrect. 11 should be now 17or 21. We got too an error HTTP 400 when we post a curl request

Note: As such a problem can occurs again, passing the right parameters to code.quarkus.io will become mandatory (jav version ,etc) @aureamunoz

curl -v -d @quarkus.json -X POST https://code.quarkus.io/api/download -H 'Content-Type: application/json'
...
> POST /api/download HTTP/2
> Host: code.quarkus.io
> User-Agent: curl/8.1.2
> Accept: */*
> Content-Type: application/json
> Content-Length: 254
> 
* We are completely uploaded and fine
< HTTP/2 400 
< access-control-allow-credentials: false

where quarkus.json

{
  "groupId": "io.quarkus",
  "artifactId": "quarkus-app",
  "version": "1.0.0-SNAPSHOT",
  "buildTool": "MAVEN",
  "javaVersion": "17",
  "extensions": [
    "io.quarkus:quarkus-resteasy-reactive",
    "io.quarkus:quarkus-hibernate-orm",
    "quarkus-info",
    "quarkus-smallrye-health",
    "quarkus-jdbc-postgresql"
  ],
  "noCode": "false"
}
aureamunoz commented 9 months ago

Oui, From Quarkus 3.7 no more java 11.

iocanel commented 9 months ago

fixed as of: https://github.com/q-shift/backstage-plugins/pull/30