Skip to content

Commit

Permalink
refactor: org secrets and add org secrets pages
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 20, 2024
1 parent 7feb6ab commit e649888
Show file tree
Hide file tree
Showing 21 changed files with 1,911 additions and 52 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ services:
VELA_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh'
VELA_SERVER_PRIVATE_KEY: 'F534FF2A080E45F38E05DC70752E6787'
VELA_USER_REFRESH_TOKEN_DURATION: 90m
VELA_USER_ACCESS_TOKEN_DURATION: 60m
VELA_USER_ACCESS_TOKEN_DURATION: 30m
VELA_DISABLE_WEBHOOK_VALIDATION: 'true'
VELA_ENABLE_SECURE_COOKIE: 'false'
VELA_REPO_ALLOWLIST: '*'
Expand Down
172 changes: 159 additions & 13 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ SPDX-License-Identifier: Apache-2.0


module Api.Operations exposing
( enableRepo
( addOrgSecret
, enableRepo
, finishAuthentication
, getCurrentUser
, getOrgBuilds
, getOrgRepos
, getOrgSecrets
, getRepoBuilds
, getRepoDeployments
, getRepoSecrets
, getSharedSecrets
, getToken
, getUserSourceRepos
, logout
Expand All @@ -33,76 +38,217 @@ import Vela
-}
getToken : String -> Request JwtAccessToken
getToken baseUrl =
get baseUrl Api.Endpoint.Token Auth.Jwt.decodeJwtAccessToken
get baseUrl
Api.Endpoint.Token
Auth.Jwt.decodeJwtAccessToken


{-| finishAuthentication : complete authentication by supplying code and state to the authenciate endpoint
which will also set the refresh token cookie
-}
finishAuthentication : String -> Auth.Session.AuthParams -> Request JwtAccessToken
finishAuthentication baseUrl { code, state } =
get baseUrl (Api.Endpoint.Authenticate { code = code, state = state }) Auth.Jwt.decodeJwtAccessToken
get baseUrl
(Api.Endpoint.Authenticate { code = code, state = state })
Auth.Jwt.decodeJwtAccessToken


{-| logout: logs the user out by deleting the refresh token cookie
-}
logout : String -> Session -> Request String
logout baseUrl session =
get baseUrl Api.Endpoint.Logout Json.Decode.string
get baseUrl
Api.Endpoint.Logout
Json.Decode.string
|> withAuth session


{-| getCurrentUser : retrieves the currently authenticated user with the current user endpoint
-}
getCurrentUser : String -> Session -> Request Vela.CurrentUser
getCurrentUser baseUrl session =
get baseUrl Api.Endpoint.CurrentUser Vela.decodeCurrentUser
get baseUrl
Api.Endpoint.CurrentUser
Vela.decodeCurrentUser
|> withAuth session


{-| updateCurrentUser : updates the currently authenticated user with the current user endpoint
-}
updateCurrentUser : String -> Session -> Http.Body -> Request Vela.CurrentUser
updateCurrentUser baseUrl session body =
put baseUrl Api.Endpoint.CurrentUser body Vela.decodeCurrentUser
put baseUrl
Api.Endpoint.CurrentUser
body
Vela.decodeCurrentUser
|> withAuth session


{-| getUserSourceRepos : retrieves the current users source repositories
-}
getUserSourceRepos : String -> Session -> Request Vela.SourceRepositories
getUserSourceRepos baseUrl session =
get baseUrl Api.Endpoint.UserSourceRepositories Vela.decodeSourceRepositories
get baseUrl
Api.Endpoint.UserSourceRepositories
Vela.decodeSourceRepositories
|> withAuth session


{-| enableRepo : enables a repo
-}
enableRepo : String -> Session -> Http.Body -> Request Vela.Repository
enableRepo baseUrl session body =
post baseUrl (Api.Endpoint.Repositories Nothing Nothing) body Vela.decodeRepository
post baseUrl
(Api.Endpoint.Repositories Nothing Nothing)
body
Vela.decodeRepository
|> withAuth session


{-| getOrgRepos : retrieves the repositories for an org
-}
getOrgRepos : String -> Session -> { a | org : String } -> Request (List Vela.Repository)
getOrgRepos baseUrl session { org } =
get baseUrl (Api.Endpoint.OrgRepositories Nothing Nothing org) Vela.decodeRepositories
get baseUrl
(Api.Endpoint.OrgRepositories Nothing Nothing org)
Vela.decodeRepositories
|> withAuth session


{-| getOrgBuilds : retrieves builds for an org
-}
getOrgBuilds :
String
-> Session
->
{ a
| org : String
, pageNumber : Maybe Int
, perPage : Maybe Int
, maybeEvent : Maybe String
}
-> Request (List Vela.Build)
getOrgBuilds baseUrl session options =
get baseUrl
(Api.Endpoint.OrgBuilds options.pageNumber options.perPage options.maybeEvent options.org)
Vela.decodeBuilds
|> withAuth session


{-| getOrgSecrets : retrieves secrets for an org
-}
getOrgSecrets :
String
-> Session
->
{ a
| org : String
, pageNumber : Maybe Int
, perPage : Maybe Int
}
-> Request (List Vela.Secret)
getOrgSecrets baseUrl session options =
get baseUrl
(Api.Endpoint.Secrets options.pageNumber options.perPage "native" "org" options.org "*")
Vela.decodeSecrets
|> withAuth session


{-| getRepoSecrets : retrieves secrets for a repo
-}
getRepoSecrets :
String
-> Session
->
{ a
| org : String
, repo : String
, pageNumber : Maybe Int
, perPage : Maybe Int
}
-> Request (List Vela.Secret)
getRepoSecrets baseUrl session options =
get baseUrl
(Api.Endpoint.Secrets options.pageNumber options.perPage "native" "repo" options.org options.repo)
Vela.decodeSecrets
|> withAuth session


{-| getSharedSecrets : retrieves secrets for a org/team
-}
getSharedSecrets :
String
-> Session
->
{ a
| org : String
, team : String
, pageNumber : Maybe Int
, perPage : Maybe Int
}
-> Request (List Vela.Secret)
getSharedSecrets baseUrl session options =
get baseUrl
(Api.Endpoint.Secrets options.pageNumber options.perPage "native" "shared" options.org options.team)
Vela.decodeSecrets
|> withAuth session


{-| getRepoBuilds : retrieves builds for a repo
-}
getRepoBuilds : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String } -> Request (List Vela.Build)
getRepoBuilds :
String
-> Session
->
{ a
| org : String
, repo : String
, pageNumber : Maybe Int
, perPage : Maybe Int
, maybeEvent : Maybe String
}
-> Request (List Vela.Build)
getRepoBuilds baseUrl session options =
get baseUrl (Api.Endpoint.Builds options.pageNumber options.perPage options.maybeEvent options.org options.repo) Vela.decodeBuilds
get baseUrl
(Api.Endpoint.Builds options.pageNumber options.perPage options.maybeEvent options.org options.repo)
Vela.decodeBuilds
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int } -> Request (List Vela.Deployment)
getRepoDeployments :
String
-> Session
->
{ a
| org : String
, repo : String
, pageNumber : Maybe Int
, perPage : Maybe Int
}
-> Request (List Vela.Deployment)
getRepoDeployments baseUrl session options =
get baseUrl (Api.Endpoint.Deployments options.pageNumber options.perPage options.org options.repo) Vela.decodeDeployments
get baseUrl
(Api.Endpoint.Deployments options.pageNumber options.perPage options.org options.repo)
Vela.decodeDeployments
|> withAuth session


{-| addOrgSecret : adds an org secret
-}
addOrgSecret :
String
-> Session
->
{ a
| org : String
, body : Http.Body
}
-> Request Vela.Secret
addOrgSecret baseUrl session options =
post baseUrl
(Api.Endpoint.Secrets Nothing Nothing "native" "org" options.org "*")
options.body
Vela.decodeSecret
|> withAuth session
Loading

0 comments on commit e649888

Please sign in to comment.