# Manage Data Sources

This page details the `immuta datasource` command, its subcommands and arguments, and the workflow for creating, renaming, and deleting data sources.

## Command overview: `immuta datasource`

This command allows you to list, save, delete, and rename data sources in your instance of Immuta. The table below illustrates subcommands and arguments.

| Subcommands    | Description                                                                                                | Argument(s)      |
| -------------- | ---------------------------------------------------------------------------------------------------------- | ---------------- |
| `list keys`    | List all data source connection keys.                                                                      | n/a              |
| `list sources` | List all data sources for a given connection key.                                                          | `connection key` |
| `save`         | Create or update all specified data sources in Immuta given connection information to the remote database. | `filepath`       |
| `delete`       | Delete all data sources for the given connection key.                                                      | `connection key` |
| `rename`       | Rename the data source connection key.                                                                     | `connection key` |

### Options

Use these options to get more details about the `datasource` command or any of its subcommands:

* `-h`
* `--help`

```bash
Manage Data Sources

Usage:
  immuta datasource [command]

Available Commands:
  delete      Delete all datasources for the given connection key
  list        List Data Source keys and sources
  rename      Rename the connection key
  save        Create/Update all specified data sources in Immuta given connection info to the remote data base

Flags:
  -h, --help   help for datasource

Global Flags:
      --config string    config file (default $HOME/.immutacfg.yaml)
  -p, --profile string   specifies the profile for what instance/api the cli will use (default "default")

Use "immuta datasource [command] --help" for more information about a command.
```

## Create a data source: `immuta datasource save`

**Required Immuta permission**: `CREATE_DATA_SOURCE`

1. Add your remote database's connection information in a valid YAML file for the V2 API. Additional payload examples for creating data sources can [be found here](https://documentation.immuta.com/SaaS/developer-guides/api-intro/immuta-v2-api/data-source):

   ```yaml
   connectionKey: 'a connection key'
   connection:
     ssl: true
     port: 5432
     hostname: immuta.db.com
     database: public
     schema: public
     username: user
     password: '{{EnvVar "myPassword"}}'
     handler: Snowflake
   ```
2. Run `immuta datasource save <filepath> [--wait int] [--dryRun]`, referencing the file you just created. The options you can specify include
   * `-d` or `--dryRun`: No updates will actually be made to the data source(s).
   * `-h` or `--help`: Get more information about the command.
   * `-w` or `--wait int`: Specify how long to wait for data source creation.

### Example

The following example illustrates a user saving an updated `datasourceInfo.yaml` file, first as a dry run and then by specifying that the data sources wait 5 seconds to be created.

```bash
$ immuta datasource save test.yml --dryRun
{"dryRun":true,"creating":["Public Credit Accounts","Public Credit Transactions","Public Fake Medical Claims 2017","Public Uciml Census Income Enriched"],"updating":[],"deleting":[],"noChange":[],"detectionRunning":false,"tagsUpdated":false,"connectionString":null}

$ immuta datasource save test.yml --wait 5
{"dryRun":false,"creating":["Public Credit Accounts","Public Credit Transactions","Public Fake Medical Claims 2017","Public Uciml Census Income Enriched"],"updating":[],"deleting":[],"noChange":[],"detectionRunning":false,"tagsUpdated":false,"connectionString":"immuta@snowflake.demo-databases.your.url.com:3306/public"}
```

## Rename a data source connection key: `immuta datasource rename`

**Requirement:** The global `GOVERNANCE` permission or be the data source owner

1. Run `immuta datasource list keys` to view a list of data source connection keys. Options you can specify include
   * `-h` or `--help`: Get more information about the command.
   * `-v` or `--verbose`: Print response as JSON.
2. To rename one of your data source connection keys, run `immuta datasource rename <old connection key> <new connection key>`. You can include the `-h` or `--help` options to get more information about this command.

### Example

The following example illustrates a user renaming a data source connection key to `demonstration`.

```bash
$ immuta datasource list keys
snowflake.demo-databases.your.url.com:3306/public/public

$ immuta datasource rename snowflake.demo-databases.your.url.com:3306/public/public demonstration
{"oldConnectionKey":"snowflake.demo-databases.your.url.com:3306/public/public","newConnectionKey":"demonstration"}

$ immuta datasource list keys
demonstration
```

## Delete data sources: `immuta datasource delete`

**Requirement:** The global `GOVERNANCE` permission or be the data source owner

This command will delete all data sources for the connection key you specify.

1. Run `immuta datasource list keys` to view a list of data source connection keys. Options you can specify include
   * `-h` or `--help`: Get more information about the command.
   * `-v` or `--verbose`: Print response as JSON.
2. Opt to view a list of the data sources in this connection key by running `immuta datasource list sources <connection key>`.
3. Run `immuta datasource delete <connection key> [--dryRun]` to delete all of these data sources. Options you can specify include
   * `-d` or `--dryRun`: No updates will actually be made.
   * `-h` or `--help`: Get more information about the command.

### Example

The following example illustrates a user deleting the `demonstration` connection key and all its data sources.

```bash
$ immuta datasource list keys

demonstration

$ immuta datasource delete demonstration
{"dryRun":false,"deleting":["Public Credit Transactions","Public Credit Accounts","Public Uciml Census Income Enriched","Public Fake Medical Claims 2017"]}

$ immuta datasource list sources demonstration
Error: status code: 404 message: The connection key "demonstration" was not found
```
