Skip to content

Commit 940d9d3

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 5cda05e + 45157c6 commit 940d9d3

File tree

16 files changed

+221
-241
lines changed

16 files changed

+221
-241
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ REGISTRY_HOSTNAME=registry.terraform.io
77
NAMESPACE=mkdev-me
88
NAME=openai
99
BINARY=terraform-provider-${NAME}
10-
VERSION=1.1.2
10+
VERSION=1.2.0-rc.1
1111
OS_ARCH=darwin_arm64
1212

1313
default: install

docs/data-sources/organization_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ description: |-
2222

2323
### Read-Only
2424

25-
- `added_at` (Number) The Unix timestamp when the user was added to the organization
25+
- `created` (Number) The Unix timestamp when the user was added to the organization
2626
- `id` (String) The ID of this resource.
2727
- `name` (String) The name of the user
2828
- `role` (String) The role of the user in the organization (owner, member, or reader)

docs/data-sources/organization_users.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ output "all_users_count" {
4646

4747
Read-Only:
4848

49-
- `added_at` (Number)
49+
- `created` (Number)
5050
- `email` (String)
5151
- `id` (String)
5252
- `name` (String)

docs/data-sources/project.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ output "project_id" {
2828
# Use project data to set variables
2929
locals {
3030
project_active = data.openai_project.production.status == "active"
31-
project_name = data.openai_project.production.name
31+
project_title = data.openai_project.production.title
3232
}
3333
```
3434

@@ -45,17 +45,9 @@ locals {
4545

4646
### Read-Only
4747

48-
- `created_at` (Number) Timestamp when the project was created
48+
- `archived_at` (Number) Timestamp when the project was archived (null if not archived)
49+
- `created` (Number) Timestamp when the project was created
4950
- `id` (String) The ID of this resource.
50-
- `name` (String) The name of the project
51+
- `is_initial` (Boolean) Whether this is the initial project
5152
- `status` (String) The status of the project
52-
- `usage_limits` (List of Object) Usage limits for the project (see [below for nested schema](#nestedatt--usage_limits))
53-
54-
<a id="nestedatt--usage_limits"></a>
55-
### Nested Schema for `usage_limits`
56-
57-
Read-Only:
58-
59-
- `max_monthly_dollars` (Number)
60-
- `max_parallel_requests` (Number)
61-
- `max_tokens` (Number)
53+
- `title` (String) The title of the project

docs/data-sources/projects.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ output "project_count" {
4242

4343
Read-Only:
4444

45-
- `created_at` (Number)
45+
- `archived_at` (Number)
46+
- `created` (Number)
4647
- `id` (String)
47-
- `name` (String)
48+
- `is_initial` (Boolean)
4849
- `status` (String)
50+
- `title` (String)

docs/resources/organization_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resource "openai_organization_user" "organization_users" {
4141

4242
### Read-Only
4343

44-
- `added_at` (Number) The Unix timestamp when the user was added to the organization
44+
- `created` (Number) The Unix timestamp when the user was added to the organization
4545
- `email` (String) The email address of the user
4646
- `id` (String) The ID of this resource.
4747
- `name` (String) The name of the user

docs/resources/project.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ description: |-
1515
```terraform
1616
# Create a new OpenAI project
1717
resource "openai_project" "development" {
18-
name = "Development Project"
19-
description = "Project for development and testing purposes"
18+
title = "Development Project"
2019
}
2120
2221
# Create a production project
2322
resource "openai_project" "production" {
24-
name = "Production API Services"
25-
description = "Project for production API services and deployments"
23+
title = "Production API Services"
2624
}
2725
2826
# Output the project ID
@@ -37,18 +35,18 @@ output "dev_project_id" {
3735

3836
### Required
3937

40-
- `name` (String) The name of the project
38+
- `title` (String) The title of the project
4139

4240
### Optional
4341

44-
- `description` (String) A description of the project
4542
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
4643

4744
### Read-Only
4845

49-
- `archived_at` (String) Timestamp when the project was archived, if applicable
50-
- `created_at` (String) Timestamp when the project was created
46+
- `archived_at` (Number) Timestamp when the project was archived, if applicable
47+
- `created` (Number) Timestamp when the project was created
5148
- `id` (String) The ID of this resource.
49+
- `is_initial` (Boolean) Whether this is the initial project
5250
- `status` (String) Status of the project (active, archived, etc.)
5351

5452
<a id="nestedblock--timeouts"></a>

examples/data-sources/openai_project/data-source.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ output "project_id" {
1313
# Use project data to set variables
1414
locals {
1515
project_active = data.openai_project.production.status == "active"
16-
project_name = data.openai_project.production.name
16+
project_title = data.openai_project.production.title
1717
}

examples/resources/openai_project/resource.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Create a new OpenAI project
22
resource "openai_project" "development" {
3-
name = "Development Project"
4-
description = "Project for development and testing purposes"
3+
title = "Development Project"
54
}
65

76
# Create a production project
87
resource "openai_project" "production" {
9-
name = "Production API Services"
10-
description = "Project for production API services and deployments"
8+
title = "Production API Services"
119
}
1210

1311
# Output the project ID

internal/client/client.go

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@ func (c *OpenAIClient) SetTimeout(timeout time.Duration) {
141141

142142
// Project represents a project in OpenAI
143143
type Project struct {
144-
Object string `json:"object"`
145-
ID string `json:"id"`
146-
Name string `json:"name"`
147-
Description string `json:"description,omitempty"`
148-
OrganizationID string `json:"organization_id,omitempty"`
149-
CreatedAt *int64 `json:"created_at"`
150-
ArchivedAt *int64 `json:"archived_at"`
151-
Status string `json:"status"`
152-
IsDefault bool `json:"is_default,omitempty"`
153-
BillingMode string `json:"billing_mode,omitempty"`
154-
APIKeys []APIKey `json:"api_keys,omitempty"`
155-
RateLimits []RateLimit `json:"rate_limits,omitempty"`
156-
Users []ProjectUser `json:"users,omitempty"`
144+
ID string `json:"id"`
145+
Object string `json:"object"`
146+
Created int64 `json:"created"`
147+
Status string `json:"status"`
148+
ArchivedAt *int64 `json:"archived_at"`
149+
IsInitial bool `json:"is_initial"`
150+
Title string `json:"title"`
157151
}
158152

159153
// ProjectUser represents a user associated with a project
@@ -197,9 +191,7 @@ type APIKey struct {
197191

198192
// CreateProjectRequest represents the request to create a project
199193
type CreateProjectRequest struct {
200-
Name string `json:"name"`
201-
Description string `json:"description,omitempty"`
202-
IsDefault bool `json:"is_default,omitempty"`
194+
Title string `json:"title"`
203195
}
204196

205197
// Error represents an error from the OpenAI API
@@ -567,23 +559,64 @@ type AssistantFunction struct {
567559
Parameters json.RawMessage `json:"parameters"`
568560
}
569561

570-
// User represents an OpenAI user
562+
// UserInfo represents the nested user details in an organization user response
563+
type UserInfo struct {
564+
ID string `json:"id"`
565+
Object string `json:"object"`
566+
Email string `json:"email"`
567+
Name string `json:"name"`
568+
}
569+
570+
// OrganizationUser represents an OpenAI organization user as returned by the API
571+
type OrganizationUser struct {
572+
Object string `json:"object"`
573+
Created int64 `json:"created"`
574+
IsDefault bool `json:"is_default"`
575+
IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
576+
IsScimManaged bool `json:"is_scim_managed"`
577+
IsServiceAccount bool `json:"is_service_account"`
578+
Role string `json:"role"`
579+
User UserInfo `json:"user"`
580+
}
581+
582+
// User provides a flattened view of OrganizationUser for easier access
583+
// This is a convenience wrapper used internally
571584
type User struct {
572-
ID string `json:"id"`
573-
Object string `json:"object"`
574-
Email string `json:"email"`
575-
Name string `json:"name"`
576-
Role string `json:"role"`
577-
AddedAt int64 `json:"added_at"`
585+
ID string `json:"id"`
586+
Object string `json:"object"`
587+
Email string `json:"email"`
588+
Name string `json:"name"`
589+
Role string `json:"role"`
590+
Created int64 `json:"created"`
591+
IsDefault bool `json:"is_default"`
592+
IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
593+
IsScimManaged bool `json:"is_scim_managed"`
594+
IsServiceAccount bool `json:"is_service_account"`
595+
}
596+
597+
// ToUser converts an OrganizationUser to a flattened User struct
598+
func (ou *OrganizationUser) ToUser() *User {
599+
return &User{
600+
ID: ou.User.ID,
601+
Object: ou.Object,
602+
Email: ou.User.Email,
603+
Name: ou.User.Name,
604+
Role: ou.Role,
605+
Created: ou.Created,
606+
IsDefault: ou.IsDefault,
607+
IsScaleTierAuthorizedPurchaser: ou.IsScaleTierAuthorizedPurchaser,
608+
IsScimManaged: ou.IsScimManaged,
609+
IsServiceAccount: ou.IsServiceAccount,
610+
}
578611
}
579612

580613
// UsersResponse represents the response from the list users API
581614
type UsersResponse struct {
582-
Object string `json:"object"`
583-
Data []User `json:"data"`
584-
FirstID string `json:"first_id"`
585-
LastID string `json:"last_id"`
586-
HasMore bool `json:"has_more"`
615+
Object string `json:"object"`
616+
Data []OrganizationUser `json:"data"`
617+
FirstID string `json:"first_id"`
618+
LastID string `json:"last_id"`
619+
HasMore bool `json:"has_more"`
587620
}
588621

589622
// ListUsers retrieves a list of users in the organization
@@ -660,12 +693,13 @@ func (c *OpenAIClient) FindUserByEmail(email string) (*User, bool, error) {
660693
return nil, false, nil
661694
}
662695

663-
// Return the first matching user
664-
user := usersResponse.Data[0]
696+
// Return the first matching user (convert from OrganizationUser to User)
697+
orgUser := usersResponse.Data[0]
698+
user := orgUser.ToUser()
665699

666700
// Double check that the email matches exactly (case insensitive)
667701
if strings.EqualFold(user.Email, email) {
668-
return &user, true, nil
702+
return user, true, nil
669703
}
670704

671705
// No exact match found
@@ -691,13 +725,14 @@ func (c *OpenAIClient) GetUser(userID string) (*User, bool, error) {
691725
return nil, false, fmt.Errorf("error getting user: %w", err)
692726
}
693727

694-
// Parse the response
695-
var user User
696-
if err := json.Unmarshal(respBody, &user); err != nil {
728+
// Parse the response into OrganizationUser (new API format)
729+
var orgUser OrganizationUser
730+
if err := json.Unmarshal(respBody, &orgUser); err != nil {
697731
return nil, false, fmt.Errorf("error decoding user response: %w", err)
698732
}
699733

700-
return &user, true, nil
734+
// Convert to flattened User struct
735+
return orgUser.ToUser(), true, nil
701736
}
702737

703738
// UpdateUserRole updates a user's role
@@ -719,13 +754,14 @@ func (c *OpenAIClient) UpdateUserRole(userID string, role string) (*User, error)
719754
return nil, fmt.Errorf("error updating user role: %w", err)
720755
}
721756

722-
// Parse the response
723-
var user User
724-
if err := json.Unmarshal(respBody, &user); err != nil {
757+
// Parse the response into OrganizationUser (new API format)
758+
var orgUser OrganizationUser
759+
if err := json.Unmarshal(respBody, &orgUser); err != nil {
725760
return nil, fmt.Errorf("error decoding user response: %w", err)
726761
}
727762

728-
return &user, nil
763+
// Convert to flattened User struct
764+
return orgUser.ToUser(), nil
729765
}
730766

731767
// DeleteUser removes a user from the organization
@@ -1075,25 +1111,15 @@ func (c *OpenAIClient) ListProjects(limit int, includeArchived bool, after strin
10751111
return &resp, nil
10761112
}
10771113

1078-
// CreateProject creates a new project with the given name and description
1079-
func (c *OpenAIClient) CreateProject(name, description string, isDefault bool) (*Project, error) {
1114+
// CreateProject creates a new project with the given title
1115+
func (c *OpenAIClient) CreateProject(title string) (*Project, error) {
10801116
// Create the request body
10811117
requestBody := map[string]interface{}{
1082-
"name": name,
1083-
}
1084-
1085-
// Only include description if it's not empty
1086-
if description != "" {
1087-
requestBody["description"] = description
1088-
}
1089-
1090-
// Only include is_default if it's true (don't send false)
1091-
if isDefault {
1092-
requestBody["is_default"] = isDefault
1118+
"title": title,
10931119
}
10941120

10951121
// Debug information
1096-
fmt.Printf("Creating project with name: %s\n", name)
1122+
fmt.Printf("Creating project with title: %s\n", title)
10971123
fmt.Printf("Request body: %+v\n", requestBody)
10981124

10991125
// Use the exact endpoint from the curl command that works
@@ -1140,21 +1166,11 @@ func (c *OpenAIClient) GetProject(id string) (*Project, error) {
11401166
return &project, nil
11411167
}
11421168

1143-
// UpdateProject updates an existing project with the given details
1144-
func (c *OpenAIClient) UpdateProject(id, name, description string, isDefault bool) (*Project, error) {
1169+
// UpdateProject updates an existing project with the given title
1170+
func (c *OpenAIClient) UpdateProject(id, title string) (*Project, error) {
11451171
// Create the request body
11461172
requestBody := map[string]interface{}{
1147-
"name": name,
1148-
}
1149-
1150-
// Only include description if it's not empty
1151-
if description != "" {
1152-
requestBody["description"] = description
1153-
}
1154-
1155-
// Only include is_default if it's true (don't send false)
1156-
if isDefault {
1157-
requestBody["is_default"] = isDefault
1173+
"title": title,
11581174
}
11591175

11601176
// Use the exact endpoint structure consistent with the curl command

0 commit comments

Comments
 (0)