mac 安装 配置 maven

下载的网址https://maven.apache.org/download.cgi

$ curl -O https://www-eu.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
$ tar -xvf  apache-maven-3.6.2-bin.tar.gz
$ sudo mv -f apache-maven-3.6.2 /usr/local/

编辑 /etc/profile 文件 sudo vim /etc/profile,在文件末尾添加如下代码:

export MAVEN_HOME=/usr/local/apache-maven-3.6.2
export PATH=${PATH}:${MAVEN_HOME}/bin

保存文件,并运行如下命令使环境变量生效:

# source /etc/profile

在console控制台输入如下命令,如果可以看到 Maven 相关版本信息,则说明 Maven 在本地已经安装成功了:

# mvn -v

打开Intellij,点击左上角从下来菜单里进入Preferences。配置maven地址

Intellij IDEA配置Maven 使用本地Nexus



上图中settings.xml 配置如下:

<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <pluginGroups></pluginGroups> <proxies></proxies> <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> <mirrors> <mirror> <id>nexus-releases</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/repository/efs-releases/</url> </mirror> <mirror> <id>nexus-snapshots</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/repository/efs-snapshots</url> </mirror> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus-releases</id> <url>http://nexus-releases</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>nexus-snapshots</id> <url>http://nexus-snapshots</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-releases</id> <url>http://nexus-releases</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> <pluginRepository> <id>nexus-snapshots</id> <url>http://nexus-snapshots</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>

我本地用docker启动的nexus:

docker volume create –name nexus-data

docker run -d -p 8081:8081 -p 8082:8082 -p 8083:8083 –name my-nexus  -v /Users/luciawang/Documents/nexus:/nexus-data  sonatype/nexus3:3.4.0

nexus 默认的用户名密码是 admin / admin123

测试一下本地代码已经可以读取本地的nexus了

Rails Rspec 单元测试 验证接口返回格式

如何在单元测试中测试接口返回的字段?

如果我们有一个api的entity为 employment.rb

# frozen_string_literal: true

module API::Entities::BorrowerEntities
  class Employment < API::Entity
    param :in_type_id, safe_path: %i[primary_income_source id]
    param :aaa_type, safe_path: %i[employed_code]
    param :started_with_employer, safe_path: %i[started_with_employer]
  end
end

 let(:default_headers) { { ‘CONTENT_TYPE’ => ‘application/json’ } }

it ‘xxx xxx’ do

  headers = { ‘Authorization’ => bearer_token_for(xixi.account) }.merge(default_headers)

  put ‘/api/v1/tester/aaa’, sample_entity_with(‘aaa_type’ => ‘Self-aaa’).to_json, headers

  expected_presenter = API::Entities::BorrowerEntities::Employment.represent(tester.account.current_aaa_detail)

  expect(response_body).to eq(JSON.parse(expected_presenter.to_json))

end

详细的例子:

Grape API Entity has a "represent" method that can be useful in specs scenarios when we expect some object to be presented with some specific entity, for example when we have:

present user, with: API::Entities::User

We are actually saying:

API::Entities::User.represent(current_user) and this will give us an object like this:
#<API::Entities::User:0x00007fe6aab82868
 @object=
  #<User:0x00117fe6aab82ee8
   id: 35345,
   name: "Test",
   email: "test@example.com",
   created_at: Mon, 14 Oct 2019 21:57:54 UTC +00:00,
   updated_at: Mon, 14 Oct 2019 21:57:54 UTC +00:00,
 @options={}>

Then in our spec scenario, we can call to_json from here and use it as a expected from the response of an API call like:
get '/api/v3/user'
expected_json = API::Entities::User.represent(current_user).to_json
expect(response.body).to eq(expected_json)

rails hirefire-resource gem

https://help.hirefire.io/article/54-job-queue-ruby-rack

https://github.com/hirefire/hirefire-resource

This library provides middleware which you can add to your stack, exposing an HTTP GET endpoint that HireFire will periodically request in order to get the latest information on your job queue(s).

gem 'hirefire-resource', '~> 0.3.6'

新增 config/initializers/hidefire.rb

# frozen_string_literal: true

HireFire::Resource.configure do |config|
  config.dyno("auto_invest_#{Rails.env}_worker".to_sym) do
    HireFire::Macro::Sidekiq.queue("auto_invest_#{Rails.env}".to_sym)
  end
end

Keycloak 导入多个领域文件 import multiple realms

