IsResourceDatabase returns true if the current resource is a database. It returns an ErrResourceNotFound error if no database name has been found.
(ctx context.Context, resourceName string)
| 16 | // IsResourceDatabase returns true if the current resource is a database. It returns |
| 17 | // an ErrResourceNotFound error if no database name has been found. |
| 18 | func IsResourceDatabase(ctx context.Context, resourceName string) (bool, error) { |
| 19 | client, err := config.ScalingoClient(ctx) |
| 20 | if err != nil { |
| 21 | return false, errors.Wrap(ctx, err, "get Scalingo client") |
| 22 | } |
| 23 | |
| 24 | app, err := client.AppsShow(ctx, resourceName) |
| 25 | if err != nil { |
| 26 | debug.Println("[detect] Unable to show app to check if resource is a database:", err) |
| 27 | return false, nil |
| 28 | } |
| 29 | |
| 30 | for f, v := range app.Flags { |
| 31 | if f == databasesResourceFlag && v { |
| 32 | return true, nil |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return false, ErrResourceNotFound |
| 37 | } |
no test coverage detected