From 3d3f6a83f8d25af0011aaebb8d59a675298dd8b0 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Wed, 4 Sep 2024 14:10:03 -0700 Subject: [PATCH] feat(proxy): add config to proxy world Signed-off-by: Jiaxiao Zhou (Mossaka) --- .github/workflows/main.yml | 1 + imports.md | 50 ++++++++++++++++++++++++++++-- proxy.md | 50 ++++++++++++++++++++++++++++-- wit/deps.lock | 13 +++++--- wit/deps.toml | 1 + wit/deps/config/runtime_config.wit | 25 +++++++++++++++ wit/deps/config/world.wit | 6 ++++ wit/deps/filesystem/types.wit | 6 ---- wit/deps/io/streams.wit | 4 +++ wit/proxy.wit | 5 +++ 10 files changed, 145 insertions(+), 16 deletions(-) create mode 100644 wit/deps/config/runtime_config.wit create mode 100644 wit/deps/config/world.wit diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5ad565..61a0d54 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,3 +21,4 @@ jobs: wasm-tools: '1.215.0' wit-bindgen: '0.30.0' worlds: 'imports proxy' + features: 'config' diff --git a/imports.md b/imports.md index 6a3caf1..4467228 100644 --- a/imports.md +++ b/imports.md @@ -13,6 +13,7 @@ It is intended to be included in other worlds.

  • interface wasi:cli/stdout@0.2.1
  • interface wasi:cli/stderr@0.2.1
  • interface wasi:cli/stdin@0.2.1
  • +
  • interface wasi:config/runtime@0.2.0-draft
  • interface wasi:http/types@0.2.1
  • interface wasi:http/outgoing-handler@0.2.1
  • @@ -258,6 +259,8 @@ when it does, they are expected to subsume this API.

    last-operation-failed: own<error>

    The last operation (a write or flush) failed before completion.

    More information is available in the error payload.

    +

    After this, the stream will be closed. All future operations return +stream-error::closed.

  • closed

    @@ -604,6 +607,47 @@ is ready for reading, before performing the splice.

    +

    Import interface wasi:config/runtime@0.2.0-draft

    +
    +

    Types

    +

    variant config-error

    +

    An error type that encapsulates the different errors that can occur fetching config

    +
    Variant Cases
    +
      +
    • +

      upstream: string

      +

      This indicates an error from an "upstream" config source. +As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), +the error message is a string. +

    • +
    • +

      io: string

      +

      This indicates an error from an I/O operation. +As this could be almost _anything_ (such as a file read, network connection, etc), +the error message is a string. +Depending on how this ends up being consumed, +we may consider moving this to use the `wasi:io/error` type instead. +For simplicity right now in supporting multiple implementations, it is being left as a string. +

    • +
    +
    +

    Functions

    +

    get: func

    +

    Gets a single opaque config value set at the given key if it exists

    +
    Params
    +
      +
    • key: string
    • +
    +
    Return values
    + +

    get-all: func

    +

    Gets a list of all set config data

    +
    Return values
    +

    Import interface wasi:http/types@0.2.1

    This interface defines all of the types and methods for implementing HTTP Requests and Responses, both incoming and outgoing, as well as @@ -629,7 +673,7 @@ their headers, trailers, and bodies.

    This type corresponds to HTTP standard Methods.

    Variant Cases
      -
    • get
    • +
    • get
    • head
    • post
    • put
    • @@ -1341,7 +1385,7 @@ This function will trap if the input-stream

      [method]future-trailers.subscribe: func

      Returns a pollable which becomes ready when either the trailers have been received, or an error has occurred. When this pollable is ready, -the get method will return some.

      +the get method will return some.

      Params
      • self: borrow<future-trailers>
      • @@ -1476,7 +1520,7 @@ Content-Length.

        [method]future-incoming-response.subscribe: func

        Returns a pollable which becomes ready when either the Response has been received, or an error has occurred. When this pollable is ready, -the get method will return some.

        +the get method will return some.

        Params
        @@ -191,6 +192,8 @@ when it does, they are expected to subsume this API.

        last-operation-failed: own<error>

        The last operation (a write or flush) failed before completion.

        More information is available in the error payload.

        +

        After this, the stream will be closed. All future operations return +stream-error::closed.

      • closed

        @@ -523,7 +526,7 @@ their headers, trailers, and bodies.

        This type corresponds to HTTP standard Methods.

        Variant Cases
          -
        • get
        • +
        • get
        • head
        • post
        • put
        • @@ -1235,7 +1238,7 @@ This function will trap if the input-stream

          [method]future-trailers.subscribe: func

          Returns a pollable which becomes ready when either the trailers have been received, or an error has occurred. When this pollable is ready, -the get method will return some.

          +the get method will return some.

          Params
          • self: borrow<future-trailers>
          • @@ -1370,7 +1373,7 @@ Content-Length.

            [method]future-incoming-response.subscribe: func

            Returns a pollable which becomes ready when either the Response has been received, or an error has occurred. When this pollable is ready, -the get method will return some.

            +the get method will return some.

            Params
            • self: borrow<future-incoming-response>
            • @@ -1512,6 +1515,47 @@ represented as a u64.

              +

              Import interface wasi:config/runtime@0.2.0-draft

              +
              +

              Types

              +

              variant config-error

              +

              An error type that encapsulates the different errors that can occur fetching config

              +
              Variant Cases
              +
                +
              • +

                upstream: string

                +

                This indicates an error from an "upstream" config source. +As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), +the error message is a string. +

              • +
              • +

                io: string

                +

                This indicates an error from an I/O operation. +As this could be almost _anything_ (such as a file read, network connection, etc), +the error message is a string. +Depending on how this ends up being consumed, +we may consider moving this to use the `wasi:io/error` type instead. +For simplicity right now in supporting multiple implementations, it is being left as a string. +

              • +
              +
              +

              Functions

              +

              get: func

              +

              Gets a single opaque config value set at the given key if it exists

              +
              Params
              +
                +
              • key: string
              • +
              +
              Return values
              + +

              get-all: func

              +

              Gets a list of all set config data

              +
              Return values
              +

              Import interface wasi:http/outgoing-handler@0.2.1

              This interface defines a handler of outgoing HTTP Requests. It should be imported by components which wish to make HTTP Requests.

              diff --git a/wit/deps.lock b/wit/deps.lock index a12064a..2a3c02f 100644 --- a/wit/deps.lock +++ b/wit/deps.lock @@ -8,15 +8,20 @@ url = "https://github.com/WebAssembly/wasi-clocks/archive/main.tar.gz" sha256 = "ea9d69ee803bc176e23e5268f5e24a2ac485dd1f62a0ab4c748e9d3f901f576f" sha512 = "5efc22927c46cd56c41e5549ec775561c7fac2ea0d365abc0b55396d9475a7c9f984077a81f84a44a726f1c008fd2fadbffffa4fa53ecd5fbfd05afd379ab428" +[config] +url = "https://github.com/WebAssembly/wasi-runtime-config/archive/main.tar.gz" +sha256 = "9148c06861712b69170af7b8ec37896b4104297d920fdec9f3bcc0b1eee4a5c8" +sha512 = "25a54101620f279c835b39f56f6dbf8a92b374b6faaf6cf6aaa1ea06d8b97b9b79788cf8abd9c2ad0c11e3629dba6a2513b71f2c54b9f95027054ae54a4615b8" + [filesystem] url = "https://github.com/WebAssembly/wasi-filesystem/archive/main.tar.gz" -sha256 = "cfe8c420e8b857de612ae2a3336680dae16b95c93c8ba3a6ff05b21210966740" -sha512 = "3c00c5544a58658e3e8025677091685286027fd49f37abf198c30b4e83b9e68f19723975aaa98794fba9f425ae9ef4f3dc0f5b9cf59203b5ecfaadf62b296f9a" +sha256 = "c8f6224d2c7ac8dd0d0b94f637439226f8010a929abfe6bc7fee52cc325f378b" +sha512 = "90aa55351ca9d7a582e115f3f2cea87f0bd3937d5b115ff00f21ca2c0056d0f3f91fe5c500ca3515bc477b58e10bb5c9c783d7cda8efad23c2466d2a475d8303" [io] url = "https://github.com/WebAssembly/wasi-io/archive/main.tar.gz" -sha256 = "2a74bd811adc46b5a0f19827ddbde89870e52b17615f4d0873f06fd977250caf" -sha512 = "94624f00c66e66203592cee820f80b1ba91ecdb71f682c154f25eaf71f8d8954197dcb64503bc21e72ed5e812af7eae876df47b7eb727b02db3a74a7ce0aefca" +sha256 = "47d2cfaacb3648de9b0b3458e87363d21e28440506036e8f32896129b7512f9b" +sha512 = "594ce1a78fda400de47a45044308472e7ea5f37a8e6a5d2fa28b067a8e2d0954dd84d4b1d764b1c343935bb2b24e89364e82deaa17e97bbb5cbf1667bad1202c" [random] url = "https://github.com/WebAssembly/wasi-random/archive/main.tar.gz" diff --git a/wit/deps.toml b/wit/deps.toml index dd738ac..2a68122 100644 --- a/wit/deps.toml +++ b/wit/deps.toml @@ -5,3 +5,4 @@ clocks = "https://github.com/WebAssembly/wasi-clocks/archive/main.tar.gz" # not used by http/proxy, but included to allow full contents of wasi-cli to validate filesystem = "https://github.com/WebAssembly/wasi-filesystem/archive/main.tar.gz" sockets = "https://github.com/WebAssembly/wasi-sockets/archive/main.tar.gz" +config = "https://github.com/WebAssembly/wasi-runtime-config/archive/main.tar.gz" \ No newline at end of file diff --git a/wit/deps/config/runtime_config.wit b/wit/deps/config/runtime_config.wit new file mode 100644 index 0000000..29d53b1 --- /dev/null +++ b/wit/deps/config/runtime_config.wit @@ -0,0 +1,25 @@ +interface runtime { + /// An error type that encapsulates the different errors that can occur fetching config + variant config-error { + /// This indicates an error from an "upstream" config source. + /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + } + + /// Gets a single opaque config value set at the given key if it exists + get: func( + /// A string key to fetch + key: string + ) -> result, config-error>; + + /// Gets a list of all set config data + get-all: func() -> result>, config-error>; +} diff --git a/wit/deps/config/world.wit b/wit/deps/config/world.wit new file mode 100644 index 0000000..378c4a7 --- /dev/null +++ b/wit/deps/config/world.wit @@ -0,0 +1,6 @@ +package wasi:config@0.2.0-draft; + +world imports { + /// The runtime interface for config + import runtime; +} \ No newline at end of file diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit index db3d968..db3f3c6 100644 --- a/wit/deps/filesystem/types.wit +++ b/wit/deps/filesystem/types.wit @@ -523,12 +523,6 @@ interface types { /// Open a file or directory. /// - /// The returned descriptor is not guaranteed to be the lowest-numbered - /// descriptor not currently open/ it is randomized to prevent applications - /// from depending on making assumptions about indexes, since this is - /// error-prone in multi-threaded contexts. The returned descriptor is - /// guaranteed to be less than 2**31. - /// /// If `flags` contains `descriptor-flags::mutate-directory`, and the base /// descriptor doesn't have `descriptor-flags::mutate-directory` set, /// `open-at` fails with `error-code::read-only`. diff --git a/wit/deps/io/streams.wit b/wit/deps/io/streams.wit index b697e24..72b3ccd 100644 --- a/wit/deps/io/streams.wit +++ b/wit/deps/io/streams.wit @@ -18,6 +18,9 @@ interface streams { /// The last operation (a write or flush) failed before completion. /// /// More information is available in the `error` payload. + /// + /// After this, the stream will be closed. All future operations return + /// `stream-error::closed`. last-operation-failed(error), /// The stream is closed: no more input will be accepted by the /// stream. A closed output-stream will return this error on all @@ -205,6 +208,7 @@ interface streams { /// The created `pollable` is a child resource of the `output-stream`. /// Implementations may trap if the `output-stream` is dropped before /// all derived `pollable`s created with this function are dropped. + @since(version = 0.2.0) subscribe: func() -> pollable; /// Write zeroes to a stream. diff --git a/wit/proxy.wit b/wit/proxy.wit index 415d2ee..036262d 100644 --- a/wit/proxy.wit +++ b/wit/proxy.wit @@ -26,6 +26,11 @@ world imports { @since(version = 0.2.0) import wasi:cli/stdin@0.2.1; + /// HTTP proxies to read runtime configurations such as environment variables, + /// API keys, and other configuration data. + @unstable(feature = config) + import wasi:config/runtime@0.2.0-draft; + /// This is the default handler to use when user code simply wants to make an /// HTTP request (e.g., via `fetch()`). @since(version = 0.2.0)