Esempio n. 1
0
 def validate_pre_signed_url():
     try:
         auth = request.headers.get('Authorization')
         if auth is None:
             logger.warning("The Authorization header is missing: %s.",
                            request.headers)
             abort(403)
         payload = signer.verify_token(auth)
         token_filename = payload.get("filename")
         request_filename = request.view_args['filename']
         if token_filename is None:
             logger.warning(
                 "The payload does not contain 'filename' key: %s.",
                 payload)
             abort(403)
         if token_filename != request_filename:
             logger.warning(
                 "The payload log_relative_path key is different than the one in token:"
                 "Request path: %s. Token path: %s.",
                 request_filename,
                 token_filename,
             )
             abort(403)
     except InvalidAudienceError:
         logger.warning("Invalid audience for the request", exc_info=True)
         abort(403)
     except InvalidSignatureError:
         logger.warning("The signature of the request was wrong",
                        exc_info=True)
         abort(403)
     except ImmatureSignatureError:
         logger.warning(
             "The signature of the request was sent from the future",
             exc_info=True)
         abort(403)
     except ExpiredSignatureError:
         logger.warning(
             "The signature of the request has expired. Make sure that all components "
             "in your system have synchronized clocks. "
             "See more at %s",
             get_docs_url("configurations-ref.html#secret-key"),
             exc_info=True,
         )
         abort(403)
     except InvalidIssuedAtError:
         logger.warning(
             "The request was issues in the future. Make sure that all components "
             "in your system have synchronized clocks. "
             "See more at %s",
             get_docs_url("configurations-ref.html#secret-key"),
             exc_info=True,
         )
         abort(403)
     except Exception:
         logger.warning("Unknown error", exc_info=True)
         abort(403)
def init_appbuilder_links(app):
    """Add links to Docs menu in navbar"""
    appbuilder = app.appbuilder
    appbuilder.add_link(name="Documentation",
                        label="Documentation",
                        href=get_docs_url(),
                        category="Docs")
    appbuilder.add_link(name="Documentation",
                        label="Airflow Website",
                        href='https://airflow.apache.org',
                        category="Docs")
    appbuilder.add_link(name="Documentation",
                        label="GitHub Repo",
                        href='https://github.com/apache/airflow',
                        category="Docs")
    appbuilder.add_link(
        name="Documentation",
        label="REST API Reference (Swagger UI)",
        href='/api/v1./api/v1_swagger_ui_index',
        category="Docs",
    )
    appbuilder.add_link(name="Documentation",
                        label="REST API Reference (Redoc)",
                        href="RedocView.redoc",
                        category='Docs')
Esempio n. 3
0
def add_deprecation_headers(response: Response):
    """
    Add `Deprecation HTTP Header Field
    <https://tools.ietf.org/id/draft-dalal-deprecation-header-03.html>`__.
    """
    response.headers['Deprecation'] = 'true'
    doc_url = get_docs_url("stable-rest-api/migration.html")
    deprecation_link = f'<{doc_url}>; rel="deprecation"; type="text/html"'
    if 'link' in response.headers:
        response.headers['Link'] += f', {deprecation_link}'
    else:
        response.headers['Link'] = f'{deprecation_link}'

    return response
Esempio n. 4
0
def add_deprecation_headers(response: Response):
    """
    Add `Deprecation HTTP Header Field
    <https://tools.ietf.org/id/draft-dalal-deprecation-header-03.html>`__.
    """
    response.headers['Deprecation'] = 'true'
    doc_url = get_docs_url("upgrading-to-2.html#migration-guide-from-experimental-api-to-stable-api-v1")
    deprecation_link = f'<{doc_url}>; rel="deprecation"; type="text/html"'
    if 'link' in response.headers:
        response.headers['Link'] += f', {deprecation_link}'
    else:
        response.headers['Link'] = f'{deprecation_link}'

    return response
Esempio n. 5
0
def main():
    """Main executable function"""
    if conf.get("core", "security") == 'kerberos':
        os.environ['KRB5CCNAME'] = conf.get('kerberos', 'ccache')
        os.environ['KRB5_KTNAME'] = conf.get('kerberos', 'keytab')
    if PY310:
        docs_url = get_docs_url('installation/prerequisites.html')
        warnings.warn(
            "Python v3.10 is not official supported on this version of Airflow. Please be careful. "
            f"For details, see: {docs_url}")

    parser = cli_parser.get_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    args.func(args)
Esempio n. 6
0
    def register_in_sensor_service(self, ti, context):
        """
        Register ti in smart sensor service

        :param ti: Task instance object.
        :param context: TaskInstance template context from the ti.
        :return: boolean
        """
        docs_url = get_docs_url('concepts/smart-sensors.html#migrating-to-deferrable-operators')
        warnings.warn(
            'Your sensor is using Smart Sensors, which are deprecated.'
            f' Please use Deferrable Operators instead. See {docs_url} for more info.',
            DeprecationWarning,
        )
        poke_context = self.get_poke_context(context)
        execution_context = self.get_execution_context(context)

        return SensorInstance.register(ti, poke_context, execution_context)
Esempio n. 7
0
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Dict, Optional

import werkzeug

from airflow._vendor.connexion import FlaskApi, ProblemException, problem
from airflow.utils.docs import get_docs_url

doc_link = get_docs_url("stable-rest-api-ref.html")

EXCEPTIONS_LINK_MAP = {
    400: f"{doc_link}#section/Errors/BadRequest",
    404: f"{doc_link}#section/Errors/NotFound",
    405: f"{doc_link}#section/Errors/MethodNotAllowed",
    401: f"{doc_link}#section/Errors/Unauthenticated",
    409: f"{doc_link}#section/Errors/AlreadyExists",
    403: f"{doc_link}#section/Errors/PermissionDenied",
    500: f"{doc_link}#section/Errors/Unknown",
}


def common_error_handler(exception):
    """
    Used to capture connexion exceptions and add link to the type field
Esempio n. 8
0
 def test_should_return_link(self, version, page, expected_url):
     with mock.patch('airflow.version.version', version):
         assert expected_url == get_docs_url(page)
Esempio n. 9
0
 def test_should_return_link(self, version, page, expected_urk):
     with mock.patch('airflow.version.version', version):
         self.assertEqual(expected_urk, get_docs_url(page))