| 140 | } |
| 141 | |
| 142 | func (s *Spec) Validate() error { |
| 143 | if s.ProjectID == "" { |
| 144 | return errors.New("project_id is required") |
| 145 | } |
| 146 | if s.DatasetID == "" { |
| 147 | return errors.New("dataset_id is required") |
| 148 | } |
| 149 | if err := s.TimePartitioning.Validate(); err != nil { |
| 150 | return fmt.Errorf("time_partitioning: %w", err) |
| 151 | } |
| 152 | if s.TimePartitioning == TimePartitioningOptionNone && s.TimePartitioningExpiration.Duration() > 0 { |
| 153 | return errors.New("time_partitioning_expiration option requires time_partitioning to be set") |
| 154 | } |
| 155 | if len(s.ServiceAccountKeyJSON) > 0 { |
| 156 | if err := isValidJson(s.ServiceAccountKeyJSON); err != nil { |
| 157 | return fmt.Errorf("invalid json for service_account_key_json: %w", err) |
| 158 | } |
| 159 | } |
| 160 | if s.TextEmbeddings != nil { |
| 161 | if err := s.TextEmbeddings.Validate(); err != nil { |
| 162 | return fmt.Errorf("text_embeddings: %w", err) |
| 163 | } |
| 164 | } |
| 165 | return nil |
| 166 | } |
| 167 | |
| 168 | func isValidJson(content string) error { |
| 169 | var v map[string]any |