官方文档 https://www.keycloak.org/docs/7.0/server_admin/#admin-console-export-import

If more than one realm file needs to be imported, a comma separated list of file names can be specified.

This is more appropriate than the cases before, as this will happen only after the master realm has been initialized.

Examples:

  • -Dkeycloak.import=/tmp/realm1.json
  • -Dkeycloak.import=/tmp/realm1.json,/tmp/realm2.json

使用场景:

在上线前需要在本地新建出不同的realm,然后导出成json配置文件,集成到docker-compose配置文件里,这样发布的时候就可以比较方便,直接部署完就自动新建出不同的realm。

(0) 启动: docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin  -p 8080:8080 jboss/keycloak

登录localhost:8080, 先配置realm,新建完导出realm。这里可以新建多个realm,分别导出多个json文件。

(1)把刚才启动的docker停止,可以直接删除上一步用到的container 也可以先留着:

删除的命令是 docker rm <container ID>

(2)新建docker-compose.yml,内容如下, 然后执行启动命令:docker-compose up -d

version: "3"
services:
  keycloak:
    image: jboss/keycloak:7.0.0
    ports:
      - "8080:8080"
    volumes:
      - "./imports:/Users/luciawang/workspace/practise/docker-compose/imports/"
    environment:
      - "KEYCLOAK_USER=admin"
      - "KEYCLOAK_PASSWORD=admin"
      - "DB_VENDOR=postgres"
      - "DB_ADDR=postgres"
      - "DB_DATABASE=postgres"
      - "DB_USER=postgres"
      - "DB_PASSWORD=123456"
      - "PROXY_ADDRESS_FORWARDING=true"
      - "KEYCLOAK_IMPORT=/Users/luciawang/workspace/practise/docker-compose/imports/realms.json,/Users/luciawang/workspace/practise/docker-compose/imports/realms1.json" 
    depends_on:
      - postgres
  postgres:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_PASSWORD:123456"

另一种方式:

version: "3"
services:
  keycloak:
    image: jboss/keycloak:7.0.0
    ports:
      - "8080:8080"
    volumes:
      - "./imports:/Users/lucia/workspace/practise/docker-compose/imports/"
    environment:
      - "KEYCLOAK_USER=admin"
      - "KEYCLOAK_PASSWORD=admin"
      - "DB_VENDOR=postgres"
      - "DB_ADDR=postgres"
      - "DB_DATABASE=postgres"
      - "DB_USER=postgres"
      - "DB_PASSWORD=123456"
      - "PROXY_ADDRESS_FORWARDING=true"
    command:
      - "-b 0.0.0.0 -Dkeycloak.import=/Users/lucia/workspace/practise/docker-compose/imports/realms.json,/Users/luciawang/workspace/practise/docker-compose/imports/realms1.json"
    depends_on:
      - postgres
  postgres:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_PASSWORD:123456"

登录localhost:8080, 进入的用户名密码都是admin,查看一下是否所有的realm都新建成功了

docker 常用命令

先介绍一个网站:https://hub.docker.com/

在这里网站里可以搜到相关的docker image

下载某个版本的docker镜像:

$ docker pull jboss/keycloak:3.3.0.Final

如果直接下载最新版本,不需要加版本号
$ docker pull jboss/keycloak

查看所有的docker container 容器

$ docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
71ae958e3ffd        postgres            "docker-entrypoint.s…"   21 minutes ago      Up 21 minutes       0.0.0.0:5432->5432/tcp             docker-compose_postgres_1
4f63a236e573        jboss/keycloak      "/opt/jboss/tools/do…"   21 minutes ago      Up 21 minutes       0.0.0.0:8080->8080/tcp, 8443/tcp   docker-compose_auth_1

删除某个容器 (71ae958e3ffd 为容器ID)

$ docker rm 71ae958e3ffd

查看所有的image

$ docker images

删除某个docker image

$ docker  rmi aabe60a21278    

启动容器并指定端口,这里以 jboss/keycloak 为例子:

$ docker run -p 8080:8080 jboss/keycloak

启动容器并使用环境变量-e(这里指的是登录keycloak admin网站的初始用户名密码)

$ docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin  -p 8080:8080 jboss/keycloak

查看某个docker container容器的日志 (71ae958e3ffd 为容器ID)

$ docker logs 71ae958e3ffd

进入某个容器的内部:(71ae958e3ffd 为容器ID)

$ docker exec -it 71ae958e3ffd bash

