fix auth type

This commit is contained in:
boufni95 2025-04-10 17:04:58 +00:00
parent 67c1260748
commit b18eab9d20
8 changed files with 26 additions and 26 deletions

View file

@ -256,7 +256,7 @@ The nostr server will send back a message response, and inside the body there wi
- This methods has an __empty__ __response__ body - This methods has an __empty__ __response__ body
- ResetMetricsStorages - ResetMetricsStorages
- auth type: __Admin__ - auth type: __Metrics__
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
- This methods has an __empty__ __response__ body - This methods has an __empty__ __response__ body
@ -301,7 +301,7 @@ The nostr server will send back a message response, and inside the body there wi
- output: [UserHealthState](#UserHealthState) - output: [UserHealthState](#UserHealthState)
- ZipMetricsStorages - ZipMetricsStorages
- auth type: __Admin__ - auth type: __Metrics__
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
- output: [ZippedMetrics](#ZippedMetrics) - output: [ZippedMetrics](#ZippedMetrics)
@ -805,7 +805,7 @@ The nostr server will send back a message response, and inside the body there wi
- This methods has an __empty__ __response__ body - This methods has an __empty__ __response__ body
- ResetMetricsStorages - ResetMetricsStorages
- auth type: __Admin__ - auth type: __Metrics__
- http method: __post__ - http method: __post__
- http route: __/api/admin/metrics/reset__ - http route: __/api/admin/metrics/reset__
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body
@ -910,7 +910,7 @@ The nostr server will send back a message response, and inside the body there wi
- output: [UserHealthState](#UserHealthState) - output: [UserHealthState](#UserHealthState)
- ZipMetricsStorages - ZipMetricsStorages
- auth type: __Admin__ - auth type: __Metrics__
- http method: __post__ - http method: __post__
- http route: __/api/admin/metrics/zip__ - http route: __/api/admin/metrics/zip__
- This methods has an __empty__ __request__ body - This methods has an __empty__ __request__ body

View file

@ -1755,7 +1755,7 @@ func NewClient(params ClientParams) *Client {
return nil return nil
}, },
ResetMetricsStorages: func() error { ResetMetricsStorages: func() error {
auth, err := params.RetrieveAdminAuth() auth, err := params.RetrieveMetricsAuth()
if err != nil { if err != nil {
return err return err
} }
@ -2106,7 +2106,7 @@ func NewClient(params ClientParams) *Client {
return &res, nil return &res, nil
}, },
ZipMetricsStorages: func() (*ZippedMetrics, error) { ZipMetricsStorages: func() (*ZippedMetrics, error) {
auth, err := params.RetrieveAdminAuth() auth, err := params.RetrieveMetricsAuth()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1639,7 +1639,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
let authCtx: Types.AuthContext = {} let authCtx: Types.AuthContext = {}
try { try {
if (!methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented') if (!methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented')
const authContext = await opts.AdminAuthGuard(req.headers['authorization']) const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
authCtx = authContext authCtx = authContext
stats.guard = process.hrtime.bigint() stats.guard = process.hrtime.bigint()
stats.validate = stats.guard stats.validate = stats.guard
@ -1941,7 +1941,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
let authCtx: Types.AuthContext = {} let authCtx: Types.AuthContext = {}
try { try {
if (!methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented') if (!methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented')
const authContext = await opts.AdminAuthGuard(req.headers['authorization']) const authContext = await opts.MetricsAuthGuard(req.headers['authorization'])
authCtx = authContext authCtx = authContext
stats.guard = process.hrtime.bigint() stats.guard = process.hrtime.bigint()
stats.validate = stats.guard stats.validate = stats.guard

View file

@ -840,8 +840,8 @@ export default (params: ClientParams) => ({
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
ResetMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' })> => { ResetMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveAdminAuth() const auth = await params.retrieveMetricsAuth()
if (auth === null) throw new Error('retrieveAdminAuth() returned null') if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
let finalRoute = '/api/admin/metrics/reset' let finalRoute = '/api/admin/metrics/reset'
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } }) const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data
@ -1007,8 +1007,8 @@ export default (params: ClientParams) => ({
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
ZipMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' }& Types.ZippedMetrics)> => { ZipMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' }& Types.ZippedMetrics)> => {
const auth = await params.retrieveAdminAuth() const auth = await params.retrieveMetricsAuth()
if (auth === null) throw new Error('retrieveAdminAuth() returned null') if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
let finalRoute = '/api/admin/metrics/zip' let finalRoute = '/api/admin/metrics/zip'
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } }) const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data

View file

@ -699,8 +699,8 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
ResetMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' })> => { ResetMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' })> => {
const auth = await params.retrieveNostrAdminAuth() const auth = await params.retrieveNostrMetricsAuth()
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')
const nostrRequest: NostrRequest = {} const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, {rpcName:'ResetMetricsStorages',authIdentifier:auth, ...nostrRequest }) const data = await send(params.pubDestination, {rpcName:'ResetMetricsStorages',authIdentifier:auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data
@ -817,8 +817,8 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
return { status: 'ERROR', reason: 'invalid response' } return { status: 'ERROR', reason: 'invalid response' }
}, },
ZipMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' }& Types.ZippedMetrics)> => { ZipMetricsStorages: async (): Promise<ResultError | ({ status: 'OK' }& Types.ZippedMetrics)> => {
const auth = await params.retrieveNostrAdminAuth() const auth = await params.retrieveNostrMetricsAuth()
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')
const nostrRequest: NostrRequest = {} const nostrRequest: NostrRequest = {}
const data = await send(params.pubDestination, {rpcName:'ZipMetricsStorages',authIdentifier:auth, ...nostrRequest }) const data = await send(params.pubDestination, {rpcName:'ZipMetricsStorages',authIdentifier:auth, ...nostrRequest })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data if (data.status === 'ERROR' && typeof data.reason === 'string') return data

View file

@ -1094,7 +1094,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
case 'ResetMetricsStorages': case 'ResetMetricsStorages':
try { try {
if (!methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented') if (!methods.ResetMetricsStorages) throw new Error('method: ResetMetricsStorages is not implemented')
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrMetricsAuthGuard(req.appId, req.authIdentifier)
stats.guard = process.hrtime.bigint() stats.guard = process.hrtime.bigint()
authCtx = authContext authCtx = authContext
stats.validate = stats.guard stats.validate = stats.guard
@ -1229,7 +1229,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
case 'ZipMetricsStorages': case 'ZipMetricsStorages':
try { try {
if (!methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented') if (!methods.ZipMetricsStorages) throw new Error('method: ZipMetricsStorages is not implemented')
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) const authContext = await opts.NostrMetricsAuthGuard(req.appId, req.authIdentifier)
stats.guard = process.hrtime.bigint() stats.guard = process.hrtime.bigint()
authCtx = authContext authCtx = authContext
stats.validate = stats.guard stats.validate = stats.guard

View file

@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?:
export type AdminContext = { export type AdminContext = {
admin_id: string admin_id: string
} }
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | ResetMetricsStorages_Input | UpdateChannelPolicy_Input | ZipMetricsStorages_Input export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | UpdateChannelPolicy_Input
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | ResetMetricsStorages_Output | UpdateChannelPolicy_Output | ZipMetricsStorages_Output export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | UpdateChannelPolicy_Output
export type AppContext = { export type AppContext = {
app_id: string app_id: string
} }
@ -28,8 +28,8 @@ export type MetricsContext = {
app_id: string app_id: string
operator_id: string operator_id: string
} }
export type MetricsMethodInputs = GetAppsMetrics_Input | GetBundleMetrics_Input | GetErrorStats_Input | GetLndMetrics_Input | GetSingleBundleMetrics_Input | GetSingleUsageMetrics_Input | GetUsageMetrics_Input | SubmitWebRtcMessage_Input export type MetricsMethodInputs = GetAppsMetrics_Input | GetBundleMetrics_Input | GetErrorStats_Input | GetLndMetrics_Input | GetSingleBundleMetrics_Input | GetSingleUsageMetrics_Input | GetUsageMetrics_Input | ResetMetricsStorages_Input | SubmitWebRtcMessage_Input | ZipMetricsStorages_Input
export type MetricsMethodOutputs = GetAppsMetrics_Output | GetBundleMetrics_Output | GetErrorStats_Output | GetLndMetrics_Output | GetSingleBundleMetrics_Output | GetSingleUsageMetrics_Output | GetUsageMetrics_Output | SubmitWebRtcMessage_Output export type MetricsMethodOutputs = GetAppsMetrics_Output | GetBundleMetrics_Output | GetErrorStats_Output | GetLndMetrics_Output | GetSingleBundleMetrics_Output | GetSingleUsageMetrics_Output | GetUsageMetrics_Output | ResetMetricsStorages_Output | SubmitWebRtcMessage_Output | ZipMetricsStorages_Output
export type UserContext = { export type UserContext = {
app_id: string app_id: string
app_user_id: string app_user_id: string
@ -365,7 +365,7 @@ export type ServerMethods = {
PayInvoice?: (req: PayInvoice_Input & {ctx: UserContext }) => Promise<PayInvoiceResponse> PayInvoice?: (req: PayInvoice_Input & {ctx: UserContext }) => Promise<PayInvoiceResponse>
RequestNPubLinkingToken?: (req: RequestNPubLinkingToken_Input & {ctx: AppContext }) => Promise<RequestNPubLinkingTokenResponse> RequestNPubLinkingToken?: (req: RequestNPubLinkingToken_Input & {ctx: AppContext }) => Promise<RequestNPubLinkingTokenResponse>
ResetDebit?: (req: ResetDebit_Input & {ctx: UserContext }) => Promise<void> ResetDebit?: (req: ResetDebit_Input & {ctx: UserContext }) => Promise<void>
ResetMetricsStorages?: (req: ResetMetricsStorages_Input & {ctx: AdminContext }) => Promise<void> ResetMetricsStorages?: (req: ResetMetricsStorages_Input & {ctx: MetricsContext }) => Promise<void>
ResetNPubLinkingToken?: (req: ResetNPubLinkingToken_Input & {ctx: AppContext }) => Promise<RequestNPubLinkingTokenResponse> ResetNPubLinkingToken?: (req: ResetNPubLinkingToken_Input & {ctx: AppContext }) => Promise<RequestNPubLinkingTokenResponse>
RespondToDebit?: (req: RespondToDebit_Input & {ctx: UserContext }) => Promise<void> RespondToDebit?: (req: RespondToDebit_Input & {ctx: UserContext }) => Promise<void>
SendAppUserToAppPayment?: (req: SendAppUserToAppPayment_Input & {ctx: AppContext }) => Promise<void> SendAppUserToAppPayment?: (req: SendAppUserToAppPayment_Input & {ctx: AppContext }) => Promise<void>
@ -380,7 +380,7 @@ export type ServerMethods = {
UpdateUserOffer?: (req: UpdateUserOffer_Input & {ctx: UserContext }) => Promise<void> UpdateUserOffer?: (req: UpdateUserOffer_Input & {ctx: UserContext }) => Promise<void>
UseInviteLink?: (req: UseInviteLink_Input & {ctx: GuestWithPubContext }) => Promise<void> UseInviteLink?: (req: UseInviteLink_Input & {ctx: GuestWithPubContext }) => Promise<void>
UserHealth?: (req: UserHealth_Input & {ctx: UserContext }) => Promise<UserHealthState> UserHealth?: (req: UserHealth_Input & {ctx: UserContext }) => Promise<UserHealthState>
ZipMetricsStorages?: (req: ZipMetricsStorages_Input & {ctx: AdminContext }) => Promise<ZippedMetrics> ZipMetricsStorages?: (req: ZipMetricsStorages_Input & {ctx: MetricsContext }) => Promise<ZippedMetrics>
} }
export enum AddressType { export enum AddressType {

View file

@ -235,14 +235,14 @@ service LightningPub {
} }
rpc ZipMetricsStorages(structs.Empty) returns (structs.ZippedMetrics) { rpc ZipMetricsStorages(structs.Empty) returns (structs.ZippedMetrics) {
option (auth_type) = "Admin"; option (auth_type) = "Metrics";
option (http_method) = "post"; option (http_method) = "post";
option (http_route) = "/api/admin/metrics/zip"; option (http_route) = "/api/admin/metrics/zip";
option (nostr) = true; option (nostr) = true;
} }
rpc ResetMetricsStorages(structs.Empty) returns (structs.Empty) { rpc ResetMetricsStorages(structs.Empty) returns (structs.Empty) {
option (auth_type) = "Admin"; option (auth_type) = "Metrics";
option (http_method) = "post"; option (http_method) = "post";
option (http_route) = "/api/admin/metrics/reset"; option (http_route) = "/api/admin/metrics/reset";
option (nostr) = true; option (nostr) = true;