Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bxb100 committed Nov 12, 2024
1 parent aeb30bd commit d7fa3a7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 43 deletions.
15 changes: 0 additions & 15 deletions __tests__/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ describe('connect references regex test', () => {
expect(exec?.groups?.field_name).toBe('weuaijejjhpp2o3em5dtokca2a')
})

it('secret ref', () => {
const ref = 'op://dev/5vtojw237m2cxymfkfhtxsrazm/text'
expect(ref).toMatch(REGEX)

const exec = REGEX.exec(ref)
expect(exec).not.toBeNull()
expect(exec?.groups).not.toBeNull()
expect(exec?.groups?.vault_name).toBe('dev')
expect(exec?.groups?.item_name).toBe('5vtojw237m2cxymfkfhtxsrazm')
expect(exec?.groups?.section_name).toBeUndefined()
expect(exec?.groups?.field_name).toBe('text')
})

it('secret ref with section', () => {
const ref = 'op://dev/5vtojw237m2cxymfkfhtxsrazm/cs/text'
expect(ref).toMatch(REGEX)
Expand All @@ -46,7 +33,5 @@ describe('connect references regex test', () => {
it('test uuid', () => {
expect(is_valid_client_uuid('d4472vsddcneis7b4onz4v75nu')).toBeTruthy()
expect(is_valid_client_uuid('dev')).toBeFalsy()
expect(is_valid_client_uuid('cs')).toBeFalsy()
expect(is_valid_client_uuid('text')).toBeFalsy()
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 11 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typescript-action",
"description": "GitHub Actions TypeScript template",
"version": "0.2.1",
"version": "0.2.2",
"author": "Lemon",
"private": true,
"homepage": "https://github.com/bxb100/load-secrets-action",
Expand Down
14 changes: 8 additions & 6 deletions src/service/connect/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ export async function get_vault_id(
if (vaults.length === 0) {
throw new Error(`No vaults found with identifier ${vault_identifier}`)
}
let oldest_vault = vaults[0]
if (vaults.length > 1) {
const oldest_vault = vaults.sort(
oldest_vault = vaults.sort(
(a, b) => (b.createdAt?.getTime() || 0) - (a.createdAt?.getTime() || 0)
)[0]
core.info(
`${vaults.length} 1Password vaults found with the title ${vault_identifier}. Will use vault ${oldest_vault.id} as it is the oldest.`
)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return oldest_vault.id!
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
vault_identifier = oldest_vault.id!
}
return vault_identifier
}
Expand All @@ -38,16 +39,17 @@ export async function get_item_id(
if (items.length === 0) {
throw new Error(`No items found with identifier ${item_identifier}`)
}
let oldest_item = items[0]
if (items.length > 1) {
const oldest_item = items.sort(
oldest_item = items.sort(
(a, b) => (b.createdAt?.getTime() || 0) - (a.createdAt?.getTime() || 0)
)[0]
core.info(
`${items.length} 1Password items found with the title ${item_identifier}. Will use item ${oldest_item.id} as it is the oldest.`
)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return oldest_item.id!
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
item_identifier = oldest_item.id!
}
return item_identifier
}
Expand Down
8 changes: 2 additions & 6 deletions src/service/connect/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/**
* https://github.com/1Password/onepassword-operator/blob/ced45c33d4c1e0267dc5af54231c5a29accce4c4/pkg/onepassword/uuid.go#L7
*
* @param uuid check this is a valid client uuid or title
* @param uuid check this is a valid client uuid, otherwise is title
*/
export function is_valid_client_uuid(uuid: string): boolean {
if (uuid.length != 26) {
return false
}

const regex = /[a-z0-9]+/
const regex = /[a-z0-9]{26}/
return regex.test(uuid)
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const Version = { version: '0.2.0' }
export const Version = { version: '0.2.2' }

0 comments on commit d7fa3a7

Please sign in to comment.