From 5e1e2ea59e15ae8482f452ba63b538069fd80167 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov Date: Tue, 17 Apr 2018 13:19:27 +0300 Subject: [PATCH] Added support for 'geo' blocks --- gixy/directives/block.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gixy/directives/block.py b/gixy/directives/block.py index f9ae0f5..5e5b1ed 100644 --- a/gixy/directives/block.py +++ b/gixy/directives/block.py @@ -173,3 +173,25 @@ class MapBlock(Block): def variables(self): # TODO(buglloc): Finish him! return [Variable(name=self.variable, value='', boundary=None, provider=self, have_script=False)] + + +class GeoBlock(Block): + nginx_name = 'geo' + self_context = False + provide_variables = True + + def __init__(self, name, args): + super(GeoBlock, self).__init__(name, args) + if len(args) == 1: # geo uses $remote_addr as default source of the value + source = '$remote_addr' + variable = args[0].strip('$') + else: + source = args[0] + variable = args[1].strip('$') + self.source = source + self.variable = variable + + @cached_property + def variables(self): + # TODO(buglloc): Finish him! -- same as in MapBlock + return [Variable(name=self.variable, value='', boundary=None, provider=self, have_script=False)]