Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner REST Endpoint 404 errors

Erik Saline August 23, 2018

I am running BitBucket Data Center 5.8.0 with 3 nodes and ScriptRunner 5.2.10.  I have a REST Endpoint setup to return owners of a Repo.  When running the command sometimes I receive a 404 error.  I have verify the REST Endpoint is setup on all 3 nodes.  

APP1G8WMBD49CB:~ eazye$ curl -u a.thebest:${ABAATAMATION} -X GET "https://bitbucket.mybiz.com/rest/scriptrunner/latest/custom/getRepoOwners?projectName=ACID&repoSlug=acid-terraform"

{

    "content": {

        "repoOwners": {

            "total": 26,

            "owner": [

                {

                    "name": "a.b2great",

                    "email": "Lst-mybiz.com.IT.CM@mybiz.com",

                    "displayName": "SCM Generic Account for \"Local\" login",

                    "active": true,

                    "slug": "a.b2great"

                },

                {

                    "name": "a.thebest",

                    "email": "a.thebest@mybiz.com",

                    "displayName": "a.thebest",

                    "active": true,

                    "slug": "a.thebest"

                },

                {

                    "name": "a.reta",

                    "email": "Lst-digital.mobility.support@mybiz.com",

                    "displayName": "user a.retail",

                    "active": true,

                    "slug": "a.reta"

                },

                {

                    "name": "hardestworker",

                    "email": "hadest.worker@mybiz.com",

                    "displayName": "Hardest Worker",

                    "active": true,

                    "slug": "hardestworker"

                },

                {

                    "name": "unknown",

                    "email": "un.known@mybiz.com",

                    "displayName": "Un Known",

                    "active": true,

                    "slug": "unknown"

                },

                {

                    "name": "eazye",

                    "email": "easy.e@mybiz.com",

                    "displayName": "Easy E",

                    "active": true,

                    "slug": "eazye"

                },

 

            ]

        }

    }

APP1G8WMBD49CB:~ eazye$ curl -v -u a.thebest:${ABAATAMATION} -X GET "https://bitbucket.mybiz.com/rest/scriptrunner/latest/custom/getRepoOwners?projectName=ACID&repoSlug=acid-terraform"

Note: Unnecessary use of -X or --request, GET is already inferred.

-   Trying 10.11.55.227...

- TCP_NODELAY set

- Connected to bitbucket.mybiz.com (10.11.55.227) port 443 (#0)

- ALPN, offering h2

- ALPN, offering http/1.1

- Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

- successfully set certificate verify locations:

-   CAfile: /etc/ssl/cert.pem

  CApath: none

 

- SSL connection using TLSv1.2 / AES256-GCM-SHA384

- ALPN, server did not agree to a protocol

- Server certificate:

-  subject: C=US; ST=Anystate; L=Anytown; O=mybiz, Inc.; CN=bitbucket.mybiz.com

-  start date: Jul 26 19:11:31 2018 GMT

-  expire date: Jul 26 19:41:31 2020 GMT

-  subjectAltName: host "bitbucket.mybiz.com" matched cert's "bitbucket.mybiz.com"

-  SSL certificate verify ok.

- Server auth using Basic with user 'a.thebest'

> GET /rest/scriptrunner/latest/custom/getRepoOwners?projectName=ACID&repoSlug=acid-terraform HTTP/1.1

> Host: bitbucket.mybiz.com

> User-Agent: curl/7.54.0

> Accept: -/-

> 

< HTTP/1.1 404 

< Server: nginx/1.8.1

< Date: Wed, 22 Aug 2018 22:50:57 GMT

< Content-Type: application/json

< Transfer-Encoding: chunked

< Connection: keep-alive

< X-AREQUESTID: -ZC7Z9x1370x21127215x1

< X-ASEN: SEN-7753076

< X-AUSERID: 4496388

< X-AUSERNAME: a.thebest

< X-Content-Type-Options: nosniff

< Vary: Accept-Encoding

< Set-Cookie: BIGipServer~off-platform~pool-bitbucket.pa.b2b.mybiz.com_443=1144523530.47873.0000; path=/; Httponly; Secure

< 

- Connection #0 to host bitbucket.mybiz.com left intact

APP1G8WMBD49CB:~ eazye$ curl -v -u a.thebest:${ABAATAMATION} -X GET "https://bitbucket.mybiz.com/rest/scriptrunner/latest/custom/getRepoOwners?projectName=ACID&repoSlug=acid-terraform"

Note: Unnecessary use of -X or --request, GET is already inferred.

-   Trying 10.11.55.227...

- TCP_NODELAY set

- Connected to bitbucket.mybiz.com (10.11.55.227) port 443 (#0)

- ALPN, offering h2

- ALPN, offering http/1.1

- Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

- successfully set certificate verify locations:

-   CAfile: /etc/ssl/cert.pem

  CApath: none

 

- SSL connection using TLSv1.2 / AES256-GCM-SHA384

- ALPN, server did not agree to a protocol

- Server certificate:

-  subject: C=US; ST=Anystate; L=Anytown; O=mybiz, Inc.; CN=bitbucket.mybiz.com

-  start date: Jul 26 19:11:31 2018 GMT

-  expire date: Jul 26 19:41:31 2020 GMT

-  subjectAltName: host "bitbucket.mybiz.com" matched cert's "bitbucket.mybiz.com"

-  SSL certificate verify ok.

- Server auth using Basic with user 'a.thebest'

> GET /rest/scriptrunner/latest/custom/getRepoOwners?projectName=ACID&repoSlug=acid-terraform HTTP/1.1

> Host: bitbucket.mybiz.com

> User-Agent: curl/7.54.0

> Accept: -/-

> 

< HTTP/1.1 404 

< Server: nginx/1.8.1

< Date: Wed, 22 Aug 2018 23:21:07 GMT

< Content-Type: application/json

< Transfer-Encoding: chunked

< Connection: keep-alive

< X-AREQUESTID: -ZC7Z9x1401x21151999x2

< X-ASEN: SEN-7753076

< X-AUSERID: 4496388

< X-AUSERNAME: a.thebest

< X-Content-Type-Options: nosniff

< Vary: Accept-Encoding

< Set-Cookie: BIGipServer~off-platform~pool-bitbucket.pa.b2b.mybiz.com_443=1144523530.47873.0000; path=/; Httponly; Secure

< 

- Connection #0 to host bitbucket.mybiz.com left intact

 

package atlassian.bitbucket.scriptRestPoints

import com.atlassian.bitbucket.permission.Permission
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.bitbucket.user.UserSearchRequest
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.util.Page
import com.atlassian.bitbucket.util.PageRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

UserService userService = ComponentLocator.getComponent(UserService)
RepositoryService repositoryService = ComponentLocator.getComponent(RepositoryService)

getRepoOwners(httpMethod: "GET", groups: ["stash-users"]) {
MultivaluedMap queryParams, String body ->


String projectName = queryParams.getFirst("projectName")
String repoSlug = queryParams.getFirst("repoSlug")

if (projectName == null) {
return Response.status(Response.Status.BAD_REQUEST).entity([error: "Project Name is empty."]).build()
}

if (repoSlug == null) {
return Response.status(Response.Status.BAD_REQUEST).entity([error: "Repo Name is empty."]).build()
}

//TODO Update to use start and end points for correct paging
PageRequestImpl pageRequest = new PageRequestImpl(0, 500)

try {
int repositoryId = repositoryService.getBySlug(projectName, repoSlug).getId()

UserSearchRequest userSearchRequestRepoAdmin = new UserSearchRequest.Builder()
.repositoryPermission(repositoryId, Permission.REPO_ADMIN)
.build()

Page<ApplicationUser> repoAdmins = userService.search(userSearchRequestRepoAdmin,
pageRequest.buildRestrictedPageRequest(PageRequest.MAX_PAGE_LIMIT))

List<ApplicationUser> listOfOwners = new ArrayList<>()

if (repoAdmins.getSize() > 0) {
for (ApplicationUser applicationUser : repoAdmins.getValues()) {
if (!listOfOwners.contains(applicationUser)) {
listOfOwners.add(applicationUser)
}
}
}

if (listOfOwners.isEmpty()) {
return Response.status(Response.Status.BAD_REQUEST).entity([repoOwners: "No owners found."]).build()
} else {

JsonBuilder repoOwners = new JsonBuilder()

def root = repoOwners.repoOwners {
total listOfOwners.size()
owner(
listOfOwners.collect {
ApplicationUser applicationUser ->
[
name : applicationUser.name,
email : applicationUser.emailAddress,
displayName: applicationUser.displayName,
active : applicationUser.active,
slug : applicationUser.slug
]
}
)
}

return Response.ok(new JsonBuilder(repoOwners).toPrettyString()).build()
}

} catch (Exception e) {
log.error("Exception: " + e.getMessage())
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity([error: e.getMessage()]).build()
}
}

 

1 answer

0 votes
Erik Saline August 23, 2018

Quick update:

I verified the REST Point was added to each node but I still had to go to each node, select the Edit link and select the Update button.  

 

So far this has seemed to fix the issue.  Not sure if this is expected behavior.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events