diff --git a/zitadel/v2/helper/form.go b/zitadel/v2/helper/form.go index 0d96f832..d90cb536 100644 --- a/zitadel/v2/helper/form.go +++ b/zitadel/v2/helper/form.go @@ -60,29 +60,21 @@ func createMultipartRequest(issuer, endpoint, path string) (*http.Request, error } func InstanceFormFilePost(clientInfo *ClientInfo, endpoint, path string) diag.Diagnostics { - r, err := createMultipartRequest(clientInfo.Issuer, endpoint, path) - if err != nil { - return diag.Errorf("failed to create asset request: %v", err) - } - - client, err := NewClientWithInterceptor(clientInfo.Issuer, clientInfo.KeyPath, []string{oidc.ScopeOpenID, zitadel.ScopeZitadelAPI()}) - if err != nil { - return diag.Errorf("failed to create client: %v", err) - } + return formFilePost(clientInfo, endpoint, path, map[string]string{}) +} - resp, err := client.Do(r) - if err != nil || resp.StatusCode != http.StatusOK { - return diag.Errorf("failed to do asset request: %v", err) - } - return nil +func OrgFormFilePost(clientInfo *ClientInfo, endpoint, path, orgID string) diag.Diagnostics { + return formFilePost(clientInfo, endpoint, path, map[string]string{"x-zitadel-orgid": orgID}) } -func OrgFormFilePost(clientInfo *ClientInfo, endpoint, orgID, path string) diag.Diagnostics { +func formFilePost(clientInfo *ClientInfo, endpoint, path string, additionalHeaders map[string]string) diag.Diagnostics { r, err := createMultipartRequest(clientInfo.Issuer, endpoint, path) if err != nil { return diag.Errorf("failed to create asset request: %v", err) } - r.Header.Add("x-zitadel-orgid", orgID) + for k, v := range additionalHeaders { + r.Header.Add(k, v) + } client, err := NewClientWithInterceptor(clientInfo.Issuer, clientInfo.KeyPath, []string{oidc.ScopeOpenID, zitadel.ScopeZitadelAPI()}) if err != nil { diff --git a/zitadel/v2/label_policy/funcs.go b/zitadel/v2/label_policy/funcs.go index dbab8338..fbf7fdbe 100644 --- a/zitadel/v2/label_policy/funcs.go +++ b/zitadel/v2/label_policy/funcs.go @@ -77,27 +77,27 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia } if d.HasChanges(logoHashVar, logoPathVar) { - if err := helper.OrgFormFilePost(clientinfo, logoURL, org, d.Get(logoPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, logoURL, d.Get(logoPathVar).(string), org); err != nil { return diag.Errorf("failed to upload logo: %v", err) } } if d.HasChanges(logoDarkHashVar, logoDarkPathVar) { - if err := helper.OrgFormFilePost(clientinfo, logoDarkURL, org, d.Get(logoDarkPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, logoDarkURL, d.Get(logoDarkPathVar).(string), org); err != nil { return diag.Errorf("failed to upload logo dark: %v", err) } } if d.HasChanges(iconHashVar, iconPathVar) { - if err := helper.OrgFormFilePost(clientinfo, iconURL, org, d.Get(iconPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, iconURL, d.Get(iconPathVar).(string), org); err != nil { return diag.Errorf("failed to upload icon: %v", err) } } if d.HasChanges(iconDarkHashVar, iconDarkPathVar) { - if err := helper.OrgFormFilePost(clientinfo, iconDarkURL, org, d.Get(iconDarkPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, iconDarkURL, d.Get(iconDarkPathVar).(string), org); err != nil { return diag.Errorf("failed to upload icon dark: %v", err) } } if d.HasChanges(fontHashVar, fontPathVar) { - if err := helper.OrgFormFilePost(clientinfo, fontURL, org, d.Get(fontPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, fontURL, d.Get(fontPathVar).(string), org); err != nil { return diag.Errorf("failed to upload font: %v", err) } } @@ -160,27 +160,27 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia d.SetId(org) if d.Get(logoHashVar) != "" && d.Get(logoPathVar) != "" { - if err := helper.OrgFormFilePost(clientinfo, logoURL, org, d.Get(logoPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, logoURL, d.Get(logoPathVar).(string), org); err != nil { return diag.Errorf("failed to upload logo: %v", err) } } if d.Get(logoDarkHashVar) != "" && d.Get(logoDarkPathVar) != "" { - if err := helper.OrgFormFilePost(clientinfo, logoDarkURL, org, d.Get(logoDarkPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, logoDarkURL, d.Get(logoDarkPathVar).(string), org); err != nil { return diag.Errorf("failed to upload logo dark: %v", err) } } if d.Get(iconHashVar) != "" && d.Get(iconPathVar) != "" { - if err := helper.OrgFormFilePost(clientinfo, iconURL, org, d.Get(iconPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, iconURL, d.Get(iconPathVar).(string), org); err != nil { return diag.Errorf("failed to upload icon: %v", err) } } if d.Get(iconDarkHashVar) != "" && d.Get(iconDarkPathVar) != "" { - if err := helper.OrgFormFilePost(clientinfo, iconDarkURL, org, d.Get(iconDarkPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, iconDarkURL, d.Get(iconDarkPathVar).(string), org); err != nil { return diag.Errorf("failed to upload icon dark: %v", err) } } if d.Get(fontHashVar) != "" && d.Get(fontPathVar) != "" { - if err := helper.OrgFormFilePost(clientinfo, fontURL, org, d.Get(fontPathVar).(string)); err != nil { + if err := helper.OrgFormFilePost(clientinfo, fontURL, d.Get(fontPathVar).(string), org); err != nil { return diag.Errorf("failed to upload font: %v", err) } }