Skip to content

Commit f2a56f9

Browse files
authored
Merge pull request #137 from patientsknowbest/feature/PHR-15489-fix-broken-update-put-calls
Add back ids into updating PUT calls PHR-15489
2 parents 99781ac + 19e540f commit f2a56f9

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

aidbox/api_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (apiClient *ApiClient) getResource(ctx context.Context, id string, response
4646
}
4747

4848
func (apiClient *ApiClient) updateResource(ctx context.Context, resource Resource, responseTarget any) error {
49-
return apiClient.put(ctx, resource, path.Join("/", resource.GetResourcePath()), responseTarget)
49+
return apiClient.put(ctx, resource, path.Join("/", resource.GetResourcePath(), "/", resource.GetID()), responseTarget)
5050
}
5151

5252
func (apiClient *ApiClient) deleteResource(ctx context.Context, id string, responseTarget Resource) error {

aidbox/identity_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type IdentityProvider struct {
2424
}
2525

2626
func (g *IdentityProvider) GetResourcePath() string {
27-
return "IdentityProvider/" + g.ID
27+
return "IdentityProvider"
2828
}
2929

3030
type IdentityProviderUserinfoSource int

internal/provider/resource_access_policy_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ func TestAccResourceAccessPolicy_allow(t *testing.T) {
3636
})
3737
}
3838

39+
func TestAccResourceAccessPolicy_schema_updated(t *testing.T) {
40+
resource.Test(t, resource.TestCase{
41+
PreCheck: func() { testAccPreCheck(t) },
42+
ProviderFactories: testProviderFactories,
43+
Steps: []resource.TestStep{
44+
{
45+
Config: testAccResourceAccessPolicy_schema,
46+
Check: resource.ComposeTestCheckFunc(
47+
resource.TestCheckResourceAttr("aidbox_access_policy.example", "schema", "{\"required\":[\"client\",\"uri\",\"request-method\"],\"properties\":{\"uri\":{\"type\":\"string\",\"pattern\":\"^/fhir/.*\"},\"client\":{\"required\":[\"id\"],\"properties\":{\"id\":{\"const\":\"postman\"}}},\"request-method\":{\"const\":\"get\"}}}"),
48+
),
49+
},
50+
{
51+
Config: testAccResourceAccessPolicy_schema_updated,
52+
Check: resource.ComposeTestCheckFunc(
53+
resource.TestCheckResourceAttr("aidbox_access_policy.example", "schema", "{\"required\":[\"client\",\"uri\",\"request-method\"],\"properties\":{\"uri\":{\"type\":\"string\",\"pattern\":\"^/(fhir|ValueSet)(/.*|$)\"},\"client\":{\"required\":[\"id\"],\"properties\":{\"id\":{\"const\":\"postman\"}}},\"request-method\":{\"const\":\"get\"}}}"),
54+
),
55+
},
56+
},
57+
})
58+
}
59+
3960
const testAccResourceAccessPolicy_schema = `
4061
resource "aidbox_access_policy" "example" {
4162
description = "A policy to allow postman to access data"
@@ -69,6 +90,39 @@ resource "aidbox_access_policy" "example" {
6990
}
7091
`
7192

93+
const testAccResourceAccessPolicy_schema_updated = `
94+
resource "aidbox_access_policy" "example" {
95+
description = "A policy to allow postman to access data"
96+
engine = "json-schema"
97+
# The test complains about whitespace differences after application when using jsonencode.
98+
# For practical purposes, jsonencode is much easier to read, so you should use that.
99+
schema = "{\"required\":[\"client\",\"uri\",\"request-method\"],\"properties\":{\"uri\":{\"type\":\"string\",\"pattern\":\"^/(fhir|ValueSet)(/.*|$)\"},\"client\":{\"required\":[\"id\"],\"properties\":{\"id\":{\"const\":\"postman\"}}},\"request-method\":{\"const\":\"get\"}}}"
100+
#schema = jsonencode({
101+
# "required" = [
102+
# "client",
103+
# "uri",
104+
# "request-method" ]
105+
# "properties" = {
106+
# "uri" = {
107+
# "type" = "string"
108+
# "pattern" = "^/(fhir|ValueSet)(/.*|$)"
109+
# }
110+
# "client" = {
111+
# "required" = ["id"]
112+
# "properties" = {
113+
# "id" = {
114+
# const = "postman"
115+
# }
116+
# }
117+
# }
118+
# "request-method" = {
119+
# "const" = "get"
120+
# }
121+
# }
122+
#})
123+
}
124+
`
125+
72126
const testAccResourceAccessPolicy_allow = `
73127
resource "aidbox_client" "client" {
74128
name = "client-id"

0 commit comments

Comments
 (0)