From fa281110b93751c7e632a6f4cee6fa392875b549 Mon Sep 17 00:00:00 2001 From: Oliver Zheng Date: Fri, 19 Apr 2024 14:55:41 -0700 Subject: [PATCH 1/2] Add `domains_data` to Organization API and deprecate `domains` --- pkg/organizations/client.go | 26 ++++++++++++- pkg/organizations/client_test.go | 65 +++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/pkg/organizations/client.go b/pkg/organizations/client.go index 80d23460..7cbe477b 100644 --- a/pkg/organizations/client.go +++ b/pkg/organizations/client.go @@ -125,6 +125,22 @@ type ListOrganizationsResponse struct { ListMetadata common.ListMetadata `json:"listMetadata"` } +type OrganizationDomainDataState string + +const ( + Verified OrganizationDomainDataState = "verified" + Pending OrganizationDomainDataState = "pending" +) + +// OrganizationDomainData contains data used to create OrganizationDomain +type OrganizationDomainData struct { + // The domain value + Domain string `json:"domain"` + + // The domain state + State OrganizationDomainDataState `json:"state"` +} + // CreateOrganizationOpts contains the options to create an Organization. type CreateOrganizationOpts struct { // Name of the Organization. @@ -134,9 +150,12 @@ type CreateOrganizationOpts struct { // outside of the Organization's configured User Email Domains. AllowProfilesOutsideOrganization bool `json:"allow_profiles_outside_organization"` - // Domains of the Organization. + // [Deprecated] Domains of the Organization. Use DomainData instead. Domains []string `json:"domains"` + // Domains of the Organization. + DomainData []OrganizationDomainData `json:"domain_data"` + // Optional unique identifier to ensure idempotency IdempotencyKey string `json:"idempotency_iey,omitempty"` } @@ -153,8 +172,11 @@ type UpdateOrganizationOpts struct { // outside of the Organization's configured User Email Domains. AllowProfilesOutsideOrganization bool - // Domains of the Organization. + // [Deprecated] Domains of the Organization. Use DomainData instead. Domains []string + + // Domains of the Organization. + DomainData []OrganizationDomainData `json:"domain_data"` } // GetOrganization gets an Organization. diff --git a/pkg/organizations/client_test.go b/pkg/organizations/client_test.go index 8dd4e9ce..a8e66d0c 100644 --- a/pkg/organizations/client_test.go +++ b/pkg/organizations/client_test.go @@ -216,7 +216,7 @@ func TestCreateOrganization(t *testing.T) { err: true, }, { - scenario: "Request returns Organization", + scenario: "Request returns Organization with Domains", client: &Client{ APIKey: "test", }, @@ -236,6 +236,32 @@ func TestCreateOrganization(t *testing.T) { }, }, }, + { + scenario: "Request returns Organization with DomainData", + client: &Client{ + APIKey: "test", + }, + options: CreateOrganizationOpts{ + Name: "Foo Corp", + DomainData: []OrganizationDomainData{ + OrganizationDomainData{ + Domain: "foo-corp.com", + State: "verified", + }, + }, + }, + expected: Organization{ + ID: "organization_id", + Name: "Foo Corp", + AllowProfilesOutsideOrganization: false, + Domains: []OrganizationDomain{ + OrganizationDomain{ + ID: "organization_domain_id", + Domain: "foo-corp.com", + }, + }, + }, + }, { scenario: "Request with duplicate Organization Domain returns error", client: &Client{ @@ -350,7 +376,7 @@ func TestUpdateOrganization(t *testing.T) { err: true, }, { - scenario: "Request returns Organization", + scenario: "Request returns Organization with Domains", client: &Client{ APIKey: "test", }, @@ -375,6 +401,41 @@ func TestUpdateOrganization(t *testing.T) { }, }, }, + { + scenario: "Request returns Organization with DomainData", + client: &Client{ + APIKey: "test", + }, + options: UpdateOrganizationOpts{ + Organization: "organization_id", + Name: "Foo Corp", + DomainData: []OrganizationDomainData{ + OrganizationDomainData{ + Domain: "foo-corp.com", + State: "verified", + }, + OrganizationDomainData{ + Domain: "foo-corp.io", + State: "verified", + }, + }, + }, + expected: Organization{ + ID: "organization_id", + Name: "Foo Corp", + AllowProfilesOutsideOrganization: false, + Domains: []OrganizationDomain{ + OrganizationDomain{ + ID: "organization_domain_id", + Domain: "foo-corp.com", + }, + OrganizationDomain{ + ID: "organization_domain_id_2", + Domain: "foo-corp.io", + }, + }, + }, + }, { scenario: "Request with duplicate Organization Domain returns error", client: &Client{ From 26b01abc863b63f424dfd35680437189e0182853 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Mon, 29 Apr 2024 12:25:56 -0700 Subject: [PATCH 2/2] Updates to godoc comments --- pkg/organizations/client.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/organizations/client.go b/pkg/organizations/client.go index 23026791..73cdf6ff 100644 --- a/pkg/organizations/client.go +++ b/pkg/organizations/client.go @@ -132,12 +132,12 @@ const ( Pending OrganizationDomainDataState = "pending" ) -// OrganizationDomainData contains data used to create OrganizationDomain +// OrganizationDomainData contains data used to create an OrganizationDomain. type OrganizationDomainData struct { - // The domain value + // The domain's value. Domain string `json:"domain"` - // The domain state + // The domain's state. State OrganizationDomainDataState `json:"state"` } @@ -150,7 +150,9 @@ type CreateOrganizationOpts struct { // outside of the Organization's configured User Email Domains. AllowProfilesOutsideOrganization bool `json:"allow_profiles_outside_organization"` - // [Deprecated] Domains of the Organization. Use DomainData instead. + // Domains of the Organization. + // + // Deprecated: Use DomainData instead. Domains []string `json:"domains"` // Domains of the Organization. @@ -172,7 +174,9 @@ type UpdateOrganizationOpts struct { // outside of the Organization's configured User Email Domains. AllowProfilesOutsideOrganization bool - // [Deprecated] Domains of the Organization. Use DomainData instead. + // Domains of the Organization. + // + // Deprecated: Use DomainData instead. Domains []string // Domains of the Organization.