docker compose 后台启动:

$ docker-compose up -d

docker compose 前台启动:

$ docker-compose up

docker compose 停止:

$ docker-compose stop 

salesforce local env 配置 本地环境

IDE

Salesforce Extension Pack + VS Code (Highly Recommended)

This is the current Salesforce Official IDE providing full support for both traditional Sandbox (which is what we are doing in Harmoney) and Scratch Org development.

Set Up Steps

At this point, you should have the IDE setup done, following the steps to start APEX code development with sandbox 

Get Started

  • First, open VS Code and create a project. To create a project with a manifest, open the command palette (press Ctrl+Shift+P on Windows or Linux, or Cmd+Shift+P on macOS) and run SFDX: Create Project with Manifest.
  • Next, authorize the org you want to develop against. To start the login process, open the command palette and run SFDX: Authorize an Org.
  • After you select a login URL and give your project a name, your browser opens and you can log in to your org. After you finish logging in, close the browser and return to VS Code.
  • Retrieve metadata you want to work with from your org is by using a package.xml file in the manifest directory. (You can modify the package.xml yourself to retrieve the necessary metadata – https://developer.salesforce.com/docs/metadata-coverage)
    • ApexClass
    • ApexComponent
    • ApexPage
    • ApexTrigger
  • Save the package.xml file if you make any change, right-click a manifest, in the Visual Studio Code explorer or the editor, then select SFDX: Retrieve Source in Manifest from Org.
  • After the process is done, all the metadata has been pulled into local and you can start coding. 

Full reference of Org Development Model with VS Code – https://forcedotcom.github.io/salesforcedx-vscode/articles/user-guide/org-development-model

keycloak docker compose 配置 导入 realm

如果需要提前将已有keycloak的realm导出并通过docker-compose导入,用下图的方式导出,将导出的文件命名为realms.json

新建文件夹并创建文件: docker-compose.yml

version: "3"
services:
  keycloak:
    image: jboss/keycloak:7.0.0
    ports:
      - "8080:8080"
    volumes:
      - "./imports:/Users/lucia/workspace/docker-compose/imports/"
    environment:
      - "KEYCLOAK_USER=admin"
      - "KEYCLOAK_PASSWORD=admin"
      - "DB_VENDOR=postgres"
      - "DB_ADDR=postgres"
      - "DB_DATABASE=postgres"
      - "DB_USER=postgres"
      - "DB_PASSWORD=123456"
      - "PROXY_ADDRESS_FORWARDING=true"
    command:
      - "-b 0.0.0.0 -Dkeycloak.import=/Users/lucia/workspace/docker-compose/imports/realms.json"
    depends_on:
      - postgres
  postgres:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_PASSWORD:123456"

如果不需要导入realm,可以直接用下面的方式:

version: "3"
services:
  keycloak:
    image: jboss/keycloak:7.0.0
    ports:
      - "8080:8080"
    environment:
      - "KEYCLOAK_USER=admin"
      - "KEYCLOAK_PASSWORD=admin"
      - "DB_VENDOR=postgres"
      - "DB_ADDR=postgres"
      - "DB_DATABASE=postgres"
      - "DB_USER=postgres"
      - "DB_PASSWORD=123456"
      - "PROXY_ADDRESS_FORWARDING=true"
    depends_on:
      - postgres
  postgres:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_PASSWORD:123456"

后台启动: docker-compose up -d

前台启动:docker-compose up

停止:docker-compose stop

查看docker启动中的容器:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
71ae958e3ffd        postgres            "docker-entrypoint.s…"   21 minutes ago      Up 21 minutes       0.0.0.0:5432->5432/tcp             docker-compose_postgres_1
4f63a236e573        jboss/keycloak      "/opt/jboss/tools/do…"   21 minutes ago      Up 21 minutes       0.0.0.0:8080->8080/tcp, 8443/tcp   docker-compose_auth_1

删除某个容器

docker rm <容器CONTAINER id>

进入容器内部

$ docker exec -it 71ae958e3ffd bash  (进入postgresql的容器内部) root@71ae958e3ffd:/# psql postgres -U postgres psql (12.0 (Debian 12.0-1.pgdg100+1)) Type "help" for help. postgres=# \c postgres You are now connected to database "postgres" as user "postgres". 




打开网页,用户名密码就是我们在docker-compose.yml 文件里配置的 admin / admin

KEYCLOAK_USER=admin

KEYCLOAK_PASSWORD=admin