Skip to content

Tag CRUD

Julien Andrieux requested to merge feature/tag-CRUD into develop

Closes #187 (closed)

messages and handlers to manage tags:

ListTag

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

GetTag

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

CreateTag

$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPOST 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags' -d '{"parent": "organizations/kDtJz8EqQ0C7KgOF6qwxfg","tag": {"display_name": "production","note": "Production purpose","color": "#FF0000"}}' | jq
{
  "name": "tags/cHJvZHVjdGlvbg",
  "display_name": "production",
  "note": "Production purpose",
  "color": "#FF0000"
}

UpdateTag

$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/cHJvZHVjdGlvbg' -d '{"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/cHJvZHVjdGlvbg", "tag": {"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/cHJvZHVjdGlvbg", "display_name": "production","note": "Production purpose","color": "#FFFF00"}, "update_mask": {"paths": ["color"]}}' | jq
{
  "name": "tags/cHJvZHVjdGlvbg",
  "display_name": "production",
  "color": "#FFFF00"
}

Trying to update the display_name of a tag? well, that's absolutely feasible:

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



$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/production' -d '{"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/production", "tag": {"display_name": "produzion"}, "update_mask": {"paths": ["display_name"]}}' | jq
{
  "name": "tags/produzion",
  "display_name": "produzion",
  "note": "Production purpose",
  "color": "#FF0000"
}

Obviously, it detects if you try to change the display_name for an existing one:

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


$ curl -s -H "api-key:f90d9d23-b0cf-410a-b1cc-d0f8678f8b8b" -H "Content-Type: application/json" -XPUT 'http://localhost:7576/v1/organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/production' -d '{"name": "organizations/kDtJz8EqQ0C7KgOF6qwxfg/tags/production", "tag": {"display_name": "produzion"}, "update_mask": {"paths": ["display_name"]}}' | jq
{
  "error": "Couldn't update tag",
  "code": 13
}

and on the server side:

17:16:45.246 [ERRO] UpdateTag: failed to update Tag: duplicate Tag name (handlers_tags.go:215)

DeleteTag

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

Merge request reports