aboutsummaryrefslogtreecommitdiff
path: root/.guix/modules/gn/packages/gn-auth.scm
blob: 197aee07a5e31126b128927a23e9929d41941f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(define-module (gn gn-auth)
  #:use-module (guix)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system python)
  #:use-module ((guix licenses) #:prefix license:)

  #:use-module (git oid)
  #:use-module (git tag)
  #:use-module (git bindings)
  #:use-module (git reference)
  #:use-module (git repository)


  ;; Packages from guix
  #:use-module (gnu packages check)

  #:use-module (gnu packages python-web)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages python-check)
  #:use-module (gnu packages python-crypto)

  #:use-module (gnu packages databases)

  #:use-module (gnu packages django))

(define %source-dir (dirname (dirname (dirname (current-filename)))))

(define (get-commit)
  "Retrieve the commit if the source directory is a repository."
  (if (git-predicate %source-dir)
      (begin (let ((commit #f))
	       (libgit2-init!)
	       (set! commit (oid->string
			     (reference-target
			      (repository-head (repository-open %source-dir)))))
	       (libgit2-shutdown!)
	       commit))
      "NOTAREPOSITORY"))

(define (list-last lst)
  (let ((len (length lst)))
    (if (> len 0)
	(list-ref lst (- len 1)))))

(define (process-version repo-head tag-vals)
  (let ((version-prefix (list-last (string-split (car tag-vals) #\/)))
	(repo-head-str (oid->string repo-head)))
    (if (zero? (oid-cmp  repo-head
			 (tag-target-id (cdr tag-vals))))
	version-prefix
	(string-append version-prefix "-" (substring repo-head-str 0 8)))))

(define (get-latest-version)
  "Get latest version tag from repository."
  (let ((%repo #f)
	(%tags (list))
	(%repo-head #f))
    (begin (libgit2-init!)
	   (set! %repo (repository-open %source-dir))
	   (set! %repo-head (reference-target (repository-head %repo)))
	   (tag-foreach %repo
			(lambda (tname tref)
			  (set! %tags (list (cons tname (tag-lookup %repo tref))))
			  0))
	   (libgit2-shutdown!)
	   (if (zero? (length %tags))
	       (string-append "v0.0.0-" (substring (oid->string %repo-head) 0 8))
	       (process-version
		%repo-head
		(list-last (sort-list %tags (lambda (item) (error item)))))))))

(define vcs-file?
  (or (git-predicate %source-dir)
      (const #t)))

(define-public python-authlib
  (package
   (name "python-authlib")
   (version "1.2.0")
   (source (origin
            (method url-fetch)
            (uri (pypi-uri "Authlib" version))
            (sha256
             (base32
              "178ycfypdv1hy4zjm09rmysxakmwch2n6a5wypwmx4d5hc4fi8sg"))))
   (build-system python-build-system)
   (native-inputs (list python-httpx
			python-flask
			python-django
			python-werkzeug
			python-starlette
			python-sqlalchemy
			python-pycryptodomex))
   (propagated-inputs (list python-cryptography))
   (arguments `(#:tests? #f)) ;; temporarily deactivate tests
   (home-page "https://authlib.org/")
   (synopsis
    "The ultimate Python library in building OAuth and OpenID Connect servers and clients.")
   (description
    "The ultimate Python library in building OAuth and OpenID Connect servers and
clients. It is designed from low level specifications implementations to high
level frameworks integrations, to meet the needs of everyone.")
   (license license:bsd-3)))

(package
 (name "genenetwork-auth")
 (version (string-append (get-latest-version)
			 "-git-"
			 (substring (get-commit) 0 9)))
 (source (local-file %source-dir "genenetwork-auth-checkout"
		     #:recursive? #t
		     #:select? vcs-file?))
 (build-system python-build-system)
 (arguments
  (list
   #:phases
   #~(modify-phases %standard-phases
	(replace 'check
	  (lambda _ (invoke "pytest" "-k" "unit_test"))))))
 ;; (inputs (list))
 (native-inputs
  (list python-mypy
	python-pytest
	python-pylint
	python-hypothesis
	python-pytest-mock
        python-mypy-extensions))
 (propagated-inputs
  (list python-flask
	python-redis
	python-authlib
	python-pymonad
	yoyo-migrations
	python-bcrypt ;; remove after removing all references
	python-mysqlclient
	python-argon2-cffi
	python-email-validator))
 (home-page "https://github.com/genenetwork/gn-auth")
 (synopsis "Authentication and Authorisation server for GeneNetwork services.")
 (description "Authentication and Authorisation server for GeneNetwork services.")
 (license license:agpl3+))