func updateAccessControl(client *bigquery.Client, conf Config) error {

	for _, dataset := range conf.Datasets {

		fmt.Println(ansi.Color(fmt.Sprintf("\n\nUpdating accesses for %s:%s", conf.Project, dataset.Name), "blue+b"))

		metaToUpdate := &bigquery.DatasetMetadataToUpdate{}

		generateAccesses(metaToUpdate, dataset.Owner.GroupByEmail, bigquery.OwnerRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Owner.UserByEmail, bigquery.OwnerRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Owner.SpecialGroup, bigquery.OwnerRole, bigquery.SpecialGroupEntity)

		generateAccesses(metaToUpdate, dataset.Writer.GroupByEmail, bigquery.WriterRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Writer.UserByEmail, bigquery.WriterRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Writer.SpecialGroup, bigquery.WriterRole, bigquery.SpecialGroupEntity)

		generateAccesses(metaToUpdate, dataset.Reader.GroupByEmail, bigquery.ReaderRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Reader.UserByEmail, bigquery.ReaderRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Reader.SpecialGroup, bigquery.ReaderRole, bigquery.SpecialGroupEntity)

		generateViews(metaToUpdate, dataset.View, conf.Project)

		ds := client.Dataset(dataset.Name)
		ctx := context.Background()
		meta, err := ds.Metadata(ctx)
		if err != nil {
			return errors.Wrap(err, "cannot get metadata for original dataset")
		}

		// Print the diff
		isDiff := diff(AccessList(meta.Access), AccessList(metaToUpdate.Access))

		if planMode {
			fmt.Println(ansi.Color(fmt.Sprintf("\n\nSkipping update since planMode is set."), "blue+b"))
		} else {
			// Update access
			if isDiff {
				if _, err := ds.Update(ctx, *metaToUpdate, meta.ETag); err != nil {
					return errors.Wrap(err, "cannot update original dataset's metadata")
				}
			}
		}
	}

	return nil
}
// updateAccessControl apply accesses to a dataset according to conf
updateAccessControl apply accesses to a dataset according to conf
// updateAccessControl apply accesses to a dataset according to conf
func updateAccessControl(client *bigquery.Client, conf Config) error {
	for _, dataset := range conf.Datasets {
		fmt.Println(ansi.Color(fmt.Sprintf("\n\nUpdating accesses for %s:%s", conf.Project, dataset.Name), "blue+b"))
		metaToUpdate := &bigquery.DatasetMetadataToUpdate{}
		generateAccesses(metaToUpdate, dataset.Owner.GroupByEmail, bigquery.OwnerRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Owner.UserByEmail, bigquery.OwnerRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Owner.SpecialGroup, bigquery.OwnerRole, bigquery.SpecialGroupEntity)
		generateAccesses(metaToUpdate, dataset.Writer.GroupByEmail, bigquery.WriterRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Writer.UserByEmail, bigquery.WriterRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Writer.SpecialGroup, bigquery.WriterRole, bigquery.SpecialGroupEntity)
		generateAccesses(metaToUpdate, dataset.Reader.GroupByEmail, bigquery.ReaderRole, bigquery.GroupEmailEntity)
		generateAccesses(metaToUpdate, dataset.Reader.UserByEmail, bigquery.ReaderRole, bigquery.UserEmailEntity)
		generateAccesses(metaToUpdate, dataset.Reader.SpecialGroup, bigquery.ReaderRole, bigquery.SpecialGroupEntity)
		generateViews(metaToUpdate, dataset.View, conf.Project)
		ds := client.Dataset(dataset.Name)
		ctx := context.Background()
		meta, err := ds.Metadata(ctx)
		if err != nil {
			return errors.Wrap(err, "cannot get metadata for original dataset")
		}
		isDiff := diff(AccessList(meta.Access), AccessList(metaToUpdate.Access))
		if planMode {
			fmt.Println(ansi.Color(fmt.Sprintf("\n\nSkipping update since planMode is set."), "blue+b"))
		} else {
			if isDiff {
				if _, err := ds.Update(ctx, *metaToUpdate, meta.ETag); err != nil {
					return errors.Wrap(err, "cannot update original dataset's metadata")
				}
			}
		}
	}
	return nil
}
func updateAccessControl ( client * bigquery . Client , conf Config ) error { for _ , dataset := range conf . Datasets { fmt . Println ( ansi . Color ( fmt . Sprintf ( " \n \n " , conf . Project , dataset . Name ) , " " ) ) metaToUpdate := & bigquery . DatasetMetadataToUpdate { } generateAccesses ( metaToUpdate , dataset . Owner . GroupByEmail , bigquery . OwnerRole , bigquery . GroupEmailEntity ) generateAccesses ( metaToUpdate , dataset . Owner . UserByEmail , bigquery . OwnerRole , bigquery . UserEmailEntity ) generateAccesses ( metaToUpdate , dataset . Owner . SpecialGroup , bigquery . OwnerRole , bigquery . SpecialGroupEntity ) generateAccesses ( metaToUpdate , dataset . Writer . GroupByEmail , bigquery . WriterRole , bigquery . GroupEmailEntity ) generateAccesses ( metaToUpdate , dataset . Writer . UserByEmail , bigquery . WriterRole , bigquery . UserEmailEntity ) generateAccesses ( metaToUpdate , dataset . Writer . SpecialGroup , bigquery . WriterRole , bigquery . SpecialGroupEntity ) generateAccesses ( metaToUpdate , dataset . Reader . GroupByEmail , bigquery . ReaderRole , bigquery . GroupEmailEntity ) generateAccesses ( metaToUpdate , dataset . Reader . UserByEmail , bigquery . ReaderRole , bigquery . UserEmailEntity ) generateAccesses ( metaToUpdate , dataset . Reader . SpecialGroup , bigquery . ReaderRole , bigquery . SpecialGroupEntity ) generateViews ( metaToUpdate , dataset . View , conf . Project ) ds := client . Dataset ( dataset . Name ) ctx := context . Background ( ) meta , err := ds . Metadata ( ctx ) if err != nil { return errors . Wrap ( err , " " ) } isDiff := diff ( AccessList ( meta . Access ) , AccessList ( metaToUpdate . Access ) ) if planMode { fmt . Println ( ansi . Color ( fmt . Sprintf ( " \n \n " ) , " " ) ) } else { if isDiff { if _ , err := ds . Update ( ctx , * metaToUpdate , meta . ETag ) ; err != nil { return errors . Wrap ( err , " " ) } } } } return nil }
updateAccessControl apply accesses to a dataset according to conf
updateAccessControl apply accesses to a dataset according to conf
// Print the diff // Update access