//native
type Zuplo = {
apiKey: string
}
/**
* Updates an API key
* Updates an API key for this consumer.
*/
export async function main(
auth: Zuplo,
accountName: string,
bucketName: string,
consumerName: string,
keyId: string,
tag: string | undefined,
body: { expiresOn?: string; description?: string; key?: string }
) {
const url = new URL(
`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/keys/${keyId}`
)
for (const [k, v] of [['tag', tag]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago