Skip to content

Commit 0ae22e4

Browse files
committed
Add S3 support
1 parent 4422dc7 commit 0ae22e4

File tree

8 files changed

+783
-259
lines changed

8 files changed

+783
-259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
build
12

23
# Compiled python modules.
34
*.pyc

lib/rift/Annex.py

Lines changed: 367 additions & 63 deletions
Large diffs are not rendered by default.

lib/rift/Config.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def _construct_mapping(loader, node):
7777
_DEFAULT_REPO_CMD = 'createrepo_c'
7878
_DEFAULT_SHARED_FS_TYPE = '9p'
7979
_DEFAULT_VIRTIOFSD = '/usr/libexec/virtiofsd'
80+
_DEFAULT_S3_CREDENTIAL_FILE = '~/.rift/auth.json'
81+
8082

8183
class Config():
8284
"""
@@ -102,9 +104,33 @@ class Config():
102104
'packages_dir': {
103105
'default': _DEFAULT_PKG_DIR,
104106
},
107+
's3_credential_file': {
108+
'required': False,
109+
'default': _DEFAULT_S3_CREDENTIAL_FILE,
110+
},
111+
's3_auth_endpoint': {
112+
'required': False,
113+
},
114+
'idp_auth_endpoint': {
115+
'required': False
116+
},
117+
'idp_app_token': {
118+
'required': True
119+
},
120+
'annex_restore_cache': {
121+
'required': False,
122+
},
105123
'annex': {
106124
'required': True,
107125
},
126+
'annex_is_s3': {
127+
'required': False,
128+
'default': False,
129+
'check': 'bool',
130+
},
131+
'annex_push': {
132+
'required': False,
133+
},
108134
'working_repo': {
109135
},
110136
'repos': {
@@ -179,11 +205,6 @@ class Config():
179205
'vm_build_post_script': {
180206
'default': _DEFAULT_VM_BUILD_POST_SCRIPT,
181207
},
182-
'gerrit_realm': {},
183-
'gerrit_server': {},
184-
'gerrit_url': {},
185-
'gerrit_username': {},
186-
'gerrit_password': {},
187208
'rpm_macros': {
188209
'check': 'dict',
189210
},
@@ -417,8 +438,14 @@ def _key_value(self, syntax, key, value):
417438
"""
418439
# Check type
419440
check = syntax.get('check', 'string')
420-
assert check in ('string', 'dict', 'list', 'digit', 'enum')
441+
assert check in ('string', 'dict', 'list', 'digit', 'enum', 'bool')
421442

443+
if check == 'bool':
444+
if not isinstance(value, bool):
445+
raise DeclError(
446+
f"Bad data type {value.__class__.__name__} for '{key}'"
447+
)
448+
return value
422449
if check == 'dict':
423450
if not isinstance(value, dict):
424451
raise DeclError(

lib/rift/Controller.py

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from operator import attrgetter
4141
import random
4242
import time
43+
import datetime
4344
import textwrap
4445
# Since pylint can not found rpm.error, disable this check
4546
from rpm import error as RpmError # pylint: disable=no-name-in-module
@@ -48,7 +49,7 @@
4849
from rift import RiftError, __version__
4950
from rift.Annex import Annex, is_binary
5051
from rift.Config import Config, Staff, Modules
51-
from rift.Gerrit import Review
52+
from rift.auth import auth
5253
from rift.Mock import Mock
5354
from rift.Package import Package, Test
5455
from rift.Repository import LocalRepository, ProjectArchRepositories
@@ -221,6 +222,9 @@ def make_parser():
221222
subsubprs.add_argument('--dest', metavar='PATH', required=True,
222223
help='destination path')
223224

225+
# Auth options
226+
subprs = subparsers.add_parser('auth', help='Authenticate for access to Annex write access')
227+
224228
# VM options
225229
subprs = subparsers.add_parser('vm', help='Manipulate VM process')
226230
subprs.add_argument('-a', '--arch', help='CPU architecture of the VM')
@@ -270,11 +274,9 @@ def make_parser():
270274
subprs.add_argument('--bump', dest='bump', action='store_true',
271275
help='also bump the release number')
272276

273-
# Gerrit review
274-
subprs = subparsers.add_parser('gerrit', add_help=False,
275-
help='Make Gerrit automatic review')
276-
subprs.add_argument('--change', help="Gerrit Change-Id", required=True)
277-
subprs.add_argument('--patchset', help="Gerrit patchset ID", required=True)
277+
# GitLab review
278+
subprs = subparsers.add_parser('gitlab', add_help=False,
279+
help='Check specfiles for GitLab')
278280
subprs.add_argument('patch', metavar='PATCH', type=argparse.FileType('r'))
279281

280282
# Parse options
@@ -357,8 +359,8 @@ def action_annex(args, config, staff, modules):
357359
message('%s: not an annex pointer, ignoring' % srcfile)
358360

359361
elif args.annex_cmd == 'delete':
360-
annex.delete(args.id)
361-
message('%s has been deleted' % args.id)
362+
if annex.delete(args.id):
363+
message('%s has been deleted' % args.id)
362364

363365
elif args.annex_cmd == 'get':
364366
annex.get(args.id, args.dest)
@@ -369,8 +371,26 @@ def action_annex(args, config, staff, modules):
369371
output_file = annex.backup(
370372
Package.list(config, staff, modules), args.output_file
371373
)
374+
372375
message(f"Annex backup is available here: {output_file}")
373376

377+
def action_auth(args, config):
378+
"""Action for 'auth' sub-commands."""
379+
auth_obj = auth(config)
380+
381+
if auth_obj.authenticate():
382+
msg = "succesfully authenticated"
383+
384+
t = auth_obj.get_expiration_timestr()
385+
if t != "":
386+
msg += "; token expires in {}".format(t)
387+
else:
388+
msg += "; token expiration time is unknown"
389+
390+
message(msg)
391+
else:
392+
message("error: authentication failed")
393+
374394
def _vm_start(vm):
375395
if vm.running():
376396
message('VM is already running')
@@ -874,23 +894,18 @@ def action_validdiff(args, config):
874894

875895
return rc
876896

877-
def action_gerrit(args, config, staff, modules):
878-
"""Review a patchset for Gerrit (specfiles)"""
879-
880-
review = Review()
897+
def action_gitlab(args, config, staff, modules):
898+
"""Review a patchset for GitLab (specfiles)"""
881899

882900
# Parse matching diff and specfiles in it
883-
for patchedfile in parse_unidiff(args.patch):
884-
filepath = patchedfile.path
885-
names = filepath.split(os.path.sep)
901+
for f in parse_unidiff(args.patch):
902+
path = f.path
903+
names = path.split(os.path.sep)
886904
if names[0] == config.get('packages_dir'):
887905
pkg = Package(names[1], config, staff, modules)
888-
if filepath == pkg.specfile and not patchedfile.is_deleted_file:
889-
Spec(pkg.specfile, config=config).analyze(review, pkg.dir)
890-
891-
# Push review
892-
review.msg_header = 'rpmlint analysis'
893-
review.push(config, args.change, args.patchset)
906+
if os.path.abspath(path) == pkg.specfile and not f.is_deleted_file:
907+
spec = Spec(pkg.specfile, config=config)
908+
spec.check()
894909

895910
def get_packages_from_patch(patch, config, modules, staff):
896911
"""
@@ -981,6 +996,11 @@ def action(config, args):
981996
action_annex(args, config, *staff_modules(config))
982997
return
983998

999+
# AUTH
1000+
if args.command == 'auth':
1001+
action_auth(args, config)
1002+
return
1003+
9841004
# VM
9851005
if args.command == 'vm':
9861006
return action_vm(args, config)
@@ -1124,9 +1144,9 @@ def action(config, args):
11241144
config=config).add_changelog_entry(author, args.comment,
11251145
bump=getattr(args, 'bump', False))
11261146

1127-
# GERRIT
1128-
elif args.command == 'gerrit':
1129-
return action_gerrit(args, config, *staff_modules(config))
1147+
# GITLAB
1148+
elif args.command == 'gitlab':
1149+
return action_gitlab(args, config, *staff_modules(config))
11301150

11311151
return 0
11321152

@@ -1167,6 +1187,18 @@ def _validate_patched_file(patched_file, config, modules, staff):
11671187
if patched_file.binary:
11681188
raise RiftError("Binary file detected: %s" % filepath)
11691189

1190+
if filepath == '.gitlab-ci.yml':
1191+
logging.debug('Ignoring gitlab ci file: %s', filepath)
1192+
return False
1193+
1194+
if filepath == 'CODEOWNERS':
1195+
logging.debug('Ignoring gitlab ci file: %s', filepath)
1196+
return False
1197+
1198+
if names[0] == "gitlab-ci":
1199+
logging.debug("Ignoring gitlab ci file: %s" % filepath)
1200+
return False
1201+
11701202
if names[0] != config.get('packages_dir'):
11711203
raise RiftError("Unknown file pattern: %s" % filepath)
11721204

lib/rift/Gerrit.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)