<commit_before>import {Injectable, EventEmitter} from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Lock } from './../models/arm/locks';
import { ArmObj } from './../models/arm/arm-obj';
import {ArmService} from './arm.service';
import {CacheService} from './cache.service';
import {Permissions, PermissionsAsRegExp} from '../models/arm/permission';

@Injectable()
export class AuthzService {
    public static readScope = "./read";
    public static writeScope = "./write";
    public static deleteScope = "./delete";
    public static actionScope = "./action"

    public static permissionsSuffix = "/providers/microsoft.authorization/permissions";
    public static authSuffix = "/providers/Microsoft.Authorization/locks";

    private _wildCardEscapeSequence = "\\*";

    constructor(private _cacheService : CacheService, private _armService : ArmService){
    }

    hasPermission(resourceId : string, requestedActions : string[]) : Observable<boolean>{
        let authId = `${resourceId}${AuthzService.permissionsSuffix}`;
        return this._cacheService.getArm(authId, false, this._armService.armPermissionsVersion)
        .map(r =>{
            let permissionsSet = r.json().value;
            return this._checkPermissions(resourceId, requestedActions, permissionsSet);
        })
    }

    hasReadOnlyLock(resourceId : string) : Observable<boolean>{
        return this._getLocks(resourceId)
        .map(locks =>{<commit_msg>Should RBAC check succeeds if request returns 429<commit_after>import {Injectable, EventEmitter} from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Lock } from './../models/arm/locks';
import { ArmObj } from './../models/arm/arm-obj';
import {ArmService} from './arm.service';
import {CacheService} from './cache.service';
import {Permissions, PermissionsAsRegExp} from '../models/arm/permission';

@Injectable()
export class AuthzService {
    public static readScope = "./read";
    public static writeScope = "./write";
    public static deleteScope = "./delete";
    public static actionScope = "./action"

    public static permissionsSuffix = "/providers/microsoft.authorization/permissions";
    public static authSuffix = "/providers/Microsoft.Authorization/locks";

    private _wildCardEscapeSequence = "\\*";

    constructor(private _cacheService : CacheService, private _armService : ArmService){
    }

    hasPermission(resourceId : string, requestedActions : string[]) : Observable<boolean>{
        let authId = `${resourceId}${AuthzService.permissionsSuffix}`;
        return this._cacheService.getArm(authId, false, this._armService.armPermissionsVersion)
        .map(r =>{
            let permissionsSet = r.json().value;
            return this._checkPermissions(resourceId, requestedActions, permissionsSet);
        })
        .catch(e => {

            // We've seen cases where ARM has a bad day and permission checks will start to fail with 429's.
            // So if these requests fail, just assume that you have permission and try your best.
            if(e.status === 429 /* too many requests */){
                return Observable.of(true)
            }

            return Observable.of(false);
        });
    }

    hasReadOnlyLock(resourceId : string) : Observable<boolean>{
        return this._getLocks(resourceId)
        .map(locks =>{
{'fraction_non_alphanumeric': 0.12616164460715293, 'fraction_numerical': 0.0025344973246972683, 'mean_word_length': 3.428927680798005, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3141116', 'n_tokens_mistral': 958, 'n_tokens_neox': 939, 'n_words': 250}