Skip to content

CRUD for targets in API

Julien Andrieux requested to merge feature/198-crud-for-targets-in-api into develop

Closes #198 (closed)

ListTargets

$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XGET 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets' | jq
{
  "targets": [
    {
      "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/MQF0eIJcRZyEBgG_sdLPWA",
      "address": "localhost",
      "tags": [
        {
          "name": "tags/production",
          "display_name": "production",
          "note": "Production server",
          "color": "#0000ff"
        }
      ]
    }
  ],
  "next_page_token": "Jgokb3JnYW5pemF0aW9ucy9rRHRKejhFcVEwQzdLZ09GNnF3eGZnAQ"
}

GetTarget

$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XGET 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/MQF0eIJcRZyEBgG_sdLPWA' | jq
{
  "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/MQF0eIJcRZyEBgG_sdLPWA",
  "address": "localhost",
  "tags": [
    {
      "name": "tags/production",
      "display_name": "production",
      "note": "Production server",
      "color": "#0000ff"
    }
  ]
}

CreateTarget

$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPOST 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets' -d '{"target": {"address": "pantomath.io","note": "Main pantomath server that hosts the website","tags": [{"name": "tags/production"}]}}' | jq
{
  "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA",
  "address": "pantomath.io",
  "note": "Main pantomath server that hosts the website",
  "tags": [
    {
      "name": "tags/production",
      "display_name": "production",
      "note": "Production server",
      "color": "#0000ff"
    }
  ]
}

UpdateTarget

normal call
$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA' -d '{"target": {"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA","address": "www.pantomath.io","note": "Main pantomath server, hosts the website","tags": [{"name": "tags/produzion"}]},"update_mask": {"paths": ["address","note","tags"]}}' | jq
{
  "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA",
  "address": "www.pantomath.io",
  "note": "Main pantomath server, hosts the website",
  "tags": [
    {
      "name": "tags/produzion",
      "display_name": "produzion",
      "note": "Production purpose",
      "color": "#FF0000"
    }
  ]
}
with an existing address
$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA' -d '{"target": {"address": "www.pantomath.io"},"update_mask": {"paths": ["address"]}}' | jq
{
  "error": "Duplicate address.",
  "code": 3
}
```

##### removing all tags

```shell
$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA' -d '{"target": {"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA","address": "www.pantomath.io","note": "Main pantomath server, hosts the website","tags": []},"update_mask": {"paths": ["tags"]}}' | jq
{
  "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA",
  "address": "www.pantomath.io",
  "note": "Main pantomath server, hosts the website"
}
```

#### `DeleteTarget`

```shell
$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XGET 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets' | jq
{
  "targets": [
    {
      "name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA",
      "address": "www.pantomath.io",
      "note": "Main pantomath server, hosts the website"
    }
  ],
  "next_page_token": "Jgokb3JnYW5pemF0aW9ucy9rRHRKejhFcVEwQzdLZ09GNnF3eGZnAQ"
}


$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XDELETE 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets/5tfyoEPkQ-iWOXn5Y42wHA' | jq
{}


$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XGET 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/targets' | jq
{
  "next_page_token": "Jgokb3JnYW5pemF0aW9ucy9rRHRKejhFcVEwQzdLZ09GNnF3eGZnAA"
}
```
Edited by Julien Andrieux

Merge request reports