git删除某个文件的提交记录

发现不小心提交了包含密码的文件,所以记录下删除该文件及记录的方法

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/main/resources/application.properties' --prune-empty --tag-name-filter cat -- --all

src/main/resources/application.properties为该文件,替换成需要的文件即可。

如果提示:Cannot rewrite branches: Your index contains uncommitted changes.

则需要:

git stash

最后提交到git:

git push origin --force --all

SpringBoot扫描注册注解

有个小需求是扫描在SpringBoot 注册的RequestMapping接口地址,可以先扫描所有使用Controller注解的类,然后获取他们的方法,判断使用的RequestMapping注解,再获取value,就能拿到接口地址了。下面为代码片段

    /**
     * 扫描使用注解的类
     * @param packageName 扫描包名
     * @param annotation 注解类
     * @return 扫描到的集合
     */
    public static List<class> scanClass(String packageName, Class annotation) {
        List<class> classList = new ArrayList&lt;>();
        if (ObjectUtils.isEmpty(packageName)) {
            return classList;
        }
        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        TypeFilter includeFilter = (metadataReader, metadataReaderFactory) -> true;
        provider.addIncludeFilter(includeFilter);
        Set<beandefinition> beanDefinitionSet = new HashSet&lt;>();
        // 指定扫描的包名
        Set<beandefinition> candidateComponents = provider.findCandidateComponents(packageName);
        beanDefinitionSet.addAll(candidateComponents);

        beanDefinitionSet.forEach(beanDefinition -> {
            try {
                Class clazz = Class.forName(beanDefinition.getBeanClassName());

                if (!ObjectUtils.isEmpty(annotation)) {
                    if (!ObjectUtils.isEmpty(AnnotationUtils.getAnnotation(clazz, annotation))) {
                        classList.add(clazz);
                    }
                } else {
                    classList.add(clazz);
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
//            System.out.println(definition.getBeanClassName());
        });
        return classList;
    }

    /**
     * 获取Url
     * @param packageName 扫描包名
     * @param className 指定类,如无指定类,为null即可
     * @return url集合
     */
    public static List<string> getUrls(String packageName,String className){
        List<class> list= scanClass(packageName, Controller.class);
        List<string> urls=new ArrayList&lt;>();
        for (Class aClass : list) {
            if(className!=null&amp;&amp;!aClass.getSimpleName().equals(className)){
                continue;
            }
            Method[] methods= aClass.getDeclaredMethods();
            for (Method method : methods) {
                RequestMapping ls=method.getAnnotation(RequestMapping.class);
                if(ls!=null) {
                    urls.add(ls.value()[0]);
                }
            }
        }
        return urls;
    }

花生壳Oray动态域名自动更新IP

前言:由于最近家里公网IP经常变动,自己又有个Oray的域名,所以想弄个动态IP更新上去,而Oray的花生壳服务现在要花钱(还限制端口),所以已经不考虑花生壳了

一、Oray设置

进入域名设置的 其他服务-自主管理,开启自主管理设置

二、关键URL API

1.登录

首先需要获取到登录token

def getToken():
    headers={
        "Authorization":"",
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    url="http://dm-api.oray.com/authorization" #登录url
    ret=requests.post(url,data='{"rootname": "自主管理域名", "password": "密码"}',headers=headers) #data是raw格式
    _json=json.loads(ret.text)
    return _json['token']

2.获取recordid

def getRecordItem ():
    url="http://dm-api.oray.com/resolves/自助管理根域名"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    ret=requests.get(url,headers=headers)
    _json=json.loads(ret.text)
    for _item in _json:
        if(_item['name']=='你目标二级域名头'):
            return _item
recordid=getRecordItem()['recordid']

3.更新IP

def updateIp():
    url="http://dm-api.oray.com/resolves/你要修改的二级域名"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    _json=json.loads('{"recordid":1,"domainname":"你要修改的二级域名","subname":"二级域名头","line":0,"recordtype":"a","value":"","ttl":3600,"priority":0}')
    _json['value']=ip #你要提交的ip
    _json['recordid']=getRecordItem()
    _data=json.dumps(_json)
    requests.post(url,data=_data,headers=headers)

以上就完成了,根据自己使用的不同语言进行http调用修改就行,放一份完整的Python代码仅供参考(假设要修改的二级域名:nas.example.cn)

import json
import requests
ip="127.0.0.1"
def getToken():
    headers={
        "Authorization":"",
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    url="http://dm-api.oray.com/authorization"
    post=requests.post(url,data='{"rootname": "example.cn", "password": "123456"}',headers=headers)
    _json=json.loads(post.text)
    return _json['token']
token=getToken()
def getRecordItem():
    url="http://dm-api.oray.com/resolves/example.cn"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    ret=requests.get(url,headers=headers)
    _json=json.loads(ret.text)
    for _item in _json:
        if(_item['name']=='nas'):
            return _item
def updateIp():
    url="http://dm-api.oray.com/resolves/nas.example.cn"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    _json=json.loads('{"recordid":0,"domainname":"nas.example.cn","subname":"nas","line":0,"recordtype":"a","value":"","ttl":3600,"priority":0}')
    _json['value']=ip
    _json['recordid']=getRecordItem()['recordid']
    _data=json.dumps(_json)
    requests.post(url,data=_data,headers=headers)
updateIp()