Skip to content

Commit

Permalink
Specify config to never change during the lifetime of the component.
Browse files Browse the repository at this point in the history
  • Loading branch information
badeend committed Oct 6, 2024
1 parent f4d699b commit ec018b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 49 deletions.
35 changes: 8 additions & 27 deletions imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,27 @@
</li>
</ul>
<h2><a id="wasi_config_store_0_2_0_draft"></a>Import interface wasi:config/store@0.2.0-draft</h2>
<hr />
<h3>Types</h3>
<h4><a id="error"></a><code>variant error</code></h4>
<p>An error type that encapsulates the different errors that can occur fetching configuration values.</p>
<h5>Variant Cases</h5>
<ul>
<li>
<p><a id="error.upstream"></a><code>upstream</code>: <code>string</code></p>
<p>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.
</li>
<li>
<p><a id="error.io"></a><code>io</code>: <code>string</code></p>
<p>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.
</li>
</ul>
<p>An immutable configuration store.</p>
<hr />
<h3>Functions</h3>
<h4><a id="get"></a><code>get: func</code></h4>
<p>Gets a configuration value of type <code>string</code> associated with the <code>key</code>.</p>
<p>The value is returned as an <code>option&lt;string&gt;</code>. If the key is not found,
<code>Ok(none)</code> is returned. If an error occurs, an <code>Err(error)</code> is returned.</p>
<p>Returns <code>none</code> if the key does not exist.</p>
<p>This always returns the same value for any given key. Configuration
data does not change over the lifetime of the component instance.</p>
<h5>Params</h5>
<ul>
<li><a id="get.key"></a><code>key</code>: <code>string</code></li>
</ul>
<h5>Return values</h5>
<ul>
<li><a id="get.0"></a> result&lt;option&lt;<code>string</code>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
<li><a id="get.0"></a> option&lt;<code>string</code>&gt;</li>
</ul>
<h4><a id="get_all"></a><code>get-all: func</code></h4>
<p>Gets a list of configuration key-value pairs of type <code>string</code>.</p>
<p>If an error occurs, an <code>Err(error)</code> is returned.</p>
<p>This always returns the same data. Configuration data does not change
over the lifetime of the component instance.</p>
<h5>Return values</h5>
<ul>
<li><a id="get_all.0"></a> result&lt;list&lt;(<code>string</code>, <code>string</code>)&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
<li><a id="get_all.0"></a> list&lt;(<code>string</code>, <code>string</code>)&gt;</li>
</ul>
33 changes: 11 additions & 22 deletions wit/store.wit
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
/// An immutable configuration store.
interface store {
/// An error type that encapsulates the different errors that can occur fetching configuration values.
variant 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 configuration value of type `string` associated with the `key`.
///
/// The value is returned as an `option<string>`. If the key is not found,
/// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned.
///
/// Returns `none` if the key does not exist.
///
/// This always returns the same value for any given key. Configuration
/// data does not change over the lifetime of the component instance.
get: func(
/// A string key to fetch
key: string
) -> result<option<string>, error>;
) -> option<string>;

/// Gets a list of configuration key-value pairs of type `string`.
///
/// If an error occurs, an `Err(error)` is returned.
get-all: func() -> result<list<tuple<string, string>>, error>;
///
/// This always returns the same data. Configuration data does not change
/// over the lifetime of the component instance.
get-all: func() -> list<tuple<string, string>>;
}

0 comments on commit ec018b5

Please # to comment.