@@ -2,6 +2,7 @@ package cli
22
33import (
44 "context"
5+ "encoding/json"
56 "errors"
67 "fmt"
78 "net/url"
4748 Name : "Verification Method" ,
4849 LongForm : "verification" ,
4950 ShortForm : "v" ,
50- Help : "Custom domain verification method. Must be 'txt'." ,
51+ Help : "*DEPRECATED* Custom domain verification method. Must be 'txt'." ,
5152 }
5253
5354 customDomainPolicy = Flag {
6667 AlwaysPrompt : true ,
6768 }
6869
70+ customDomainMetadata = Flag {
71+ Name : "Domain Metadata" ,
72+ LongForm : "metadata" ,
73+ ShortForm : "m" ,
74+ Help : "The Custom Domain Metadata, formatted as JSON." ,
75+ AlwaysPrompt : true ,
76+ }
77+
6978 customDomainPolicyOptions = []string {
7079 customDomainTLSPolicyRecommended ,
7180 customDomainTLSPolicyCompatible ,
@@ -177,6 +186,7 @@ func createCustomDomainCmd(cli *cli) *cobra.Command {
177186 VerificationMethod string
178187 TLSPolicy string
179188 CustomClientIPHeader string
189+ DomainMetadata string
180190 }
181191
182192 cmd := & cobra.Command {
@@ -190,13 +200,21 @@ func createCustomDomainCmd(cli *cli) *cobra.Command {
190200 Example : ` auth0 domains create
191201 auth0 domains create --domain <domain-name>
192202 auth0 domains create --domain <domain-name> --policy recommended
203+ auth0 domains create --domain <domain-name> --policy recommended --metadata '{"key1":"value1","key2":"value2"}'
193204 auth0 domains create --domain <domain-name> --policy recommended --type auth0
194205 auth0 domains create --domain <domain-name> --policy recommended --type auth0 --ip-header "cf-connecting-ip"
195206 auth0 domains create -d <domain-name> -p recommended -t auth0 -i "cf-connecting-ip" --json` ,
196207 RunE : func (cmd * cobra.Command , args []string ) error {
197208 if err := customDomainDomain .Ask (cmd , & inputs .Domain , nil ); err != nil {
198209 return err
199210 }
211+ if err := customDomainPolicy .Select (cmd , & inputs .TLSPolicy , customDomainPolicyOptions , auth0 .String (customDomainTLSPolicyRecommended )); err != nil {
212+ return err
213+ }
214+
215+ if err := customDomainMetadata .Ask (cmd , & inputs .DomainMetadata , nil ); err != nil {
216+ return err
217+ }
200218
201219 customDomain := & management.CustomDomain {
202220 Domain : & inputs .Domain ,
@@ -208,10 +226,6 @@ func createCustomDomainCmd(cli *cli) *cobra.Command {
208226 customDomain .Type = auth0 .String (customDomainProvisioningTypeAuth0 )
209227 }
210228
211- if inputs .VerificationMethod != "" {
212- customDomain .VerificationMethod = apiVerificationMethodFor (inputs .VerificationMethod )
213- }
214-
215229 if inputs .TLSPolicy != "" {
216230 customDomain .TLSPolicy = apiTLSPolicyFor (inputs .TLSPolicy )
217231 }
@@ -220,6 +234,14 @@ func createCustomDomainCmd(cli *cli) *cobra.Command {
220234 customDomain .CustomClientIPHeader = & inputs .CustomClientIPHeader
221235 }
222236
237+ if inputs .DomainMetadata != "" {
238+ var metadata map [string ]interface {}
239+ if err := json .Unmarshal ([]byte (inputs .DomainMetadata ), & metadata ); err != nil {
240+ return fmt .Errorf ("invalid JSON for metadata: %w" , err )
241+ }
242+ customDomain .DomainMetadata = & metadata
243+ }
244+
223245 if err := ansi .Waiting (func () error {
224246 return cli .api .CustomDomain .Create (cmd .Context (), customDomain )
225247 }); err != nil {
@@ -238,6 +260,7 @@ func createCustomDomainCmd(cli *cli) *cobra.Command {
238260 customDomainVerification .RegisterString (cmd , & inputs .VerificationMethod , "" )
239261 customDomainPolicy .RegisterString (cmd , & inputs .TLSPolicy , "" )
240262 customDomainIPHeader .RegisterString (cmd , & inputs .CustomClientIPHeader , "" )
263+ customDomainMetadata .RegisterString (cmd , & inputs .DomainMetadata , "" )
241264
242265 return cmd
243266}
@@ -247,6 +270,7 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
247270 ID string
248271 TLSPolicy string
249272 CustomClientIPHeader string
273+ DomainMetadata string
250274 }
251275
252276 cmd := & cobra.Command {
@@ -260,7 +284,9 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
260284 Example : ` auth0 domains update
261285 auth0 domains update <domain-id> --policy compatible
262286 auth0 domains update <domain-id> --policy compatible --ip-header "cf-connecting-ip"
263- auth0 domains update <domain-id> -p compatible -i "cf-connecting-ip" --json` ,
287+ auth0 domains update <domain-id> --metadata '{"key1":"value1","key2":null}'
288+ auth0 domains update <domain-id> -p compatible -i "cf-connecting-ip" --json
289+ ` ,
264290 RunE : func (cmd * cobra.Command , args []string ) error {
265291 var current * management.CustomDomain
266292
@@ -287,6 +313,10 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
287313 return err
288314 }
289315
316+ if err := customDomainMetadata .AskU (cmd , & inputs .DomainMetadata , nil ); err != nil {
317+ return err
318+ }
319+
290320 // Start with an empty custom domain object. We'll conditionally
291321 // hydrate it based on the provided parameters since
292322 // we'll do PATCH semantics.
@@ -300,12 +330,29 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
300330 c .CustomClientIPHeader = & inputs .CustomClientIPHeader
301331 }
302332
333+ if inputs .DomainMetadata != "" {
334+ var metadata map [string ]interface {}
335+ if err := json .Unmarshal ([]byte (inputs .DomainMetadata ), & metadata ); err != nil {
336+ return fmt .Errorf ("invalid JSON for metadata: %w" , err )
337+ }
338+ c .DomainMetadata = & metadata
339+ }
340+
303341 if err := ansi .Waiting (func () error {
304342 return cli .api .CustomDomain .Update (cmd .Context (), inputs .ID , c )
305343 }); err != nil {
306344 return fmt .Errorf ("failed to update custom domain: %w" , err )
307345 }
308346
347+ // AFTER the API call: clean nil values from the map for clean rendering.
348+ if c .DomainMetadata != nil {
349+ for k , v := range * c .DomainMetadata {
350+ if v == nil {
351+ delete (* c .DomainMetadata , k )
352+ }
353+ }
354+ }
355+
309356 cli .renderer .CustomDomainUpdate (c )
310357
311358 return nil
@@ -314,6 +361,7 @@ func updateCustomDomainCmd(cli *cli) *cobra.Command {
314361
315362 customDomainPolicy .RegisterStringU (cmd , & inputs .TLSPolicy , "" )
316363 customDomainIPHeader .RegisterStringU (cmd , & inputs .CustomClientIPHeader , "" )
364+ customDomainMetadata .RegisterString (cmd , & inputs .DomainMetadata , "" )
317365
318366 cmd .Flags ().BoolVar (& cli .json , "json" , false , "Output in json format." )
319367
0 commit comments