From 9c992ef1225a76793ffa7cab590d8c64aa7a358d Mon Sep 17 00:00:00 2001 From: Philipp Heuer Date: Tue, 23 Jul 2024 21:53:39 +0200 Subject: [PATCH] feat: use versioned api endpoints --- go.mod | 26 +-- go.sum | 48 +++--- pkg/cmd/api.go | 15 +- .../containeraction/containerexecutor.go | 2 +- .../containeraction/util_test.go | 15 ++ pkg/core/restapi/openapi.yaml | 157 ++++++++++++------ pkg/core/restapi/serve.go | 53 +++--- 7 files changed, 207 insertions(+), 109 deletions(-) create mode 100644 pkg/core/actionexecutor/containeraction/util_test.go diff --git a/go.mod b/go.mod index b525fcf..a711b59 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cidverse/cid -go 1.21 +go 1.22 require ( github.com/ProtonMail/gopenpgp/v2 v2.7.5 @@ -16,8 +16,8 @@ require ( github.com/cidverse/cidverseutils/zerologconfig v0.1.0 github.com/cidverse/go-rules v0.0.0-20231112122021-075e5e6f8abc github.com/cidverse/go-vcs v0.0.0-20240628195958-27702663f242 - github.com/cidverse/normalizeci v1.1.1-0.20240507162324-423657017129 - github.com/cidverse/repoanalyzer v0.1.1-0.20240510193438-abb053de8c14 + github.com/cidverse/normalizeci v1.1.1-0.20240716145002-cfaf14fb65c4 + github.com/cidverse/repoanalyzer v0.1.1-0.20240704190901-1e2e27d72222 github.com/go-resty/resty/v2 v2.13.1 github.com/google/uuid v1.6.0 github.com/hashicorp/go-version v1.7.0 @@ -28,7 +28,7 @@ require ( github.com/opencontainers/image-spec v1.1.0 github.com/oriser/regroup v0.0.0-20230527212431-1b00c9bdbc5b github.com/rs/zerolog v1.33.0 - github.com/samber/lo v1.44.0 + github.com/samber/lo v1.46.0 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v3 v3.0.1 @@ -42,11 +42,11 @@ require ( github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect - github.com/antlr4-go/antlr/v4 v4.13.0 // indirect - github.com/charlievieth/fastwalk v1.0.6 // indirect + github.com/antlr4-go/antlr/v4 v4.13.1 // indirect + github.com/charlievieth/fastwalk v1.0.8 // indirect github.com/cidverse/cidverseutils/exec v0.1.0 // indirect github.com/cloudflare/circl v1.3.9 // indirect - github.com/cyphar/filepath-securejoin v0.2.5 // indirect + github.com/cyphar/filepath-securejoin v0.3.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/gabriel-vasile/mimetype v1.4.4 // indirect @@ -59,7 +59,7 @@ require ( github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/cel-go v0.20.1 // indirect - github.com/google/go-github/v61 v61.0.0 // indirect + github.com/google/go-github/v63 v63.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/gosimple/slug v1.14.0 // indirect github.com/gosimple/unidecode v1.0.1 // indirect @@ -81,16 +81,16 @@ require ( github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/shibumi/go-pathspec v1.3.0 // indirect - github.com/skeema/knownhosts v1.2.2 // indirect + github.com/skeema/knownhosts v1.3.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - github.com/xanzy/go-gitlab v0.106.0 // indirect + github.com/xanzy/go-gitlab v0.107.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.25.0 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect + golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect golang.org/x/mod v0.19.0 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect @@ -98,8 +98,8 @@ require ( golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index 34d8242..3d693b4 100644 --- a/go.sum +++ b/go.sum @@ -17,15 +17,15 @@ github.com/ProtonMail/gopenpgp/v2 v2.7.5 h1:STOY3vgES59gNgoOt2w0nyHBjKViB/qSg7Nj github.com/ProtonMail/gopenpgp/v2 v2.7.5/go.mod h1:IhkNEDaxec6NyzSI0PlxapinnwPVIESk8/76da3Ct3g= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= -github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= -github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= -github.com/charlievieth/fastwalk v1.0.6 h1:C7nXgxQIjEkpKWT1fbXGFzQiblwqq2ZsxrR0ohh5IRs= -github.com/charlievieth/fastwalk v1.0.6/go.mod h1:rV19+IF9Y2TYQNy4MqEk5M/spNHjKsA0i71yrsv2p4E= +github.com/charlievieth/fastwalk v1.0.8 h1:uaoH6cAKSk73aK7aKXqs0+bL+J3Txzd3NGH8tRXgHko= +github.com/charlievieth/fastwalk v1.0.8/go.mod h1:yGy1zbxog41ZVMcKA/i8ojXLFsuayX5VvwhQVoj9PBI= github.com/cidverse/cidverseutils/ci v0.1.0 h1:vLxi+T3Oj2uJzO8KWLLRUzgEfC8y2hoS14AE9pCr2ew= github.com/cidverse/cidverseutils/ci v0.1.0/go.mod h1:uOMGB2Kh/0HA936tlnzgBvrxv4hmXYeSbJxP383nHKU= github.com/cidverse/cidverseutils/compress v0.1.0 h1:GrCp/50/Ltl3rn/WctHxY6lN+wgoms0qBqYpEbWmiZw= @@ -50,10 +50,10 @@ github.com/cidverse/go-rules v0.0.0-20231112122021-075e5e6f8abc h1:eVuHW4U9Boiqj github.com/cidverse/go-rules v0.0.0-20231112122021-075e5e6f8abc/go.mod h1:1E+4h0XkcYJVq3RHoYQradnCt7wk3JgnuRRnfeiwAzE= github.com/cidverse/go-vcs v0.0.0-20240628195958-27702663f242 h1:WbROpjwLzkYze8lcbFQ8Zga9fC3RxLedss8h4uXyOvM= github.com/cidverse/go-vcs v0.0.0-20240628195958-27702663f242/go.mod h1:Cvbn1Zx80b6rlt/t3CCEuQczd0t+jJjjR97MIG5SQr4= -github.com/cidverse/normalizeci v1.1.1-0.20240507162324-423657017129 h1:pbgchEoNEvKnIv2Hs7vmT9p+mCpr07ewjlpw0XIGzlI= -github.com/cidverse/normalizeci v1.1.1-0.20240507162324-423657017129/go.mod h1:fIJEgJ5jCHFxS61NPSpBSKXoNyMSYZC9GY3x5pVK960= -github.com/cidverse/repoanalyzer v0.1.1-0.20240510193438-abb053de8c14 h1:awlmw+fLSV6nLytZwFdjynR63sRzt4pkI7vGiYV0lFA= -github.com/cidverse/repoanalyzer v0.1.1-0.20240510193438-abb053de8c14/go.mod h1:seX5hGx0kH2Fo3d10BBH8Ojj2ar3ztsn9iweDJ2LANU= +github.com/cidverse/normalizeci v1.1.1-0.20240716145002-cfaf14fb65c4 h1:Y0zTWGWUSk+ETv9/5nQS9JHKcDIDTB+8SUXVygCfUqA= +github.com/cidverse/normalizeci v1.1.1-0.20240716145002-cfaf14fb65c4/go.mod h1:Tf53SXr3q7brk8XmirnghmCreVb3UJDlPNF7aot29Ao= +github.com/cidverse/repoanalyzer v0.1.1-0.20240704190901-1e2e27d72222 h1:xCbR5jUYXehp4F/qZfOTM/Y2Qc0HwSCllJoDMVG4zrw= +github.com/cidverse/repoanalyzer v0.1.1-0.20240704190901-1e2e27d72222/go.mod h1:Zr6zFuWWVwYnyaMpPgHAI9NzaqSk376eKX+jbuO3+Lk= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.9 h1:QFrlgFYf2Qpi8bSpVPK1HBvWpx16v/1TZivyo7pGuBE= github.com/cloudflare/circl v1.3.9/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= @@ -61,8 +61,8 @@ github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUo github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= -github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE= +github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -104,8 +104,8 @@ github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= -github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= +github.com/google/go-github/v63 v63.0.0 h1:13xwK/wk9alSokujB9lJkuzdmQuVn2QCPeck76wR3nE= +github.com/google/go-github/v63 v63.0.0/go.mod h1:IqbcrgUmIcEaioWrGYei/09o+ge5vhffGOcxrO0AfmA= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -179,8 +179,8 @@ github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWR github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= -github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA= -github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/samber/lo v1.46.0 h1:w8G+oaCPgz1PoCJztqymCFaKwXt+5cCXn51uPxExFfQ= +github.com/samber/lo v1.46.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA= github.com/secure-systems-lab/go-securesystemslib v0.8.0/go.mod h1:UH2VZVuJfCYR8WgMlCU1uFsOUU+KeyrTWcSS73NBOzU= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= @@ -188,8 +188,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI= github.com/shibumi/go-pathspec v1.3.0/go.mod h1:Xutfslp817l2I1cZvgcfeMQJG5QnU2lh5tVaaMCl3jE= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= -github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY= +github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -215,8 +215,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/xanzy/go-gitlab v0.106.0 h1:EDfD03K74cIlQo2EducfiupVrip+Oj02bq9ofw5F8sA= -github.com/xanzy/go-gitlab v0.106.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= +github.com/xanzy/go-gitlab v0.107.0 h1:P2CT9Uy9yN9lJo3FLxpMZ4xj6uWcpnigXsjvqJ6nd2Y= +github.com/xanzy/go-gitlab v0.107.0/go.mod h1:wKNKh3GkYDMOsGmnfuX+ITCmDuSDWFO0G+C4AygL9RY= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -229,8 +229,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= @@ -304,10 +304,10 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0= -google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a h1:YIa/rzVqMEokBkPtydCkx1VLmv3An1Uw7w1P1m6EhOY= +google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a h1:hqK4+jJZXCU4pW7jsAdGOVFIfLHQeV7LaizZKnZ84HI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/cmd/api.go b/pkg/cmd/api.go index dfba8ca..8d906fa 100644 --- a/pkg/cmd/api.go +++ b/pkg/cmd/api.go @@ -27,13 +27,20 @@ cid api --type http --listen localhost:7400`, secret, _ := cmd.Flags().GetString("secret") currentModuleID, _ := cmd.Flags().GetInt("current-module") - // find project directory and load config + // find project dir projectDir := api.FindProjectDir() - cfg := app.Load(projectDir) - env := api.GetCIDEnvironment(cfg.Env, projectDir) // log log.Debug().Str("command", "api").Str("type", apiType).Str("listen", listen).Str("socket", socketFile).Str("dir", projectDir).Msg("running command") + if apiType == "socket" { + log.Info().Str("path", socketFile).Msg("serving api via socket") + } else { + log.Info().Str("addr", listen).Msg("serving api via http") + } + + // load config + cfg := app.Load(projectDir) + env := api.GetCIDEnvironment(cfg.Env, projectDir) // scan for modules modules := analyzer.ScanDirectory(projectDir) @@ -47,7 +54,7 @@ cid api --type http --listen localhost:7400`, localState := state.GetStateFromFile(stateFile) // start api - apiEngine := restapi.Setup(restapi.APIConfig{ + apiEngine := restapi.Setup(&restapi.APIConfig{ BuildID: "0", JobID: "0", ProjectDir: projectDir, diff --git a/pkg/core/actionexecutor/containeraction/containerexecutor.go b/pkg/core/actionexecutor/containeraction/containerexecutor.go index 03302cb..bc72b9a 100644 --- a/pkg/core/actionexecutor/containeraction/containerexecutor.go +++ b/pkg/core/actionexecutor/containeraction/containerexecutor.go @@ -84,7 +84,7 @@ func (e Executor) Execute(ctx *commonapi.ActionExecutionContext, localState *sta socketFile := path.Join(tempDir, hash.UUIDNoDash(uuid.New().String())+".socket") // listen - apiEngine := restapi.Setup(restapi.APIConfig{ + apiEngine := restapi.Setup(&restapi.APIConfig{ BuildID: buildID, JobID: jobID, ProjectDir: ctx.ProjectDir, diff --git a/pkg/core/actionexecutor/containeraction/util_test.go b/pkg/core/actionexecutor/containeraction/util_test.go new file mode 100644 index 0000000..060856c --- /dev/null +++ b/pkg/core/actionexecutor/containeraction/util_test.go @@ -0,0 +1,15 @@ +package containeraction + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGenerateSecret(t *testing.T) { + // generate secret + secret := generateSecret(32) + + // check length + assert.Len(t, secret, 32, "Generated secret length is incorrect") +} diff --git a/pkg/core/restapi/openapi.yaml b/pkg/core/restapi/openapi.yaml index 6b468e8..285a485 100644 --- a/pkg/core/restapi/openapi.yaml +++ b/pkg/core/restapi/openapi.yaml @@ -1,65 +1,67 @@ -openapi: 3.0.1 +openapi: 3.0.3 info: - title: CID Workflow and Action API + title: CID + description: API for Actions and Workflows license: name: MIT + url: https://github.com/cidverse/cid/blob/main/LICENSE + contact: + name: Philipp Heuer + email: git@philippheuer.me + url: https://github.com/cidverse/cid version: 1.0.0 + servers: - url: http://localhost:8080 + - url: unix://tmp/my-socket.socket + tags: + - name: observability + description: Observability, Monitoring and Logging - name: info description: Information - - name: vcs - description: VCS Operations - - name: file - description: File Operations - name: artifact description: Artifact Operations - name: command description: Command Operations + - name: file + description: File Operations + - name: vcs + description: VCS Operations + paths: # info api - /health: + /v1/health: get: tags: - - info - summary: simple healthcheck - operationId: health + - observability + summary: healthcheck + description: a very simple healthcheck + operationId: getHealthV1 responses: - 200: + "200": description: healthcheck result content: application/json: schema: - $ref: '#/components/schemas/Healthcheck' - /log: + $ref: '#/components/schemas/HealthStatus' + example: + status: "up" + /v1/log: post: tags: - - info + - observability summary: logs a message - operationId: log + operationId: logMessageV1 requestBody: content: application/json: schema: - $ref: '#/components/schemas/LogMessageRequest' + $ref: '#/components/schemas/LogMessagePayload' responses: 201: description: Null response content: {} - /project: - get: - tags: - - info - summary: query information about the current project - operationId: projectInformation - responses: - 200: - description: project information - content: - application/json: - schema: - $ref: '#/components/schemas/ProjectInformation' /config/current: get: tags: @@ -119,7 +121,7 @@ paths: schema: $ref: '#/components/schemas/Error' # vcs api - /vcs/commit: + /v1/vcs/commit: get: tags: - vcs @@ -127,7 +129,7 @@ paths: operationId: vcsCommits parameters: - name: changes - in: path + in: query description: include changes in response required: false schema: @@ -139,21 +141,21 @@ paths: application/json: schema: $ref: '#/components/schemas/VCSCommitList' - /vcs/commit/{hash}: + /v1/vcs/commit/{id}: get: tags: - vcs summary: vcs commits operationId: vcsCommits parameters: - - name: hash + - name: id in: path - description: commit hash + description: commit id / hash required: true schema: type: string - name: changes - in: path + in: query description: include changes in response required: false schema: @@ -215,6 +217,8 @@ paths: type: array items: type: string + nullable: false + responses: 200: description: file list @@ -261,9 +265,10 @@ paths: type: string requestBody: content: - text/plain: + application/octet-stream: schema: type: string + format: binary responses: 201: description: Null response @@ -275,6 +280,13 @@ paths: - artifact summary: List Artifacts operationId: artifactList + parameters: + - name: query + in: query + description: Search Query + required: false + schema: + type: string responses: 200: description: file list @@ -348,7 +360,7 @@ paths: type: string responses: 200: - description: file list + description: file content content: application/octet-stream: schema: @@ -387,7 +399,7 @@ components: detail: type: string example: error details - Healthcheck: + HealthStatus: required: - status type: object @@ -395,7 +407,7 @@ components: status: type: string example: up - LogMessageRequest: + LogMessagePayload: required: - level - message @@ -403,7 +415,14 @@ components: properties: level: type: string - example: debug + description: log level + enum: + - trace + - debug + - info + - warning + - error + example: info message: type: string example: hello world @@ -411,7 +430,7 @@ components: type: object description: dynamic key value properties / log context additionalProperties: - $ref: '#/components/schemas/AnyValue' + type: object ActionConfig: type: object properties: @@ -456,7 +475,7 @@ components: type: object description: dynamic configuration options for the action additionalProperties: - $ref: '#/components/schemas/AnyValue' + type: object ProjectEnv: type: object additionalProperties: @@ -531,6 +550,45 @@ components: type: array items: $ref: '#/components/schemas/ProjectModule' + ArtifactList: + type: array + items: + $ref: '#/components/schemas/Artifact' + Artifact: + type: object + properties: + build_id: + type: string + description: build id + example: 1234 + job_id: + type: string + description: job id + example: 1234 + id: + type: string + description: artifact id + example: 1234 + module: + type: string + description: module slug + example: root + type: + type: string + description: artifact type + example: binary + name: + type: string + description: artifact name + example: report.sarif + format: + type: string + description: artifact format + example: sarif + format_version: + type: string + description: artifact format version + example: 2.1.0 # vcs VCSCommitList: type: array @@ -562,11 +620,13 @@ components: tags: $ref: '#/components/schemas/VCSTagList' authored_at: - type: date + type: string + format: date-time description: authored at example: "2022-11-21T23:55:08+01:00" committed_at: - type: date + type: string + format: date-time description: committed at example: "2022-11-21T23:55:08+01:00" VCSAuthor: @@ -686,12 +746,14 @@ components: type: array description: expose container ports items: - type: number + type: integer + format: int32 ExecuteCommandResult: type: object properties: code: - type: number + type: integer + format: int32 description: command exit code example: 1 command: @@ -706,6 +768,7 @@ components: type: string description: error message example: exit status 1 + nullable: true stdout: type: string description: standard output (if capture-output was request, empty otherwise) @@ -714,5 +777,3 @@ components: type: string description: error output (if capture-output was request, empty otherwise) example: "" - AnyValue: - description: 'Can be anything: string, number, array, object, etc., including `null`' diff --git a/pkg/core/restapi/serve.go b/pkg/core/restapi/serve.go index 6312795..f4b5a5b 100644 --- a/pkg/core/restapi/serve.go +++ b/pkg/core/restapi/serve.go @@ -9,7 +9,7 @@ import ( "github.com/rs/zerolog/log" ) -func Setup(handlers APIConfig) *echo.Echo { +func Setup(handlers *APIConfig) *echo.Echo { // config e := echo.New() e.HideBanner = true @@ -19,24 +19,37 @@ func Setup(handlers APIConfig) *echo.Echo { e.Use(middleware.Recover()) // e.Use(middleware.Logger()) - // generic routes - e.GET("/health", handlers.healthCheck) - e.POST("/log", handlers.logMessage) - - // config - e.GET("/config/current", handlers.configCurrent) - - // project routes - e.GET("/env", handlers.projectEnv) - e.GET("/module", handlers.moduleList) - e.GET("/module/current", handlers.moduleCurrent) + // observability + e.GET("/health", handlers.healthCheck) // deprecated + e.GET("/v1/health", handlers.healthCheck) + e.POST("/log", handlers.logMessage) // deprecated + e.POST("/v1/log", handlers.logMessage) // vcs - e.GET("/vcs/commit", handlers.vcsCommits) - e.GET("/vcs/commit/:hash", handlers.vcsCommitByHash) - e.GET("/vcs/tag", handlers.vcsTags) - e.GET("/vcs/release", handlers.vcsReleases) - e.GET("/vcs/diff", handlers.vcsDiff) + e.GET("/vcs/commit", handlers.vcsCommits) // deprecated + e.GET("/vcs/commit/:hash", handlers.vcsCommitByHash) // deprecated + e.GET("/vcs/tag", handlers.vcsTags) // deprecated + e.GET("/vcs/release", handlers.vcsReleases) // deprecated + e.GET("/vcs/diff", handlers.vcsDiff) // deprecated + e.GET("/v1/vcs/commit", handlers.vcsCommits) + e.GET("/v1/vcs/commit/:hash", handlers.vcsCommitByHash) + e.GET("/v1/vcs/tag", handlers.vcsTags) + e.GET("/v1/vcs/release", handlers.vcsReleases) + e.GET("/v1/vcs/diff", handlers.vcsDiff) + + // deprecated job endpoints + e.GET("/config/current", handlers.configCurrent) // deprecated + e.GET("/env", handlers.projectEnv) // deprecated + e.GET("/module/current", handlers.moduleCurrent) // deprecated + + // current job + e.GET("/v1/job/config", handlers.configCurrent) + e.GET("/v1/job/env", handlers.projectEnv) + e.GET("/v1/job/module", handlers.moduleCurrent) + + // repoanalyzer + e.GET("/module", handlers.moduleList) // deprecated + e.GET("/v1/repoanalyzer/module", handlers.moduleList) // artifacts e.GET("/artifact", handlers.artifactList) @@ -49,11 +62,13 @@ func Setup(handlers APIConfig) *echo.Echo { e.GET("/file/write", handlers.fileWrite) // command routes - e.POST("/command", handlers.commandExecute) + e.POST("/command", handlers.commandExecute) // deprecated + e.POST("/v1/command/execute", handlers.commandExecute) // TODO: (advanced) exec command as async task (+ get command status / log output / send stdin input) // provenance - e.GET("/provenance", handlers.provenance) + e.GET("/provenance", handlers.provenance) // deprecated + e.GET("/v1/provenance", handlers.provenance) return e }