Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit aa26f6e

Browse files
authored
OPAClient: rename 'authorize' -> 'evaluate' (#51)
Signed-off-by: Stephan Renatus <stephan@styra.com>
1 parent b514377 commit aa26f6e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/opaclient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export class OPAClient {
5656
this.opa = new Opa(sdk);
5757
}
5858

59-
/** `authorize` is used to evaluate the policy at the specified.
59+
/** `evaluate` is used to evaluate the policy at the specified.
6060
*
6161
* @param path - The path to the policy, without `/v1/data`: use `authz/allow` to evaluate policy `data.authz.allow`.
6262
* @param input - The input to the policy, if needed.
6363
* @param fromResult - A function that is used to transform the policy evaluation result (which could be `undefined`).
6464
*/
65-
async authorize<In extends Input | ToInput, Res>(
65+
async evaluate<In extends Input | ToInput, Res>(
6666
path: string,
6767
input?: In,
6868
fromResult?: (res?: Result) => Res,

tests/authorizer.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ allow if {
8080
});
8181

8282
it("can be called without types, without input", async () => {
83-
const res = await new OPAClient(serverURL).authorize("test/p_bool");
83+
const res = await new OPAClient(serverURL).evaluate("test/p_bool");
8484
assert.strictEqual(res, true);
8585
});
8686

8787
it("can be called with input==false", async () => {
88-
const res = await new OPAClient(serverURL).authorize(
88+
const res = await new OPAClient(serverURL).evaluate(
8989
"test/p_bool_false",
9090
false,
9191
);
9292
assert.strictEqual(res, true);
9393
});
9494

9595
it("supports rules with slashes", async () => {
96-
const res = await new OPAClient(serverURL).authorize(
96+
const res = await new OPAClient(serverURL).evaluate(
9797
"has/weird%2fpackage/but/it_is",
9898
);
9999
assert.strictEqual(res, true);
@@ -108,7 +108,7 @@ allow if {
108108
foo: string;
109109
}
110110
const inp: myInput = { name: "alice", list: [1, 2, true] };
111-
const res = await new OPAClient(serverURL).authorize<myInput, myResult>(
111+
const res = await new OPAClient(serverURL).evaluate<myInput, myResult>(
112112
"test/compound_input",
113113
inp,
114114
);
@@ -120,7 +120,7 @@ allow if {
120120
type: string;
121121
}
122122
const inp = true;
123-
const res = await new OPAClient(serverURL).authorize<boolean, typeResult>(
123+
const res = await new OPAClient(serverURL).evaluate<boolean, typeResult>(
124124
"test/has_type",
125125
inp,
126126
);
@@ -143,7 +143,7 @@ allow if {
143143
interface myResult {
144144
foo: string;
145145
}
146-
const res = await new OPAClient(serverURL).authorize<A, myResult>(
146+
const res = await new OPAClient(serverURL).evaluate<A, myResult>(
147147
"test/compound_input",
148148
inp,
149149
);
@@ -170,15 +170,15 @@ allow if {
170170
interface myResult {
171171
foo: string;
172172
}
173-
const res = await new OPAClient(serverURL).authorize<A, myResult>(
173+
const res = await new OPAClient(serverURL).evaluate<A, myResult>(
174174
"test/compound_input",
175175
inp,
176176
);
177177
assert.deepStrictEqual(res, { foo: "bar" });
178178
});
179179

180180
it("supports result class implementing FromResult", async () => {
181-
const res = await new OPAClient(serverURL).authorize<any, boolean>(
181+
const res = await new OPAClient(serverURL).evaluate<any, boolean>(
182182
"test/compound_result",
183183
undefined, // input
184184
(r?: Result) => (r as Record<string, any>)["allowed"] ?? false,
@@ -195,7 +195,7 @@ allow if {
195195
});
196196
const res = await new OPAClient(serverURL, {
197197
sdk: { httpClient },
198-
}).authorize("test/p_bool");
198+
}).evaluate("test/p_bool");
199199
assert.strictEqual(res, true);
200200
assert.strictEqual(called, true);
201201
});
@@ -204,7 +204,7 @@ allow if {
204204
const authorization = "Bearer opensesame";
205205
const res = await new OPAClient(serverURL, {
206206
headers: { authorization },
207-
}).authorize("token/p");
207+
}).evaluate("token/p");
208208
assert.strictEqual(res, true);
209209
});
210210

0 commit comments

Comments
 (0)