Skip to content

Commit 86c1a70

Browse files
committed
migrate to onepassword version 2.30.0
1 parent d09c8fb commit 86c1a70

File tree

9 files changed

+91
-95
lines changed

9 files changed

+91
-95
lines changed

.github/workflows/test.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
npm install
1717
- run: |
1818
npm run all
19-
test: # make sure the action works on a clean machine without building
19+
test: # make sure the action works
2020
strategy:
2121
matrix:
2222
runs-on: [macos-latest, ubuntu-20.04, ubuntu-22.04, ubuntu-latest]
@@ -30,6 +30,10 @@ jobs:
3030
- name: Checkout Github
3131
uses: actions/checkout@v3
3232
if: ${{ !env.ACT }}
33+
- name: Install dependencies
34+
run: npm install
35+
- name: Build Typescript
36+
run: npm run all
3337
- name: Test Action
3438
uses: ./
3539
id: secrets

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0
2+
3+
- Migrated from 1Password CLI version 1.8.0 to 2.30.0
4+
15
## 2.1.0
26

37
- Support for multi word names. Resolves [#54](https://github.com/RobotsAndPencils/1password-action/issues/54)

__tests__/parsing.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ test('parses multiple unquoted, renamed items', async () => {
4242
})
4343

4444
test('parses single unquoted multi word item', async () => {
45-
const output = parseItemRequestsInput('GitHub Action Test Vault > Test Login Four Words')
45+
const output = parseItemRequestsInput(
46+
'GitHub Action Test Vault > Test Login Four Words'
47+
)
4648
expect(output).toHaveLength(1)
4749
expect(output[0].vault).toBe('GitHub Action Test Vault')
4850
expect(output[0].name).toBe('Test Login Four Words')
4951
expect(output[0].outputName).toBe('test_login_four_words')
5052
})
5153

5254
test('parses single unquoted multi word item separated by periods', async () => {
53-
const output = parseItemRequestsInput('GitHub Action Test Vault > Test.Login.Four.Words')
55+
const output = parseItemRequestsInput(
56+
'GitHub Action Test Vault > Test.Login.Four.Words'
57+
)
5458
expect(output).toHaveLength(1)
5559
expect(output[0].vault).toBe('GitHub Action Test Vault')
5660
expect(output[0].name).toBe('Test.Login.Four.Words')

dist/index.js

+16-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/1password.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {install} from './install'
33
import * as tc from '@actions/tool-cache'
44
import {execWithOutput} from './exec'
55

6-
const ONE_PASSWORD_VERSION = '1.8.0'
6+
const ONE_PASSWORD_VERSION = '2.30.0'
77

88
export class OnePassword {
99
onePasswordEnv: {[key: string]: string}
@@ -37,13 +37,18 @@ export class OnePassword {
3737
const output = await execWithOutput(
3838
'op',
3939
[
40-
'signin',
40+
'account',
41+
'add',
42+
'--address',
4143
signInAddress,
44+
'--email',
4245
emailAddress,
46+
'--secret-key',
4347
secretKey,
4448
'--raw',
4549
'--shorthand',
46-
'github_action'
50+
'github_action',
51+
'--signin'
4752
],
4853
{
4954
env,
@@ -67,23 +72,31 @@ export class OnePassword {
6772
async listItemsInVault(vault: string): Promise<string> {
6873
const env = this.onePasswordEnv
6974

70-
return await execWithOutput('op', ['list', 'items', '--vault', vault], {
71-
env
72-
})
75+
return await execWithOutput(
76+
'op',
77+
['item', 'list', '--vault', vault, '--format=json'],
78+
{
79+
env
80+
}
81+
)
7382
}
7483

7584
async getItemInVault(vault: string, uuid: string): Promise<string> {
7685
const env = this.onePasswordEnv
77-
return await execWithOutput('op', ['get', 'item', uuid, '--vault', vault], {
78-
env
79-
})
86+
return await execWithOutput(
87+
'op',
88+
['item', 'get', uuid, '--vault', vault, '--format=json'],
89+
{
90+
env
91+
}
92+
)
8093
}
8194

8295
async getDocument(uuid: string, filename: string): Promise<void> {
8396
const env = this.onePasswordEnv
8497
await execWithOutput(
8598
'op',
86-
['get', 'document', uuid, '--output', filename],
99+
['document', 'get', uuid, '--output', filename],
87100
{
88101
env
89102
}
@@ -92,6 +105,6 @@ export class OnePassword {
92105

93106
async signOut(): Promise<void> {
94107
const env = this.onePasswordEnv
95-
await execWithOutput('op', ['signout', '--forget'], {env})
108+
await execWithOutput('op', ['signout', '--account', 'github_action', '--forget'], {env})
96109
}
97110
}

src/install.ts

+6-30
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,24 @@ import {mv} from '@actions/io'
44
import {chmod} from '@actions/io/lib/io-util'
55
import * as tc from '@actions/tool-cache'
66
import * as exec from '@actions/exec'
7-
import {execWithOutput} from './exec'
87

9-
const CERT_IDENTIFIER = 'Developer ID Installer: AgileBits Inc. (2BUA8C4S2C)'
108
const KEY_FINGERPRINT = '3FEF9748469ADBE15DA7CA80AC2D62742012EA22'
119

1210
export async function install(onePasswordVersion: string): Promise<void> {
1311
const platform = os.platform().toLowerCase()
1412

15-
let extension = 'zip'
13+
let arch = 'amd64'
1614
if (platform === 'darwin') {
17-
extension = 'pkg'
15+
arch = 'arm64'
1816
}
19-
const onePasswordUrl = `https://cache.agilebits.com/dist/1P/op/pkg/v${onePasswordVersion}/op_${platform}_amd64_v${onePasswordVersion}.${extension}`
20-
const archive = await tc.downloadTool(onePasswordUrl)
17+
const onePasswordUrl = `https://cache.agilebits.com/dist/1P/op2/pkg/v${onePasswordVersion}/op_${platform}_${arch}_v${onePasswordVersion}.zip`
2118
core.info(
2219
`Downloading ${onePasswordVersion} for ${platform} from ${onePasswordUrl}`
2320
)
21+
const archive = await tc.downloadTool(onePasswordUrl)
22+
const extracted = await tc.extractZip(archive)
2423

25-
let extracted: string
26-
if (platform === 'darwin') {
27-
const signatureCheck = await execWithOutput('pkgutil', [
28-
'--check-signature',
29-
archive
30-
])
31-
if (signatureCheck.includes(CERT_IDENTIFIER) === false) {
32-
throw new Error(
33-
`Signature verification of the installer package downloaded from ${onePasswordUrl} failed.\nExpecting it to include ${CERT_IDENTIFIER}.\nReceived:\n${signatureCheck}`
34-
)
35-
} else {
36-
core.info('Verified the code signature of the installer package.')
37-
}
38-
39-
// Expanding the package manually to avoid needing an admin password for installation and to be able to put it into the tool cache.
40-
const destination = 'op.unpkg'
41-
await exec.exec('pkgutil', ['--expand', archive, destination])
42-
await exec.exec(
43-
`/bin/bash -c "cat ${destination}/Payload | gzip -d | cpio -id"`
44-
)
45-
extracted = '.'
46-
} else {
47-
extracted = await tc.extractZip(archive)
48-
24+
if (platform !== 'darwin') {
4925
await exec.exec('gpg', [
5026
'--keyserver',
5127
'keyserver.ubuntu.com',

src/main.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function run(): Promise<void> {
3434
core.setSecret(secretKey)
3535

3636
core.startGroup('Signing in to 1Password')
37+
3738
try {
3839
await onePassword.signIn(
3940
signInAddress,
@@ -92,13 +93,12 @@ async function requestItems(
9293
core.info(
9394
`Getting items in 1Password Vault:${style.bold.open} ${itemRequest.vault}`
9495
)
95-
9696
const itemsJSON = await onePassword.listItemsInVault(itemRequest.vault)
9797

9898
const items: Item[] = JSON.parse(itemsJSON)
9999
const uuid = items
100-
.filter(item => item.overview.title === itemRequest.name)
101-
.map(item => item.uuid)[0]
100+
.filter(item => item.title === itemRequest.name)
101+
.map(item => item.id)[0]
102102

103103
if (!uuid) {
104104
throw new Error(
@@ -110,14 +110,13 @@ async function requestItems(
110110
const itemJSON = await onePassword.getItemInVault(itemRequest.vault, uuid)
111111
const item: Item = JSON.parse(itemJSON)
112112

113-
switch (item.templateUuid) {
114-
// Item
115-
case '001': {
116-
const username = (item.details.fields ?? []).filter(
117-
field => field.designation === 'username'
113+
switch (item.category) {
114+
case 'LOGIN': {
115+
const username = (item.fields ?? []).filter(
116+
field => field.purpose === 'USERNAME'
118117
)[0].value
119-
const password = (item.details.fields ?? []).filter(
120-
field => field.designation === 'password'
118+
const password = (item.fields ?? []).filter(
119+
field => field.purpose === 'PASSWORD'
121120
)[0].value
122121

123122
const usernameOutputName = `${itemRequest.outputName}_username`
@@ -128,12 +127,14 @@ async function requestItems(
128127

129128
break
130129
}
131-
// Password
132-
case '005': {
133-
const password = item.details.password
130+
case 'PASSWORD': {
131+
const password = (item.fields ?? []).filter(
132+
field => field.purpose === 'PASSWORD'
133+
)[0].value
134+
134135
if (password === undefined) {
135136
throw new Error(
136-
`${style.inverse.open}Expected string for property item.details.password, got undefined.`
137+
`${style.inverse.open}Expected string for field password, got undefined.`
137138
)
138139
}
139140

@@ -143,12 +144,11 @@ async function requestItems(
143144

144145
break
145146
}
146-
// Document
147-
case '006': {
148-
const filename = item.details.documentAttributes?.fileName
147+
case 'DOCUMENT': {
148+
const filename = (item.files ?? [])[0].name
149149
if (filename === undefined) {
150150
throw new Error(
151-
`${style.inverse.open}Expected string for property document.details.documentAttributes?.filename, got undefined.`
151+
`${style.inverse.open}Expected string for file name, got undefined.`
152152
)
153153
}
154154

0 commit comments

Comments
 (0)