Skip to content

Instantly share code, notes, and snippets.

@darxtrix
Created June 25, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darxtrix/3f4ac92d0ac5ef7cdc0c1c7bd5932dd5 to your computer and use it in GitHub Desktop.
Save darxtrix/3f4ac92d0ac5ef7cdc0c1c7bd5932dd5 to your computer and use it in GitHub Desktop.
OBS API

OBS API

We need the following functionality:

  • co/init package
  • add files
  • remove files
  • commit
  • get build results
  • get repo urls

There are two ways of writing an OBS client:

  • Using OBS REST API

  • Using osc (.core,.config) modules

  • Using OBS REST API :

We can find the REST endpoints called in the individuals command by adding a debugging flag (-d) while running them, for example:

$ osc -d results
GET https://api.opensuse.org/build/home:laszlo_budai:syslog-ng-gsoc-autorel/_result?package=syslog-ng-autorel
xUbuntu_16.04        i586       succeeded
xUbuntu_16.04        x86_64     succeeded
xUbuntu_15.10        i586       succeeded
xUbuntu_15.10        x86_64     succeeded
xUbuntu_15.04        i586       succeeded
xUbuntu_15.04        x86_64     succeeded
xUbuntu_14.04        i586       succeeded
xUbuntu_14.04        x86_64     succeeded
xUbuntu_12.04        i586       disabled
xUbuntu_12.04        x86_64     disabled
Debian_8.0           i586       succeeded
Debian_8.0           x86_64     succeeded
Debian_7.0           i586       disabled
Debian_7.0           x86_64     disabled

We can do full inspection of HTTP requests using the following:

$ osc -d --http-full-debug results

GET https://api.opensuse.org/build/home:laszlo_budai:syslog-ng-gsoc-autorel/_result?package=syslog-ng-autorel
send: 'GET /build/home:laszlo_budai:syslog-ng-gsoc-autorel/_result?package=syslog-ng-autorel HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: api.opensuse.org\r\nConnection: close\r\nUser-agent: osc/0.142git\r\n\r\n'
reply: 'HTTP/1.1 401 Authorization Required\r\n'
header: Date: Fri, 24 Jun 2016 09:19:04 GMT
header: Server: Apache/2.2.12 (Linux/SUSE)
header: WWW-Authenticate: Basic realm="Use your novell account"
header: Vary: accept-language,accept-charset
header: Strict-Transport-Security: max-age=31536000
header: Accept-Ranges: bytes
header: Connection: close
header: Transfer-Encoding: chunked
header: Content-Type: text/html; charset=iso-8859-1
header: Content-Language: en
send: 'GET /build/home:laszlo_budai:syslog-ng-gsoc-autorel/_result?package=syslog-ng-autorel HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: api.opensuse.org\r\nConnection: close\r\nAuthorization: Basic YmxhY2stcGVyBvphbmbmWDNAb2JzIw==\r\nUser-agent: osc/0.142git\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Fri, 24 Jun 2016 09:19:05 GMT
header: Server: Apache/2.4.16 (Linux/SUSE)
header: Strict-Transport-Security: max-age=31536000
header: Cache-Control: no-transform
header: X-XSS-Protection: 1; mode=block
header: X-Opensuse-Runtimes: {"view":null,"db":4.411665,"backend":0,"xml":0}
header: X-Request-Id: 5606b8e5-c741-436a-8446-3922a19f24c4
header: X-Opensuse-APIVersion: 2.7.51.git20160615.77d3dc6
header: X-Runtime: 0.013295
header: X-Frame-Options: SAMEORIGIN
header: X-Content-Type-Options: nosniff
header: X-Powered-By: Phusion Passenger 5.0.22
header: Content-Type: text/xml
header: Cache-Control: no-cache
header: Content-Length: 2994
header: Set-Cookie: openSUSE_session=a15c4f569dd5553a365ecfe6ff4551eb17; path=/; Max-Age=86400; Secure; HttpOnly; domain=.opensuse.org
header: Connection: close
xUbuntu_16.04        i586       succeeded
xUbuntu_16.04        x86_64     succeeded
xUbuntu_15.10        i586       succeeded
xUbuntu_15.10        x86_64     succeeded
xUbuntu_15.04        i586       succeeded
xUbuntu_15.04        x86_64     succeeded
xUbuntu_14.04        i586       succeeded
xUbuntu_14.04        x86_64     succeeded
xUbuntu_12.04        i586       disabled
xUbuntu_12.04        x86_64     disabled
Debian_8.0           i586       succeeded
Debian_8.0           x86_64     succeeded
Debian_7.0           i586       disabled
Debian_7.0           x86_64     disabled
  • Using osc: The osc.core and osc.commandline modules presents functions to extend this functionality. For eg. adding files can be implemented by using the addFiles function defined in osc.core module. We can use these modules to write plugins futher on. It is nice rather than calling osc executable by calling os.system etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment