@@ -55,14 +55,7 @@ func (a ReposAPI) Create(r reposCreateRequest) (ReposInformation, error) {
5555 return resp , fmt .Errorf ("git_provider isn't specified and we can't detect provider from URL" )
5656 }
5757 if r .Path != "" {
58- if ! strings .HasPrefix (r .Path , "/Repos/" ) {
59- return resp , fmt .Errorf ("path should start with /Repos/" )
60- }
61- p := r .Path
62- if strings .HasSuffix (r .Path , "/" ) {
63- p = strings .TrimSuffix (r .Path , "/" )
64- }
65- p = path .Dir (p )
58+ p := path .Dir (strings .TrimSuffix (r .Path , "/" ))
6659 if err := workspace .NewNotebooksAPI (a .context , a .client ).Mkdirs (p ); err != nil {
6760 return resp , err
6861 }
@@ -151,6 +144,23 @@ func GetGitProviderFromUrl(uri string) string {
151144 return provider
152145}
153146
147+ func validatePath (i interface {}, k string ) (_ []string , errors []error ) {
148+ v := i .(string )
149+ if v != "" {
150+ if ! strings .HasPrefix (v , "/Repos/" ) {
151+ errors = append (errors , fmt .Errorf ("should start with /Repos/, got '%s'" , v ))
152+ return
153+ }
154+ v = strings .TrimSuffix (v , "/" )
155+ parts := strings .Split (v , "/" )
156+ if len (parts ) != 4 { // we require 3 path parts + starting /
157+ errors = append (errors , fmt .Errorf ("should have 3 components (/Repos/<directory>/<repo>), got %d" , len (parts )- 1 ))
158+ return
159+ }
160+ }
161+ return
162+ }
163+
154164func ResourceRepo () * schema.Resource {
155165 s := common .StructToSchema (ReposInformation {}, func (s map [string ]* schema.Schema ) map [string ]* schema.Schema {
156166 s ["url" ].ValidateFunc = validation .IsURLWithScheme ([]string {"https" , "http" })
@@ -159,6 +169,7 @@ func ResourceRepo() *schema.Resource {
159169 }
160170 s ["branch" ].ConflictsWith = []string {"tag" }
161171 s ["branch" ].ValidateFunc = validation .StringIsNotWhiteSpace
172+ s ["path" ].ValidateFunc = validatePath
162173
163174 s ["tag" ] = & schema.Schema {
164175 Type : schema .TypeString ,
0 commit comments